EditModal.tsx
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React, { useEffect, useState } from "react";
import { Modal, Form, Select, message, Skeleton } from "antd";
import { save, ListVO, queryBacklogList, BacklogItemVO, queryThresholds } from "../api";
import useInitial from "@/hooks/useInitail";
import SettingList from "./SettingList";
interface Props {
visible: boolean;
onCancel: () => void;
item?: ListVO;
onRefresh?: () => void;
}
export default ({ visible, onCancel, item, onRefresh }: Props) => {
const [form] = Form.useForm();
const [saveLoading, setSaveLoading] = useState(false);
const [loading, setLoading] = useState<boolean>();
const { data: BacklogList, setParams } = useInitial<BacklogItemVO[], any>(queryBacklogList, [], {});
useEffect(() => {
if (visible) {
setParams({}, true);
}
if (visible && item?.id) {
setLoading(true);
queryThresholds({ id: item?.id })
.then((res) => {
form.setFieldsValue({
configId: { value: item.configId, label: item.itemName },
interveneList: res.data || [],
});
setLoading(false);
})
.catch((e) => {
message.error(`干预配置查询失败:${e.message}`);
setLoading(false);
});
}
if (!visible) {
setSaveLoading(false);
form?.resetFields();
}
}, [visible]);
function handleSave(feildValue: any) {
setSaveLoading(true);
const params = {
...feildValue,
configId: feildValue?.configId.value,
id: item?.id,
};
save(params)
.then(() => {
message.success("操作成功");
onCancel?.();
onRefresh?.();
})
.catch((e) => message.error(e.message))
.finally(() => setSaveLoading(false));
}
return (
<Modal
open={visible}
onCancel={onCancel}
onOk={form.submit}
title={item?.id ? "编辑超时干预" : "新增超时干预"}
confirmLoading={saveLoading}
width="65%"
>
<Skeleton active loading={loading}>
<Form form={form} onFinish={handleSave} wrapperCol={{ span: 18 }} labelCol={{ span: 4 }}>
<Form.Item name="configId" label="待办" rules={[{ required: true, message: "待办不能为空" }]}>
<Select
placeholder="请选择"
disabled={!!item?.id}
showSearch
optionFilterProp="children"
labelInValue
filterOption={(input, option: any) => option?.children.indexOf(input) >= 0}
>
{BacklogList.map((item) => (
<Select.Option value={item.id} key={item.id}>
{item.itemName}
</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item name="interveneList" label="干预设置" rules={[{ required: true, message: "干预设置不能为空" }]}>
<SettingList saveLoading={saveLoading} />
</Form.Item>
</Form>
</Skeleton>
</Modal>
);
};