|
|
@@ -1,12 +1,223 @@
|
|
|
-import React from "react";
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
- function A4Roomset() {
|
|
|
-
|
|
|
+import { Button, Input, Popconfirm, Table } from "antd";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
+import { MessageFu } from "@/utils/message";
|
|
|
+import { A4_APIdel, A4_APIgetList } from "@/store/action/A4Roomset";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import { A4tableType } from "@/types";
|
|
|
+import { A4addInfoType } from "./data";
|
|
|
+import A4AddModal from "./A4AddModal";
|
|
|
+import A4SonAdd from "./A4SonAdd";
|
|
|
+function A4Roomset() {
|
|
|
+ const dispatch = useDispatch();
|
|
|
+
|
|
|
+ // 筛选和分页
|
|
|
+ const [tableSelect, setTableSelect] = useState({
|
|
|
+ searchKey: "",
|
|
|
+ });
|
|
|
+
|
|
|
+ // 发送接口的函数
|
|
|
+ const getListFu = useCallback(() => {
|
|
|
+ dispatch(A4_APIgetList(tableSelect));
|
|
|
+ }, [dispatch, tableSelect]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getListFu();
|
|
|
+ }, [getListFu]);
|
|
|
+
|
|
|
+ // 输入框的改变
|
|
|
+ const txtTimeRef = useRef(-1);
|
|
|
+ const txtChangeFu = useCallback(
|
|
|
+ (txt: string, key: "searchKey") => {
|
|
|
+ clearTimeout(txtTimeRef.current);
|
|
|
+ txtTimeRef.current = window.setTimeout(() => {
|
|
|
+ setTableSelect({ ...tableSelect, [key]: txt });
|
|
|
+ }, 500);
|
|
|
+ },
|
|
|
+ [tableSelect]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 点击重置
|
|
|
+ const [inputKey, setInputKey] = useState(1);
|
|
|
+ const resetSelectFu = useCallback(() => {
|
|
|
+ // 把2个输入框和时间选择器清空
|
|
|
+ setInputKey(Date.now());
|
|
|
+ setTableSelect({
|
|
|
+ searchKey: "",
|
|
|
+ });
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const A2TableList = useSelector(
|
|
|
+ (state: RootState) => state.A4Roomset.tableInfo
|
|
|
+ );
|
|
|
+
|
|
|
+ // 点击删除
|
|
|
+ const delFu = useCallback(
|
|
|
+ async (id: number) => {
|
|
|
+ const res = await A4_APIdel(id);
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success("删除成功!");
|
|
|
+ getListFu();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [getListFu]
|
|
|
+ );
|
|
|
+
|
|
|
+ const columns = useMemo(() => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: "库房名称",
|
|
|
+ dataIndex: "name",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "库房编号",
|
|
|
+ dataIndex: "num",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "货架数量",
|
|
|
+ render: (item: A4tableType) => (item.pcs ? item.pcs : 0),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "备注",
|
|
|
+ render: (item: A4tableType) =>
|
|
|
+ item.description ? (
|
|
|
+ item.description.length >= 50 ? (
|
|
|
+ <span style={{ cursor: "pointer" }} title={item.description}>
|
|
|
+ {item.description.substring(0, 50) + "..."}
|
|
|
+ </span>
|
|
|
+ ) : (
|
|
|
+ item.description
|
|
|
+ )
|
|
|
+ ) : (
|
|
|
+ "(空)"
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "操作",
|
|
|
+ render: (item: A4tableType) => (
|
|
|
+ <>
|
|
|
+ <Button
|
|
|
+ size="small"
|
|
|
+ type="text"
|
|
|
+ onClick={() =>
|
|
|
+ setAddInfo({
|
|
|
+ id: item.id,
|
|
|
+ level: 1,
|
|
|
+ txt: "编辑",
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 编辑
|
|
|
+ </Button>
|
|
|
+ <Button size="small" type="text" onClick={() => setSonId(item.id)}>
|
|
|
+ 货架管理
|
|
|
+ </Button>
|
|
|
+
|
|
|
+ {item.id !== 1 ? (
|
|
|
+ <Popconfirm
|
|
|
+ title="删除后无法恢复,是否删除?"
|
|
|
+ okText="删除"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => delFu(item.id)}
|
|
|
+ >
|
|
|
+ <Button size="small" type="text" danger>
|
|
|
+ 删除
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+ ) : null}
|
|
|
+ </>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }, [delFu]);
|
|
|
+
|
|
|
+ // 新增和编辑
|
|
|
+ const [addInfo, setAddInfo] = useState<A4addInfoType>({
|
|
|
+ id: 0,
|
|
|
+ level: 1,
|
|
|
+ txt: "",
|
|
|
+ });
|
|
|
+
|
|
|
+ // 货架管理
|
|
|
+ const [sonId, setSonId] = useState(0);
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.A4Roomset}>
|
|
|
<div className="pageTitle">库房设置</div>
|
|
|
+
|
|
|
+ {/* 顶部筛选 */}
|
|
|
+ <div className="A4top">
|
|
|
+ {/* 左侧输入框 */}
|
|
|
+ <div className="A4top1">
|
|
|
+ <div className="A4topRow">
|
|
|
+ <span>搜索项:</span>
|
|
|
+ <Input
|
|
|
+ key={inputKey}
|
|
|
+ maxLength={10}
|
|
|
+ style={{ width: 240 }}
|
|
|
+ placeholder="请输入库房编号,最多10字"
|
|
|
+ allowClear
|
|
|
+ onChange={(e) => txtChangeFu(e.target.value, "searchKey")}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ {/* 右侧按钮 */}
|
|
|
+ <div className="A4top2">
|
|
|
+ <Button onClick={resetSelectFu}>重置</Button> 
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ onClick={() => {
|
|
|
+ if (A2TableList.length >= 20)
|
|
|
+ return MessageFu.warning("最多创建20个库房!");
|
|
|
+ setAddInfo({ id: -1, level: 1, txt: "新增" });
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 新增
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 表格主体 */}
|
|
|
+ <div className="tableMain">
|
|
|
+ <Table
|
|
|
+ // 不用展示 子结构表格
|
|
|
+ expandable={{ childrenColumnName: "my" }}
|
|
|
+ scroll={{ y: 675 }}
|
|
|
+ dataSource={A2TableList}
|
|
|
+ columns={columns}
|
|
|
+ rowKey="id"
|
|
|
+ pagination={false}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 新增和编辑的弹窗 */}
|
|
|
+ {addInfo.id ? (
|
|
|
+ <A4AddModal
|
|
|
+ addInfo={addInfo}
|
|
|
+ closeFu={() => setAddInfo({ id: 0, level: 1, txt: "" })}
|
|
|
+ upTableFu={getListFu}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+
|
|
|
+ {/* 点击 货架管理出来的页面*/}
|
|
|
+ {sonId ? (
|
|
|
+ <A4SonAdd
|
|
|
+ parentId={sonId}
|
|
|
+ closeFu={() => {
|
|
|
+ getListFu();
|
|
|
+ setSonId(0);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
</div>
|
|
|
- )
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
const MemoA4Roomset = React.memo(A4Roomset);
|