|
@@ -1,4 +1,4 @@
|
|
|
-import { historyApi } from "@/api";
|
|
|
+import { getMetaListApi, historyApi, overviewApi } from "@/api";
|
|
|
import {
|
|
|
DageUpload,
|
|
|
DageUploadConsumer,
|
|
@@ -9,6 +9,7 @@ import { HistoryDictItem } from "@/types";
|
|
|
import { Form, FormInstance, Input, Select } from "antd";
|
|
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
|
|
+import { DageCheckboxGroup } from "@/components/CheckboxGroup";
|
|
|
|
|
|
export default function HistoryCreateOrEdit() {
|
|
|
const navigate = useNavigate();
|
|
@@ -18,13 +19,53 @@ export default function HistoryCreateOrEdit() {
|
|
|
const formRef = useRef<FormInstance>(null);
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
const [dictList, setDictList] = useState<HistoryDictItem[]>([]);
|
|
|
+ const [metaList, setMetaList] = useState([]);
|
|
|
+ const [companyList, setCompanyList] = useState<
|
|
|
+ {
|
|
|
+ label: string;
|
|
|
+ value: number;
|
|
|
+ }[]
|
|
|
+ >([]);
|
|
|
+
|
|
|
+ const getCompanyList = async () => {
|
|
|
+ const data = await overviewApi.getList({
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 999,
|
|
|
+ });
|
|
|
+ setCompanyList(
|
|
|
+ data.records.map((i) => ({
|
|
|
+ label: i.name,
|
|
|
+ value: i.id,
|
|
|
+ }))
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
+ const getMetaList = async () => {
|
|
|
+ const data = await getMetaListApi();
|
|
|
+ setMetaList(
|
|
|
+ data.map((i: any) => ({
|
|
|
+ label: i.name,
|
|
|
+ value: i.id,
|
|
|
+ }))
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getMetaList();
|
|
|
+ getCompanyList();
|
|
|
+ }, []);
|
|
|
|
|
|
const getDetail = useCallback(async () => {
|
|
|
setLoading(true);
|
|
|
try {
|
|
|
- const { entity, file } = await historyApi.getDetail(params.id as string);
|
|
|
+ const {
|
|
|
+ entity: { mateIds, companyId, ...rest },
|
|
|
+ file,
|
|
|
+ } = await historyApi.getDetail(params.id as string);
|
|
|
formRef.current?.setFieldsValue({
|
|
|
- ...entity,
|
|
|
+ ...rest,
|
|
|
+ companyId: companyId ? Number(companyId) : null,
|
|
|
+ mateIds: mateIds ? mateIds.split(",").map((i) => Number(i)) : [],
|
|
|
fileIds: file.map((i) => ({
|
|
|
uid: i.id + "",
|
|
|
url: `${process.env.REACT_APP_API_URL}${i.filePath}`,
|
|
@@ -48,7 +89,11 @@ export default function HistoryCreateOrEdit() {
|
|
|
const handleSubmit = useCallback(async () => {
|
|
|
if (!(await formRef.current?.validateFields())) return;
|
|
|
|
|
|
- const { fileIds = [], ...rest } = formRef.current?.getFieldsValue();
|
|
|
+ const {
|
|
|
+ fileIds = [],
|
|
|
+ mateIds = [],
|
|
|
+ ...rest
|
|
|
+ } = formRef.current?.getFieldsValue();
|
|
|
|
|
|
if (params.id) {
|
|
|
rest.id = params.id;
|
|
@@ -56,6 +101,7 @@ export default function HistoryCreateOrEdit() {
|
|
|
|
|
|
await historyApi.add({
|
|
|
...rest,
|
|
|
+ mateIds: mateIds.join(","),
|
|
|
fileIds: fileIds
|
|
|
.map((i: any) => (!!i.response ? i.response.id : i.uid))
|
|
|
.join(),
|
|
@@ -108,6 +154,19 @@ export default function HistoryCreateOrEdit() {
|
|
|
disabled={readonly.current}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
+ <Form.Item label="所属企业" name="companyId">
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ showSearch
|
|
|
+ style={{ width: 200 }}
|
|
|
+ placeholder="请选择"
|
|
|
+ options={companyList}
|
|
|
+ disabled={readonly.current}
|
|
|
+ filterOption={(input, option) =>
|
|
|
+ (option?.label ?? "").includes(input)
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
<Form.Item label="企业" name="companyName">
|
|
|
<Input.TextArea
|
|
|
className="w450"
|
|
@@ -117,6 +176,13 @@ export default function HistoryCreateOrEdit() {
|
|
|
readOnly={readonly.current}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
+ <Form.Item label="所属工业" name="mateIds">
|
|
|
+ <DageCheckboxGroup
|
|
|
+ max={3}
|
|
|
+ options={metaList}
|
|
|
+ style={{ width: 650 }}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
<Form.Item label="简介" name="description">
|
|
|
<Input.TextArea
|
|
|
className="w450"
|