|
@@ -6,7 +6,7 @@ import {
|
|
|
goodsRemoveAPI,
|
|
|
} from "@/store/action/goods";
|
|
|
import { GoodsTableSearch } from "@/types";
|
|
|
-import history from "@/utils/history";
|
|
|
+import { typeChangeObj } from "@/utils/changeData";
|
|
|
import {
|
|
|
Input,
|
|
|
Select,
|
|
@@ -25,24 +25,43 @@ import React, {
|
|
|
useState,
|
|
|
} from "react";
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
-import { useLocation } from "react-router-dom";
|
|
|
import GoodsAdd from "../GoodsAdd";
|
|
|
import styles from "./index.module.scss";
|
|
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
|
function Goods() {
|
|
|
- // 获取地址栏参数
|
|
|
- const location = useLocation();
|
|
|
-
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
const pageNumRef = useRef(1);
|
|
|
const pagePageRef = useRef(10);
|
|
|
|
|
|
+ // 0------------点击新增或者编辑出来的页面
|
|
|
+ const [editPageShow, setEditPageShow] = useState(false);
|
|
|
+ const editId = useRef(0);
|
|
|
+
|
|
|
+ const openEditPageFu = useCallback((id: number) => {
|
|
|
+ editId.current = id;
|
|
|
+ setEditPageShow(true);
|
|
|
+ }, []);
|
|
|
|
|
|
- // 点击新增或者编辑出来的页面
|
|
|
- const [editPageShow,setEditPageShow] =useState(false)
|
|
|
+ // 点击新增,新增成功之后的回调
|
|
|
+ const addTableListFu = useCallback(() => {
|
|
|
+ setTableSelect({
|
|
|
+ name: "",
|
|
|
+ num: "",
|
|
|
+ dictTexture: "",
|
|
|
+ dictAge: "",
|
|
|
+ dictLevel: "",
|
|
|
+ dictSource: "",
|
|
|
+ startTime: "",
|
|
|
+ endTime: "",
|
|
|
+ topic: -1,
|
|
|
+ display: -1,
|
|
|
+ pageSize: 10,
|
|
|
+ pageNum: 1,
|
|
|
+ });
|
|
|
+ }, []);
|
|
|
|
|
|
// 从仓库获取下拉列表数据
|
|
|
const dictList = useSelector((state: RootState) => state.loginStore.dictList);
|
|
@@ -52,16 +71,6 @@ function Goods() {
|
|
|
(state: RootState) => state.goodsReducer.tableInfo
|
|
|
);
|
|
|
|
|
|
- // 如果有参数 根据参数页码在次发送请求
|
|
|
- useEffect(() => {
|
|
|
- const urlParam = location.state || {};
|
|
|
- setTableSelect({
|
|
|
- ...tableSelect,
|
|
|
- pageNum: Number(urlParam.k) ? Number(urlParam.k) : 1,
|
|
|
- });
|
|
|
- // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
- }, [location]);
|
|
|
-
|
|
|
// 顶部筛选
|
|
|
const [tableSelect, setTableSelect] = useState<GoodsTableSearch>({
|
|
|
name: "",
|
|
@@ -208,12 +217,12 @@ function Goods() {
|
|
|
|
|
|
const columns = useMemo(() => {
|
|
|
return [
|
|
|
- {
|
|
|
- width: 80,
|
|
|
- title: "序号",
|
|
|
- render: (text: any, record: any, index: any) =>
|
|
|
- index + 1 + (pageNumRef.current - 1) * pagePageRef.current,
|
|
|
- },
|
|
|
+ // {
|
|
|
+ // width: 80,
|
|
|
+ // title: "序号",
|
|
|
+ // render: (text: any, record: any, index: any) =>
|
|
|
+ // index + 1 + (pageNumRef.current - 1) * pagePageRef.current,
|
|
|
+ // },
|
|
|
{
|
|
|
title: "名称",
|
|
|
dataIndex: "name",
|
|
@@ -237,7 +246,7 @@ function Goods() {
|
|
|
{
|
|
|
title: "来源",
|
|
|
dataIndex: "dictSource",
|
|
|
- },
|
|
|
+ },
|
|
|
{
|
|
|
title: "简介",
|
|
|
render: (item: GoodsTableSearch) =>
|
|
@@ -263,7 +272,7 @@ function Goods() {
|
|
|
},
|
|
|
{
|
|
|
title: "类型",
|
|
|
- dataIndex: "dictSource",
|
|
|
+ render: (item: GoodsTableSearch) => typeChangeObj[item.type!],
|
|
|
},
|
|
|
{
|
|
|
title: "最近编辑时间",
|
|
@@ -292,11 +301,7 @@ function Goods() {
|
|
|
<Button
|
|
|
size="small"
|
|
|
type="text"
|
|
|
- onClick={() =>
|
|
|
- history.push(
|
|
|
- `/goods/edit?k=${pageNumRef.current}&id=${item.id}`
|
|
|
- )
|
|
|
- }
|
|
|
+ onClick={() => openEditPageFu(item.id!)}
|
|
|
>
|
|
|
编辑
|
|
|
</Button>
|
|
@@ -314,7 +319,7 @@ function Goods() {
|
|
|
),
|
|
|
},
|
|
|
];
|
|
|
- }, [delTableFu, isEnabledClickFu]);
|
|
|
+ }, [delTableFu, isEnabledClickFu, openEditPageFu]);
|
|
|
|
|
|
return (
|
|
|
<div className={styles.Goods}>
|
|
@@ -437,12 +442,7 @@ function Goods() {
|
|
|
<div className="row">
|
|
|
<Button onClick={resetSelectFu}>重置</Button>{" "}
|
|
|
    
|
|
|
- <Button
|
|
|
- type="primary"
|
|
|
- onClick={() =>
|
|
|
- history.push(`/goods/edit?k=${pageNumRef.current}`)
|
|
|
- }
|
|
|
- >
|
|
|
+ <Button type="primary" onClick={() => openEditPageFu(0)}>
|
|
|
新增
|
|
|
</Button>
|
|
|
</div>
|
|
@@ -468,9 +468,15 @@ function Goods() {
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
|
- {/* 点击新增或者编辑出来的页面 */}
|
|
|
- {editPageShow?<GoodsAdd />:null}
|
|
|
-
|
|
|
+ {/* 点击新增或者编辑出来的页面 */}
|
|
|
+ {editPageShow ? (
|
|
|
+ <GoodsAdd
|
|
|
+ id={editId.current}
|
|
|
+ closePage={() => setEditPageShow(false)}
|
|
|
+ upTableList={getList}
|
|
|
+ addTableList={() => addTableListFu()}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
</div>
|
|
|
);
|
|
|
}
|