123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- import React, { useCallback, useEffect, useRef, useState } from "react";
- import styles from "./index.module.scss";
- import classNames from "classnames";
- import { A2getGoodsDataType } from "@/types";
- import { Input, Pagination } from "antd";
- import { SearchOutlined } from "@ant-design/icons";
- import { useDispatch, useSelector } from "react-redux";
- import { A2_APIgetGoodsList, A2_APIgetSelectData } from "@/store/action/A2Main";
- import { RootState } from "@/store";
- import { envUrl } from "@/utils/env";
- import ImageLazy from "@/components/ImageLazy";
- // 轮播图
- import { Swiper, SwiperSlide } from "swiper/react";
- import { FreeMode } from "swiper";
- // Import Swiper styles
- import "swiper/css";
- import "swiper/css/free-mode";
- import Tab4Info from "../Tab4Info";
- const typeArr = [
- { id: "img", name: "二维文物" },
- { id: "model", name: "三维文物" },
- ];
- function Tab4() {
- const dispatch = useDispatch();
- // 看看是不是还没有发送请求
- const [isDataFlag, setIsDataFlag] = useState(false);
- // 发送请求参数
- const [getData, setGetData] = useState<A2getGoodsDataType>({
- dictAge: "",
- dictTexture: "",
- searchKey: "",
- pageNum: 1,
- pageSize: 8,
- type: "img",
- });
- // 发送请求函数
- const getList = useCallback(() => {
- setIsDataFlag(true);
- let searchKey = "";
- if (inpValueRef.current) searchKey = inpValueRef.current.input.value;
- dispatch(A2_APIgetGoodsList({ ...getData, searchKey }));
- }, [dispatch, getData]);
- useEffect(() => {
- getList();
- }, [getList]);
- // 输入框
- const [inpValue, setInpValue] = useState("");
- const inpValueRef = useRef<any>(null);
- useEffect(() => {
- inpValueRef.current = inpValue;
- }, [inpValue]);
- useEffect(() => {
- // 发送请求拿到下拉框数据
- // dispatch(A2_APIgetSelectData("age"));
- dispatch(A2_APIgetSelectData("texture"));
- }, [dispatch]);
- // 获取下拉数据
- const selectData = useSelector(
- (state: RootState) => state.A2Main.selectData.texture
- );
- // 从仓库获取数据
- const goodsList = useSelector((state: RootState) => state.A2Main.goodsList);
- // 详情页 id
- const [infoId, setInfoId] = useState(0);
- return (
- <div
- className={styles.Tab4}
- style={{ backgroundImage: `url(${envUrl}/goods/bac.jpg)` }}
- >
- <div className="tab4Top">
- {/* 二维 三维的筛选 */}
- {typeArr.map((v) => (
- <div
- key={v.id}
- className={classNames(
- "tab4Top1",
- v.id === getData.type ? "tab4Top1Ac" : ""
- )}
- onClick={() => setGetData({ ...getData, type: v.id, pageNum: 1 })}
- >
- {v.name}
- </div>
- ))}
- {/* 输入框 */}
- <div className="tab4Top2">
- <div className="tab4Top2_1">
- <SearchOutlined />
- </div>
- <Input
- placeholder="请输入关键词"
- maxLength={30}
- value={inpValue}
- onChange={(e) => setInpValue(e.target.value.trim())}
- ref={inpValueRef}
- />
- <div
- className="tab4Top2_2"
- onClick={() => {
- if (getData.pageNum === 1) getList();
- else setGetData({ ...getData, pageNum: 1 });
- }}
- >
- 搜索
- </div>
- </div>
- </div>
- {/* 类型的筛选 */}
- <div className="tab4Top2">
- <Swiper
- modules={[FreeMode]}
- className="appSw"
- spaceBetween={0}
- slidesPerView="auto"
- freeMode={true}
- mousewheel={true}
- // onSlideChange={(e) => console.log("slide change", e)}
- // onSwiper={(swiper) => (mySwiperRef.current = swiper)}
- >
- {selectData.map((v) => (
- <SwiperSlide key={v.label}>
- <div
- onClick={(e) =>
- setGetData({
- ...getData,
- dictTexture: v.value as string,
- pageNum: 1,
- })
- }
- className={classNames(
- "row",
- getData.dictTexture === v.value ? "active" : ""
- )}
- >
- <span>{v.label}</span>
- </div>
- </SwiperSlide>
- ))}
- </Swiper>
- </div>
- {/* 主要内容 */}
- {goodsList.list.length <= 0 && isDataFlag ? (
- <div className="tav4MainNone">暂无数据</div>
- ) : (
- <div className="tab4Main">
- {goodsList.list.map((v) => (
- <div
- className="tab4Mrow"
- key={v.id}
- title={v.name}
- onClick={() => setInfoId(v.id)}
- >
- <div className="tab4MrowImg">
- <ImageLazy src={v.thumb} noLook width="100%" height="100%" />
- </div>
- <p>{v.name}</p>
- </div>
- ))}
- </div>
- )}
- {/* 分页器 */}
- <div className="tab4Page">
- <Pagination
- showQuickJumper
- current={getData.pageNum}
- total={goodsList.total}
- pageSize={15}
- hideOnSinglePage={true}
- onChange={(page) => setGetData({ ...getData, pageNum: page })}
- showSizeChanger={false}
- />
- </div>
- {/* 点击文物进入详情页 */}
- {infoId ? (
- <Tab4Info id={infoId} closePage={() => setInfoId(0)} isOpen={false} />
- ) : null}
- </div>
- );
- }
- const MemoTab4 = React.memo(Tab4);
- export default MemoTab4;
|