|
@@ -0,0 +1,284 @@
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
|
+import styles from "./index.module.scss";
|
|
|
+import {
|
|
|
+ Button,
|
|
|
+ Form,
|
|
|
+ FormInstance,
|
|
|
+ Input,
|
|
|
+ InputNumber,
|
|
|
+ Modal,
|
|
|
+ Popconfirm,
|
|
|
+ Select,
|
|
|
+} from "antd";
|
|
|
+import { A2addInfoType, A2inTableType, options1 } from "../data";
|
|
|
+import TextArea from "antd/es/input/TextArea";
|
|
|
+import ZupFileOne from "@/components/Z_upFileOne";
|
|
|
+import ZupFileOtherList from "@/components/Z_upFileOtherList";
|
|
|
+import { A2_APIaddSon } from "@/store/action/A2Goods";
|
|
|
+import { MessageFu } from "@/utils/message";
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ addInfo: A2addInfoType;
|
|
|
+ upTableFu: (item: A2inTableType) => void;
|
|
|
+ closeFu: () => void;
|
|
|
+};
|
|
|
+
|
|
|
+function A2AddModal({ addInfo, upTableFu, closeFu }: Props) {
|
|
|
+ // 获取详情的方法
|
|
|
+ const getInfoFu = useCallback((id: number) => {}, []);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (addInfo.txt === "新增") {
|
|
|
+ setDirCode(Date.now() + "");
|
|
|
+ } else getInfoFu(addInfo.id);
|
|
|
+ }, [addInfo.id, addInfo.txt, getInfoFu]);
|
|
|
+
|
|
|
+ // 表单的ref
|
|
|
+ const FormBoxRef = useRef<FormInstance>(null);
|
|
|
+ // FormBoxRef.current?.setFieldsValue(res.data);
|
|
|
+
|
|
|
+ // 目录码
|
|
|
+ const [dirCode, setDirCode] = useState("");
|
|
|
+
|
|
|
+ // 点击了提交的校验
|
|
|
+ const [isOk, setIsOk] = useState(false);
|
|
|
+
|
|
|
+ // 封面图
|
|
|
+ const [thumb, setThumb] = useState("");
|
|
|
+
|
|
|
+ // 附件的ref
|
|
|
+ const fileRef = useRef<any>(null);
|
|
|
+
|
|
|
+ // 没有通过校验
|
|
|
+ const onFinishFailed = useCallback(() => {
|
|
|
+ setIsOk(true);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // 通过校验点击确定
|
|
|
+ const onFinish = useCallback(
|
|
|
+ async (value: any) => {
|
|
|
+ setIsOk(true);
|
|
|
+
|
|
|
+ const fileIds = fileRef.current.fileIdsRefFu();
|
|
|
+
|
|
|
+ if (!thumb) return;
|
|
|
+
|
|
|
+ const size = [
|
|
|
+ value.sizeChang || " ",
|
|
|
+ value.sizeKuang || " ",
|
|
|
+ value.sizeGao || " ",
|
|
|
+ ];
|
|
|
+
|
|
|
+ const obj = {
|
|
|
+ ...value,
|
|
|
+ id: addInfo.txt === "新增" ? null : addInfo.id,
|
|
|
+ size: size.join(","),
|
|
|
+ thumb,
|
|
|
+ fileIds,
|
|
|
+ };
|
|
|
+
|
|
|
+ const res = await A2_APIaddSon(obj);
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success(`${addInfo.txt}成功!`);
|
|
|
+ upTableFu(res.data);
|
|
|
+ closeFu();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [addInfo.id, addInfo.txt, closeFu, thumb, upTableFu]
|
|
|
+ );
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Modal
|
|
|
+ wrapClassName={styles.A2AddModal}
|
|
|
+ open={true}
|
|
|
+ title={addInfo.txt}
|
|
|
+ footer={
|
|
|
+ [] // 设置footer为空,去掉 取消 确定默认按钮
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <div className="A2RAmain">
|
|
|
+ <Form
|
|
|
+ scrollToFirstError={true}
|
|
|
+ ref={FormBoxRef}
|
|
|
+ // labelCol={{ span: 2 }}
|
|
|
+ name="basic"
|
|
|
+ onFinish={onFinish}
|
|
|
+ onFinishFailed={onFinishFailed}
|
|
|
+ autoComplete="off"
|
|
|
+ >
|
|
|
+ <Form.Item
|
|
|
+ label="名称"
|
|
|
+ name="name"
|
|
|
+ rules={[{ required: true, message: "请输入名称!" }]}
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={20} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ label="编号"
|
|
|
+ name="num"
|
|
|
+ rules={[{ required: true, message: "请输入名称!" }]}
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={20} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <div className="A2RArow">
|
|
|
+ <Form.Item
|
|
|
+ label="时代"
|
|
|
+ name="dictAge"
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={10} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ label="质地"
|
|
|
+ name="dictTexture"
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={10} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="A2RArow A2RArow2">
|
|
|
+ <Form.Item
|
|
|
+ label="长"
|
|
|
+ name="sizeChang"
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={8} showCount placeholder="请输入长度" />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ label="宽"
|
|
|
+ name="sizeKuang"
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={8} showCount placeholder="请输入宽度" />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ label="高"
|
|
|
+ name="sizeGao"
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={8} showCount placeholder="请输入高度" />
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="A2RArow">
|
|
|
+ <Form.Item
|
|
|
+ label="重量"
|
|
|
+ name="quality"
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={8} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ className="A2RArowLabel"
|
|
|
+ label="实际数量"
|
|
|
+ name="pcs"
|
|
|
+ >
|
|
|
+ <InputNumber style={{width:256}} min={1} max={8} placeholder="请输入数字" />
|
|
|
+ {/* <Input maxLength={8} showCount /> */}
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="A2RArow">
|
|
|
+ <Form.Item
|
|
|
+ label="来源"
|
|
|
+ name="source"
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={10} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ className="A2RArowLabel"
|
|
|
+ label="完残程度"
|
|
|
+ name="complete"
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={10} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="A2RArow">
|
|
|
+ <Form.Item
|
|
|
+ label="级别"
|
|
|
+ name="dictLevel"
|
|
|
+ rules={[{ required: true, message: "请选择级别!" }]}
|
|
|
+ >
|
|
|
+ <Select
|
|
|
+ placeholder="请选择"
|
|
|
+ options={options1.filter((v) => v.label !== "全部")}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ className="A2RArowLabel"
|
|
|
+ label="定级时间"
|
|
|
+ name="levelTime"
|
|
|
+ getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
|
|
|
+ >
|
|
|
+ <Input maxLength={10} showCount placeholder="请输入内容" />
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <Form.Item label="简介" name="description">
|
|
|
+ <TextArea placeholder="请输入内容" showCount maxLength={200} />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <br />
|
|
|
+ <Form.Item className="A2RAbtn">
|
|
|
+ <Button type="primary" htmlType="submit">
|
|
|
+ 提交
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <Popconfirm
|
|
|
+ title="放弃编辑后,信息将不会保存!"
|
|
|
+ okText="放弃"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={closeFu}
|
|
|
+ okButtonProps={{ loading: false }}
|
|
|
+ >
|
|
|
+ <Button>取消</Button>
|
|
|
+ </Popconfirm>
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ <div className="A2RAmainRight">
|
|
|
+ {/* 封面图和附件 */}
|
|
|
+ <div className="A2RAFormRow">
|
|
|
+ <div className="A2RAFormRowll">
|
|
|
+ <span>* </span>封面:
|
|
|
+ </div>
|
|
|
+ <div className="A2RAFormRowrr">
|
|
|
+ <ZupFileOne
|
|
|
+ cover={thumb}
|
|
|
+ setCover={(val) => setThumb(val)}
|
|
|
+ isLook={addInfo.txt === "查看"}
|
|
|
+ coverCheck={isOk}
|
|
|
+ size={2}
|
|
|
+ dirCode={dirCode}
|
|
|
+ myUrl="cms/goods/file/upload"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div className="A2RAFormRow">
|
|
|
+ <div className="A2RAFormRowll">图片或附件:</div>
|
|
|
+ <div className="A2RAFormRowrr">
|
|
|
+ <ZupFileOtherList
|
|
|
+ max={30}
|
|
|
+ isLook={addInfo.txt === "查看"}
|
|
|
+ size={500}
|
|
|
+ dirCode={dirCode}
|
|
|
+ myUrl="cms/goods/file/upload"
|
|
|
+ ref={fileRef}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </Modal>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+const MemoA2AddModal = React.memo(A2AddModal);
|
|
|
+
|
|
|
+export default MemoA2AddModal;
|