|
@@ -1,26 +1,68 @@
|
|
|
-import { FC, useRef } from "react";
|
|
|
+import { FC, Key, useEffect, useRef, useState } from "react";
|
|
|
import { DatePicker, Form, Input, InputNumber } from "antd";
|
|
|
import {
|
|
|
EditableFormInstance,
|
|
|
EditableProTable,
|
|
|
} from "@ant-design/pro-components";
|
|
|
-import { useNavigate } from "react-router-dom";
|
|
|
-import { uniqueId } from "lodash";
|
|
|
+import { useNavigate, useParams } from "react-router-dom";
|
|
|
+import { isString, uniqueId } from "lodash";
|
|
|
import { FileTemplateTable, FormPageFooter, PageContainer } from "@/components";
|
|
|
import { DEFAULT_BONUS_ITEM } from "../../../../constants";
|
|
|
import { TableBonusType } from "../../types";
|
|
|
import style from "./index.module.scss";
|
|
|
+import { dayjs, formatDate } from "@dage/utils";
|
|
|
+import { getManageIndexDetailApi, saveManageIndexApi } from "@/api";
|
|
|
+import { DageLoading } from "@dage/pc-components";
|
|
|
+import { IManageIndexDetail } from "@/types";
|
|
|
|
|
|
const { TextArea } = Input;
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
|
const CreateOrEditManagementIndex: FC = () => {
|
|
|
const navigate = useNavigate();
|
|
|
+ const params = useParams();
|
|
|
+ const isEdit = isString(params.id);
|
|
|
+ const [loading, setLoading] = useState(false);
|
|
|
+ const [detail, setDetail] = useState<IManageIndexDetail | null>(null);
|
|
|
const [form] = Form.useForm();
|
|
|
/** 加分项列表 */
|
|
|
const bonusRef = useRef<EditableFormInstance<TableBonusType>>();
|
|
|
+ const [bounsEditableKeys, setBounsEditableKeys] = useState<Key[]>([]);
|
|
|
// 减分项列表
|
|
|
const deductionRef = useRef<EditableFormInstance<TableBonusType>>();
|
|
|
+ const [deductionEditableKeys, setDeductionEditableKeys] = useState<Key[]>([]);
|
|
|
+
|
|
|
+ const getDetail = async () => {
|
|
|
+ try {
|
|
|
+ setLoading(true);
|
|
|
+ const data = await getManageIndexDetailApi(params.id!);
|
|
|
+ form.setFieldsValue({
|
|
|
+ name: data.name,
|
|
|
+ date: [dayjs(data.dateStart), dayjs(data.dateEnd)],
|
|
|
+ remark: data.remark,
|
|
|
+ materialIds: data.materials,
|
|
|
+ bonus: data.jsonAdd ? JSON.parse(data.jsonAdd) : undefined,
|
|
|
+ deduction: data.jsonSub ? JSON.parse(data.jsonSub) : undefined,
|
|
|
+ });
|
|
|
+ if (data.jsonAdd) {
|
|
|
+ setBounsEditableKeys(
|
|
|
+ JSON.parse(data.jsonAdd).map(
|
|
|
+ (i: IManageIndexDetail["materials"][number]) => i.id
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (data.jsonSub) {
|
|
|
+ setDeductionEditableKeys(
|
|
|
+ JSON.parse(data.jsonSub).map(
|
|
|
+ (i: IManageIndexDetail["materials"][number]) => i.id
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ setDetail(data);
|
|
|
+ } finally {
|
|
|
+ setLoading(false);
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
if (
|
|
@@ -30,13 +72,31 @@ const CreateOrEditManagementIndex: FC = () => {
|
|
|
)
|
|
|
return;
|
|
|
|
|
|
- console.log(form.getFieldsValue());
|
|
|
+ const { date, materialIds, bonus, deduction, ...rest } =
|
|
|
+ form.getFieldsValue();
|
|
|
+ if (materialIds)
|
|
|
+ rest.materialIds = materialIds.map((i: any) => i.id).join(",");
|
|
|
+ if (bonus) rest.jsonAdd = JSON.stringify(bonus);
|
|
|
+ if (deduction) rest.jsonSub = JSON.stringify(deduction);
|
|
|
+
|
|
|
+ await saveManageIndexApi({
|
|
|
+ ...rest,
|
|
|
+ dateStart: formatDate(date[0], "YYYY-MM-DD"),
|
|
|
+ dateEnd: formatDate(date[1], "YYYY-MM-DD"),
|
|
|
+ type: params.type,
|
|
|
+ id: detail?.id,
|
|
|
+ });
|
|
|
+ navigate(-1);
|
|
|
};
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ isEdit && getDetail();
|
|
|
+ }, []);
|
|
|
+
|
|
|
return (
|
|
|
- <PageContainer title="新增考核">
|
|
|
+ <PageContainer title={isEdit ? "编辑考核" : "新增考核"}>
|
|
|
<Form labelCol={{ span: 4 }} form={form} onFinish={handleSubmit}>
|
|
|
- <Form.Item label="考核名称" required>
|
|
|
+ <Form.Item label="考核名称" name="name" rules={[{ required: true }]}>
|
|
|
<Input
|
|
|
className="mw650"
|
|
|
placeholder="请输入内容,最多20字"
|
|
@@ -44,10 +104,10 @@ const CreateOrEditManagementIndex: FC = () => {
|
|
|
maxLength={20}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="考核周期" required>
|
|
|
- <RangePicker />
|
|
|
+ <Form.Item label="考核周期" required name="date">
|
|
|
+ <RangePicker format="YYYY-MM-DD" />
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="说明">
|
|
|
+ <Form.Item label="说明" name="remark">
|
|
|
<TextArea
|
|
|
className="mw650"
|
|
|
showCount
|
|
@@ -57,8 +117,11 @@ const CreateOrEditManagementIndex: FC = () => {
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
|
|
|
- <Form.Item label="需上传资料" name="file">
|
|
|
- {/* <FileTemplateTable tips="注:该资料用于此次整体考核,与具体指标无关" /> */}
|
|
|
+ <Form.Item label="需上传资料" name="materialIds">
|
|
|
+ <FileTemplateTable
|
|
|
+ module="assess"
|
|
|
+ tips="注:该资料用于此次整体考核,与具体指标无关"
|
|
|
+ />
|
|
|
</Form.Item>
|
|
|
|
|
|
<Form.Item label="附加项">
|
|
@@ -138,12 +201,14 @@ const CreateOrEditManagementIndex: FC = () => {
|
|
|
]}
|
|
|
editable={{
|
|
|
type: "multiple",
|
|
|
+ editableKeys: bounsEditableKeys,
|
|
|
actionRender: (row, config, defaultDoms) => {
|
|
|
return [defaultDoms.delete];
|
|
|
},
|
|
|
onValuesChange: (record, recordList) => {
|
|
|
form.setFieldValue("bonus", recordList);
|
|
|
},
|
|
|
+ onChange: setBounsEditableKeys,
|
|
|
}}
|
|
|
/>
|
|
|
</Form.Item>
|
|
@@ -215,12 +280,14 @@ const CreateOrEditManagementIndex: FC = () => {
|
|
|
]}
|
|
|
editable={{
|
|
|
type: "multiple",
|
|
|
+ editableKeys: deductionEditableKeys,
|
|
|
actionRender: (row, config, defaultDoms) => {
|
|
|
return [defaultDoms.delete];
|
|
|
},
|
|
|
onValuesChange: (record, recordList) => {
|
|
|
form.setFieldValue("deduction", recordList);
|
|
|
},
|
|
|
+ onChange: setDeductionEditableKeys,
|
|
|
}}
|
|
|
/>
|
|
|
</Form.Item>
|
|
@@ -228,6 +295,8 @@ const CreateOrEditManagementIndex: FC = () => {
|
|
|
|
|
|
<FormPageFooter onSubmit={handleSubmit} onCancel={() => navigate(-1)} />
|
|
|
</Form>
|
|
|
+
|
|
|
+ {loading && <DageLoading />}
|
|
|
</PageContainer>
|
|
|
);
|
|
|
};
|