|
|
@@ -0,0 +1,254 @@
|
|
|
+import React, {
|
|
|
+ useCallback,
|
|
|
+ useEffect,
|
|
|
+ useMemo,
|
|
|
+ useRef,
|
|
|
+ useState,
|
|
|
+} from "react";
|
|
|
+import styles from "./index.module.scss";
|
|
|
+import TextArea from "antd/es/input/TextArea";
|
|
|
+import { A2GoodObjTxt, A2addInfoType } from "@/pages/A2Goods/data";
|
|
|
+import { A2tableType } from "@/types";
|
|
|
+import { A3roomStatuType } from "../data";
|
|
|
+import { B1TieleObj } from "@/pages/B1Submit/data";
|
|
|
+import { API_roomTree } from "@/store/action/A4Roomset";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
+import { RootState } from "@/store";
|
|
|
+import { Button, Cascader, Popconfirm } from "antd";
|
|
|
+import {
|
|
|
+ A2_APIaddWaiRoom,
|
|
|
+ A2_APIgetInfoWai,
|
|
|
+ A2_APIinDels,
|
|
|
+} from "@/store/action/A2Goods";
|
|
|
+import { MessageFu } from "@/utils/message";
|
|
|
+import history from "@/utils/history";
|
|
|
+import B1Look from "@/pages/B1Submit/B1Look";
|
|
|
+import A2SelectModal from "@/pages/A2Goods/A2Register/A2SelectModal";
|
|
|
+import ZlistTable from "@/components/ZlistTable";
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ closeFu: () => void;
|
|
|
+ outInfo: A2addInfoType;
|
|
|
+ myType: A3roomStatuType;
|
|
|
+ // 从藏品查看页面点击注销进来
|
|
|
+ isLookItem?: A2tableType;
|
|
|
+};
|
|
|
+
|
|
|
+function A3RoomStatu({ closeFu, outInfo, myType, isLookItem }: Props) {
|
|
|
+ const dispatch = useDispatch();
|
|
|
+
|
|
|
+ // 获取下拉框树结构
|
|
|
+ useEffect(() => {
|
|
|
+ dispatch(API_roomTree());
|
|
|
+ }, [dispatch]);
|
|
|
+
|
|
|
+ const roomTree = useSelector((state: RootState) => state.A4Roomset.roomTree);
|
|
|
+
|
|
|
+ // 从 藏品查看也进来,直接把这条藏品信息添加到表格
|
|
|
+ useEffect(() => {
|
|
|
+ if (isLookItem && isLookItem.id) setTableList([isLookItem]);
|
|
|
+ }, [isLookItem]);
|
|
|
+
|
|
|
+ // 记录删除了的所有id集合
|
|
|
+ const delIdArr = useRef<number[]>([]);
|
|
|
+
|
|
|
+ // 当前审批的状态
|
|
|
+ const statusRef = useRef(0);
|
|
|
+
|
|
|
+ // 获取详情
|
|
|
+ const getInfoFu = useCallback(async (id: number) => {
|
|
|
+ const res = await A2_APIgetInfoWai(id);
|
|
|
+ if (res.code === 0) {
|
|
|
+ setTopValue(res.data.entity.description);
|
|
|
+ statusRef.current = res.data.entity.status;
|
|
|
+ setTableList(res.data.child);
|
|
|
+ const loc = res.data.entity.storageIds;
|
|
|
+ setRoomId(loc ? loc.split(",").map((v: any) => Number(v)) : undefined);
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (outInfo.txt !== "新增") getInfoFu(outInfo.id);
|
|
|
+ }, [getInfoFu, outInfo.id, outInfo.txt]);
|
|
|
+
|
|
|
+ // 表格信息
|
|
|
+ const [tableList, setTableList] = useState<A2tableType[]>([]);
|
|
|
+
|
|
|
+ // 申请说明字段
|
|
|
+ const [topValue, setTopValue] = useState("");
|
|
|
+
|
|
|
+ // 库房的选择
|
|
|
+ const [roomId, setRoomId] = useState<undefined | number[]>(undefined);
|
|
|
+
|
|
|
+ // 点击提交或者存草稿
|
|
|
+ const btnOkFu = useCallback(
|
|
|
+ async (status: 0 | 1) => {
|
|
|
+ if (!roomId) return MessageFu.warning("请选择库房!");
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ id:
|
|
|
+ outInfo.txt === "新增" || statusRef.current === 2 ? null : outInfo.id,
|
|
|
+ description: topValue,
|
|
|
+ goodsIds: tableList.map((v) => v.id).join(","),
|
|
|
+ status,
|
|
|
+ type: myType,
|
|
|
+ storageIds: roomId ? roomId.join(",") : null,
|
|
|
+ };
|
|
|
+
|
|
|
+ const res1 = await A2_APIaddWaiRoom(obj);
|
|
|
+
|
|
|
+ // 删除id集合
|
|
|
+ if (delIdArr.current.length > 0) {
|
|
|
+ await A2_APIinDels(delIdArr.current.join(","));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (res1.code === 0) {
|
|
|
+ MessageFu.success(`操作成功!`);
|
|
|
+ if (window.location.hash.includes("/submit")) {
|
|
|
+ history.replace("/404");
|
|
|
+ window.setTimeout(() => {
|
|
|
+ history.push("/submit");
|
|
|
+ }, 200);
|
|
|
+ } else history.push("/submit");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [myType, outInfo.id, outInfo.txt, roomId, tableList, topValue]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 点击表格的查看
|
|
|
+ const [lookId, setLookId] = useState(0);
|
|
|
+
|
|
|
+ // 表格的操作模块的列
|
|
|
+ const listTableBtn = useMemo(() => {
|
|
|
+ return {
|
|
|
+ title: "操作",
|
|
|
+ render: (item: A2tableType) => (
|
|
|
+ <>
|
|
|
+ <Button size="small" type="text" onClick={() => setLookId(item.id)}>
|
|
|
+ 查看
|
|
|
+ </Button>
|
|
|
+
|
|
|
+ <Popconfirm
|
|
|
+ title="删除后无法恢复,是否删除?"
|
|
|
+ okText="删除"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => {
|
|
|
+ delIdArr.current.push(item.id);
|
|
|
+ setTableList(tableList.filter((v) => v.id !== item.id));
|
|
|
+ MessageFu.success("删除成功!");
|
|
|
+ }}
|
|
|
+ okButtonProps={{ loading: false }}
|
|
|
+ >
|
|
|
+ <Button size="small" type="text" danger>
|
|
|
+ 删除
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+ </>
|
|
|
+ ),
|
|
|
+ };
|
|
|
+ }, [tableList]);
|
|
|
+
|
|
|
+ // 新增和编辑
|
|
|
+ const [addInfo, setAddInfo] = useState<A2addInfoType>({ id: 0, txt: "" });
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className={styles.A3RoomStatu}>
|
|
|
+ <div className="A3Rtop">
|
|
|
+ <div className="A3RTitle">{Reflect.get(B1TieleObj, myType)}</div>
|
|
|
+ <div className="A3RtopRow A3RtopRow1">
|
|
|
+ <div className="A3Rtopll">
|
|
|
+ <span>*</span> {Reflect.get(A2GoodObjTxt, myType)}库房:
|
|
|
+ </div>
|
|
|
+ <div className="A3Rtoprr">
|
|
|
+ <Cascader
|
|
|
+ // 自定义字段
|
|
|
+ fieldNames={{
|
|
|
+ label: "name",
|
|
|
+ value: "id",
|
|
|
+ children: "children",
|
|
|
+ }}
|
|
|
+ style={{ width: 160 }}
|
|
|
+ options={roomTree}
|
|
|
+ placeholder="全部"
|
|
|
+ value={roomId}
|
|
|
+ onChange={(e) => setRoomId(e as number[])}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div className="A3RtopRow">
|
|
|
+ <div className="A3Rtopll">申请说明:</div>
|
|
|
+ <div className="A3Rtoprr">
|
|
|
+ <TextArea
|
|
|
+ value={topValue}
|
|
|
+ onChange={(e) => setTopValue(e.target.value)}
|
|
|
+ placeholder="请输入内容"
|
|
|
+ showCount
|
|
|
+ maxLength={200}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="A3Rtable">
|
|
|
+ <div className="A3Rtable1">
|
|
|
+ <div>藏品清单:</div>
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ onClick={() => {
|
|
|
+ if (tableList.length >= 50)
|
|
|
+ return MessageFu.warning("最多支持50条藏品!");
|
|
|
+ setAddInfo({ id: -1, txt: "新增" });
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 新增
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ <div className="A3Rtable2">
|
|
|
+ <ZlistTable list={tableList} btnDom={listTableBtn} y={478} />
|
|
|
+ </div>
|
|
|
+ <div className="A3Rtable3">
|
|
|
+ <Button
|
|
|
+ disabled={!tableList.length}
|
|
|
+ type="primary"
|
|
|
+ onClick={() => btnOkFu(1)}
|
|
|
+ >
|
|
|
+ 提交
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <Button disabled={!tableList.length} onClick={() => btnOkFu(0)}>
|
|
|
+ 存草稿
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <Popconfirm
|
|
|
+ title="放弃编辑后,信息将不会保存!"
|
|
|
+ okText="放弃"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={closeFu}
|
|
|
+ okButtonProps={{ loading: false }}
|
|
|
+ >
|
|
|
+ <Button>取消</Button>
|
|
|
+ </Popconfirm>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 新增和编辑弹窗 */}
|
|
|
+ {addInfo.id ? (
|
|
|
+ <A2SelectModal
|
|
|
+ oldList={tableList}
|
|
|
+ closeFu={() => setAddInfo({ id: 0, txt: "" })}
|
|
|
+ upTableFu={(itemArr) => setTableList(itemArr)}
|
|
|
+ myType={myType as "RK" | "CK" | "YK"}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+
|
|
|
+ {/* 点击表格的查看 */}
|
|
|
+ {lookId ? (
|
|
|
+ <B1Look goodsId={lookId} closeFu={() => setLookId(0)} isCance={true} />
|
|
|
+ ) : null}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA3RoomStatu = React.memo(A3RoomStatu);
|
|
|
+
|
|
|
+export default MemoA3RoomStatu;
|