|
@@ -12,14 +12,25 @@ import {
|
|
} from "antd";
|
|
} from "antd";
|
|
import { PlusOutlined, CloseCircleOutlined } from "@ant-design/icons";
|
|
import { PlusOutlined, CloseCircleOutlined } from "@ant-design/icons";
|
|
import TextArea from "antd/es/input/TextArea";
|
|
import TextArea from "antd/es/input/TextArea";
|
|
-import React, { useCallback, useMemo, useRef, useState } from "react";
|
|
|
|
|
|
+import React, {
|
|
|
|
+ useCallback,
|
|
|
|
+ useEffect,
|
|
|
|
+ useMemo,
|
|
|
|
+ useRef,
|
|
|
|
+ useState,
|
|
|
|
+} from "react";
|
|
import styles from "./index.module.scss";
|
|
import styles from "./index.module.scss";
|
|
import classNames from "classnames";
|
|
import classNames from "classnames";
|
|
import "./index.css";
|
|
import "./index.css";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import { RootState } from "@/store";
|
|
import { RootState } from "@/store";
|
|
import ImageLazy from "../ImageLazy";
|
|
import ImageLazy from "../ImageLazy";
|
|
-import { goodsSonAddAPI, object1AddUpFileAPI } from "@/store/action/object1";
|
|
|
|
|
|
+import {
|
|
|
|
+ delInfileAPI,
|
|
|
|
+ getInfoInAPI,
|
|
|
|
+ goodsSonAddAPI,
|
|
|
|
+ object1AddUpFileAPI,
|
|
|
|
+} from "@/store/action/object1";
|
|
const { Option } = Select;
|
|
const { Option } = Select;
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
@@ -37,7 +48,8 @@ function ObjectAdd({ id, colsePage, editId, dirCode }: Props) {
|
|
setTitSelect("tit1");
|
|
setTitSelect("tit1");
|
|
return message.warning("有表单不符号规则!");
|
|
return message.warning("有表单不符号规则!");
|
|
};
|
|
};
|
|
- // 通过校验之后发送请求
|
|
|
|
|
|
+
|
|
|
|
+ // --------通过校验之后发送请求----------点击确定
|
|
const onFinish = async (values: any) => {
|
|
const onFinish = async (values: any) => {
|
|
const oldObj = {} as any;
|
|
const oldObj = {} as any;
|
|
for (const k in values) {
|
|
for (const k in values) {
|
|
@@ -47,8 +59,8 @@ function ObjectAdd({ id, colsePage, editId, dirCode }: Props) {
|
|
// 外形尺寸 3个 字段 变成一个组数
|
|
// 外形尺寸 3个 字段 变成一个组数
|
|
const size = [values.size1, values.size2, values.size3];
|
|
const size = [values.size1, values.size2, values.size3];
|
|
// 具体质量 + 单位
|
|
// 具体质量 + 单位
|
|
- let quality = "";
|
|
|
|
- if (values.quality) quality = values.quality + danweiValue;
|
|
|
|
|
|
+ let quality = [] as any;
|
|
|
|
+ if (values.quality) quality = [values.quality, danweiValue];
|
|
// 文件id
|
|
// 文件id
|
|
const fileIds = [] as any;
|
|
const fileIds = [] as any;
|
|
for (const k in results) {
|
|
for (const k in results) {
|
|
@@ -63,8 +75,9 @@ function ObjectAdd({ id, colsePage, editId, dirCode }: Props) {
|
|
|
|
|
|
const obj = {
|
|
const obj = {
|
|
...oldObj,
|
|
...oldObj,
|
|
- size,
|
|
|
|
- quality,
|
|
|
|
|
|
+ id: id ? id : null,
|
|
|
|
+ size: size.join(","),
|
|
|
|
+ quality: quality.join(","),
|
|
thumb: cover,
|
|
thumb: cover,
|
|
dirCode: dirCode + "",
|
|
dirCode: dirCode + "",
|
|
fileIds: fileIds.join(","),
|
|
fileIds: fileIds.join(","),
|
|
@@ -72,7 +85,12 @@ function ObjectAdd({ id, colsePage, editId, dirCode }: Props) {
|
|
dictAge,
|
|
dictAge,
|
|
dictTexture,
|
|
dictTexture,
|
|
};
|
|
};
|
|
- await dispatch(goodsSonAddAPI(obj));
|
|
|
|
|
|
+ await dispatch(goodsSonAddAPI(obj, id));
|
|
|
|
+
|
|
|
|
+ // 真正的删除
|
|
|
|
+ if (delFileList.current.length) {
|
|
|
|
+ await delInfileAPI(delFileList.current.join(","));
|
|
|
|
+ }
|
|
// 关闭弹窗
|
|
// 关闭弹窗
|
|
colsePage();
|
|
colsePage();
|
|
|
|
|
|
@@ -118,26 +136,74 @@ function ObjectAdd({ id, colsePage, editId, dirCode }: Props) {
|
|
const [danweiValue, setDanweiValue] = useState("kg");
|
|
const [danweiValue, setDanweiValue] = useState("kg");
|
|
|
|
|
|
// 设置表单初始数据(区分编辑和新增)
|
|
// 设置表单初始数据(区分编辑和新增)
|
|
|
|
+ const FormBoxRef = useRef<any>({});
|
|
|
|
+ const getInfoInAPIFu = useCallback(
|
|
|
|
+ async (id: number) => {
|
|
|
|
+ const res = await getInfoInAPI(id);
|
|
|
|
+ const data = res.data.entity;
|
|
|
|
+ const size = data.size.split(",");
|
|
|
|
+ const quality = data.quality.split(",");
|
|
|
|
+ const dictAge = data.dictAge.split(",");
|
|
|
|
+ const dictTexture = data.dictTexture.split(",");
|
|
|
|
+ FormBoxRef.current.setFieldsValue({
|
|
|
|
+ ...data,
|
|
|
|
+ size1: size[0],
|
|
|
|
+ size2: size[1],
|
|
|
|
+ size3: size[2],
|
|
|
|
+ quality: quality[0],
|
|
|
|
+ dictAge,
|
|
|
|
+ dictTexture,
|
|
|
|
+ });
|
|
|
|
+ // 具体质量的单位
|
|
|
|
+ setDanweiValue(quality[1]);
|
|
|
|
+ // 藏品图片
|
|
|
|
+ setCover(data.thumb);
|
|
|
|
+
|
|
|
|
+ const fileData = {
|
|
|
|
+ img: [],
|
|
|
|
+ video: [],
|
|
|
|
+ audio: [],
|
|
|
|
+ model: [],
|
|
|
|
+ doc: [],
|
|
|
|
+ } as any;
|
|
|
|
+ res.data.file.forEach((v: any) => {
|
|
|
|
+ fileData[v.type].push(v);
|
|
|
|
+ });
|
|
|
|
+ // 修改附件仓库信息
|
|
|
|
+ dispatch({ type: "login/setFileData", payload: fileData });
|
|
|
|
+ },
|
|
|
|
+ [dispatch]
|
|
|
|
+ );
|
|
|
|
|
|
- const defaultData = useRef<any>(null);
|
|
|
|
- if (id) {
|
|
|
|
- defaultData.current = {
|
|
|
|
- name: "编辑",
|
|
|
|
- dictNum: "索书号",
|
|
|
|
- dictAge: ["其他"],
|
|
|
|
- };
|
|
|
|
- } else {
|
|
|
|
- defaultData.current = {
|
|
|
|
- dictNum: options1[0].name ? options1[0].name : null,
|
|
|
|
- dictAge: ["地质年代", "显生宙", "新生代", "第四纪"],
|
|
|
|
- dictTexture: ["单一质地", "有机质", "竹"],
|
|
|
|
- dictGoodType: options4[0].name ? options4[0].name : null,
|
|
|
|
- dictLevel: options5[0].name ? options5[0].name : null,
|
|
|
|
- dictQualityScope: options6[0].name ? options6[0].name : null,
|
|
|
|
- complete: options7[0].name ? options7[0].name : null,
|
|
|
|
- dictCheckInScope: options9[0].name ? options9[0].name : null,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
|
|
+ // 进页面看看是编辑就 从仓库获取信息,新增就设置默认值
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (id) {
|
|
|
|
+ getInfoInAPIFu(id);
|
|
|
|
+ } else {
|
|
|
|
+ FormBoxRef.current.setFieldsValue({
|
|
|
|
+ dictNum: options1[0].name ? options1[0].name : null,
|
|
|
|
+ dictAge: ["地质年代", "显生宙", "新生代", "第四纪"],
|
|
|
|
+ dictTexture: ["单一质地", "有机质", "竹"],
|
|
|
|
+ dictGoodType: options4[0].name ? options4[0].name : null,
|
|
|
|
+ dictLevel: options5[0].name ? options5[0].name : null,
|
|
|
|
+ dictQualityScope: options6[0].name ? options6[0].name : null,
|
|
|
|
+ complete: options7[0].name ? options7[0].name : null,
|
|
|
|
+ dictCheckInScope: options9[0].name ? options9[0].name : null,
|
|
|
|
+ });
|
|
|
|
+ // 清空附件仓库信息
|
|
|
|
+ dispatch({ type: "login/setFileData", payload: {} });
|
|
|
|
+ }
|
|
|
|
+ }, [
|
|
|
|
+ dispatch,
|
|
|
|
+ getInfoInAPIFu,
|
|
|
|
+ id,
|
|
|
|
+ options1,
|
|
|
|
+ options4,
|
|
|
|
+ options5,
|
|
|
|
+ options6,
|
|
|
|
+ options7,
|
|
|
|
+ options9,
|
|
|
|
+ ]);
|
|
|
|
|
|
// -----------关于藏品附件的信息
|
|
// -----------关于藏品附件的信息
|
|
const [fileSelect, setFileSelect] = useState("img");
|
|
const [fileSelect, setFileSelect] = useState("img");
|
|
@@ -163,6 +229,9 @@ function ObjectAdd({ id, colsePage, editId, dirCode }: Props) {
|
|
[fileSelect]: results[fileSelect].filter((v: any) => v.id !== id),
|
|
[fileSelect]: results[fileSelect].filter((v: any) => v.id !== id),
|
|
};
|
|
};
|
|
dispatch({ type: "login/setFileData", payload: data });
|
|
dispatch({ type: "login/setFileData", payload: data });
|
|
|
|
+
|
|
|
|
+ // 把删除的id存起来
|
|
|
|
+ delFileList.current.push(id);
|
|
},
|
|
},
|
|
[dispatch, fileSelect, results]
|
|
[dispatch, fileSelect, results]
|
|
);
|
|
);
|
|
@@ -263,6 +332,8 @@ function ObjectAdd({ id, colsePage, editId, dirCode }: Props) {
|
|
|
|
|
|
const upFileFlagRef = useRef(false);
|
|
const upFileFlagRef = useRef(false);
|
|
|
|
|
|
|
|
+ const delFileList = useRef<any>([]);
|
|
|
|
+
|
|
const upFileFu = (flag?: any) => {
|
|
const upFileFu = (flag?: any) => {
|
|
upFileFlagRef.current = flag ? flag : 0;
|
|
upFileFlagRef.current = flag ? flag : 0;
|
|
myInput2.current?.click();
|
|
myInput2.current?.click();
|
|
@@ -298,6 +369,9 @@ function ObjectAdd({ id, colsePage, editId, dirCode }: Props) {
|
|
}),
|
|
}),
|
|
};
|
|
};
|
|
dispatch({ type: "login/setFileData", payload: data });
|
|
dispatch({ type: "login/setFileData", payload: data });
|
|
|
|
+
|
|
|
|
+ // 把删除的id存起来
|
|
|
|
+ delFileList.current.push(upFileFlagRef.current);
|
|
} else {
|
|
} else {
|
|
// 新上传
|
|
// 新上传
|
|
const data = {
|
|
const data = {
|
|
@@ -349,11 +423,11 @@ function ObjectAdd({ id, colsePage, editId, dirCode }: Props) {
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<Form
|
|
<Form
|
|
|
|
+ ref={FormBoxRef}
|
|
name="basic"
|
|
name="basic"
|
|
onFinish={onFinish}
|
|
onFinish={onFinish}
|
|
onFinishFailed={onFinishFailed}
|
|
onFinishFailed={onFinishFailed}
|
|
autoComplete="off"
|
|
autoComplete="off"
|
|
- initialValues={defaultData.current}
|
|
|
|
>
|
|
>
|
|
{/* -----------------------表单信息 */}
|
|
{/* -----------------------表单信息 */}
|
|
<div className="formBox" hidden={titSelect === "tit2"}>
|
|
<div className="formBox" hidden={titSelect === "tit2"}>
|