|
@@ -1,7 +1,7 @@
|
|
|
import BreadTit from "@/components/BreadTit";
|
|
|
import { object3AddAPI, object3infoOutAPI } from "@/store/action/object3";
|
|
|
import history, { urlParameter } from "@/utils/history";
|
|
|
-import { Button, Input, Popconfirm, Table } from "antd";
|
|
|
+import { Button, Cascader, Input, message, Popconfirm, Table } from "antd";
|
|
|
import TextArea from "antd/es/input/TextArea";
|
|
|
import React, {
|
|
|
useCallback,
|
|
@@ -18,8 +18,39 @@ import { RootState } from "@/store";
|
|
|
import ImageLazy from "@/components/ImageLazy";
|
|
|
import GoodsAll from "./GoodsAll";
|
|
|
import LookModal from "@/components/LookObjTable/LookModal";
|
|
|
+import { getStores1ListAPI } from "@/store/action/stores1";
|
|
|
function AddObject3() {
|
|
|
const dispatch = useDispatch();
|
|
|
+
|
|
|
+ // 进页面获取所有的库房信息
|
|
|
+ useEffect(() => {
|
|
|
+ dispatch(getStores1ListAPI());
|
|
|
+ }, [dispatch]);
|
|
|
+
|
|
|
+ // 从仓库中获取库房总信息
|
|
|
+ const storesAllList = useSelector(
|
|
|
+ (state: RootState) => state.stores1Store.infoList
|
|
|
+ );
|
|
|
+
|
|
|
+ // 从仓库拿表格信息
|
|
|
+ const results = useSelector(
|
|
|
+ (state: RootState) => state.object3Store.goodsTableList
|
|
|
+ );
|
|
|
+
|
|
|
+ // 针对表格信息扩展自己需要的 入库 级连 筛选信息
|
|
|
+ const storesLocArr = useRef<any>({});
|
|
|
+
|
|
|
+ // 级联筛选发生变化
|
|
|
+ const onChangeStores = useCallback(
|
|
|
+ (value: any, arr: any, id: number) => {
|
|
|
+ storesLocArr.current[id] = {
|
|
|
+ ids: value.join(","),
|
|
|
+ names: arr.map((v: any) => v.name).join("/"),
|
|
|
+ };
|
|
|
+ },
|
|
|
+ [storesLocArr]
|
|
|
+ );
|
|
|
+
|
|
|
// 顶部数据
|
|
|
const [addInfoTop, setAddInfoTop] = useState<any>({});
|
|
|
|
|
@@ -35,12 +66,27 @@ function AddObject3() {
|
|
|
}, [dispatch]);
|
|
|
|
|
|
// 通过id获取详情函数
|
|
|
- const object3infoOutAPIFu = useCallback(async (id: number) => {
|
|
|
- const res = await object3infoOutAPI(id);
|
|
|
- // setAddInfoTop(res.data);
|
|
|
- // // 获取表格详情信息
|
|
|
- // dispatch(getObj1InfoTableAPI(id));
|
|
|
- }, []);
|
|
|
+ const object3infoOutAPIFu = useCallback(
|
|
|
+ async (id: number) => {
|
|
|
+ const res = await object3infoOutAPI(id);
|
|
|
+ setAddInfoTop(res.data.entity);
|
|
|
+ // 设置表格信息
|
|
|
+ dispatch({
|
|
|
+ type: "object3/getGoodsTableList",
|
|
|
+ payload: res.data.child,
|
|
|
+ });
|
|
|
+ // 设置藏品位置ref
|
|
|
+ if (res.data.child && res.data.child.length) {
|
|
|
+ res.data.child.forEach((v: any) => {
|
|
|
+ storesLocArr.current[v.id] = {
|
|
|
+ ids: v.storageAncestor,
|
|
|
+ names: v.storageAncestorName,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [dispatch]
|
|
|
+ );
|
|
|
|
|
|
// 获取地址栏参数
|
|
|
const location = useLocation();
|
|
@@ -63,7 +109,26 @@ function AddObject3() {
|
|
|
}, [urlParam.d, urlParam.k]);
|
|
|
|
|
|
// 点击提交
|
|
|
- const submitFu = useCallback(() => {}, []);
|
|
|
+ const submitFu = useCallback(async () => {
|
|
|
+ if (results.length === 0)
|
|
|
+ return message.warning("至少需要添加一条藏品信息!");
|
|
|
+
|
|
|
+ const objLength = Object.keys(storesLocArr.current).length;
|
|
|
+ if (objLength < results.length) return message.warning("请选择藏品位置!");
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ description: addInfoTop.description,
|
|
|
+ id: addInfoTop.id,
|
|
|
+ goodsIds: results.map((v: any) => v.id).join(","),
|
|
|
+ location: storesLocArr.current,
|
|
|
+ };
|
|
|
+
|
|
|
+ const res: any = await object3AddAPI(obj);
|
|
|
+ if (res.code === 0) {
|
|
|
+ message.success("操作成功!");
|
|
|
+ cancelFu();
|
|
|
+ }
|
|
|
+ }, [addInfoTop.description, addInfoTop.id, cancelFu, results]);
|
|
|
|
|
|
// 点击添加或者编辑出来页面
|
|
|
const [addPage, setAddPage] = useState(false);
|
|
@@ -83,17 +148,17 @@ function AddObject3() {
|
|
|
// 选中的表格数据
|
|
|
const [tableSelectList, setTableSelectList] = useState([]);
|
|
|
|
|
|
- // 从仓库拿表格信息
|
|
|
- const results = useSelector(
|
|
|
- (state: RootState) => state.object3Store.goodsTableList
|
|
|
- );
|
|
|
-
|
|
|
// 点击删除
|
|
|
const delTableListFu = useCallback(() => {
|
|
|
console.log("多个删除", tableSelectList);
|
|
|
const data = _.differenceBy(results, tableSelectList, "id");
|
|
|
- dispatch({ type: "login/setGoodsSonList", payload: data });
|
|
|
+ dispatch({ type: "object3/getGoodsTableList", payload: data });
|
|
|
setTableSelectList(data);
|
|
|
+
|
|
|
+ // 同时删除藏品位置信息
|
|
|
+ tableSelectList.forEach((v: any) => {
|
|
|
+ delete storesLocArr.current[v.id];
|
|
|
+ });
|
|
|
}, [dispatch, results, tableSelectList]);
|
|
|
|
|
|
// 控制弹窗的显示隐藏
|
|
@@ -137,7 +202,25 @@ function AddObject3() {
|
|
|
},
|
|
|
{
|
|
|
title: "藏品位置",
|
|
|
- render: (item: any) => <>123</>,
|
|
|
+ width: 200,
|
|
|
+ render: (item: any) => (
|
|
|
+ <>
|
|
|
+ <Cascader
|
|
|
+ defaultValue={item.storageAncestorName.split(",")}
|
|
|
+ allowClear={false}
|
|
|
+ fieldNames={{
|
|
|
+ label: "name",
|
|
|
+ value: "id",
|
|
|
+ children: "children",
|
|
|
+ }}
|
|
|
+ onChange={(value, selectedOptions) =>
|
|
|
+ onChangeStores(value, selectedOptions, item.id)
|
|
|
+ }
|
|
|
+ options={storesAllList}
|
|
|
+ placeholder="请选择"
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ ),
|
|
|
},
|
|
|
{
|
|
|
title: "操作",
|
|
@@ -150,7 +233,7 @@ function AddObject3() {
|
|
|
),
|
|
|
},
|
|
|
];
|
|
|
- }, [lookGoods]);
|
|
|
+ }, [lookGoods, onChangeStores, storesAllList]);
|
|
|
|
|
|
return (
|
|
|
<div className={styles.AddObject3}>
|