EditModal.tsx
9.49 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import React, { useState, useEffect } from "react";
import { Form, Modal, message, Input, Select, Radio, Checkbox, InputNumber, Spin } from "antd";
import usePagination from "@/hooks/usePagination";
import { systemListApi } from "@/pages/admin/Privilege/api";
import { transformDTO, transformFormData } from "../entity";
import { KpiGroupSetteing } from "@/pages/performance/KpiGroupSetting/interface";
import * as api from "../../KpiGroupSetting/EditComfirm/api";
import { ShopList, saveQualitySetteing, qalityDetail } from "../api";
import { getAllPostListApi } from "@/common/api";
import ShopSelectNew from "@/components/ShopSelectNew";
import PersonModal from "./PersonModal";
import IndivatorsTable from "./IndivatorsTable";
import { QualitySetteing } from "@/pages/performance/QualitySetting/interface";
import useInitial from "@/hooks/useInitail";
const FormItem = Form.Item;
const { Option } = Select;
interface Props {
item: { visible: boolean; currentItem?: QualitySetteing.QualityListItems };
onClose?: (refresh?: boolean) => any;
setItem: Function;
roleList: CommonApi.RoleCodeVO[];
}
export default function EditModal({ onClose, setItem, item, roleList }: Props) {
const [form] = Form.useForm();
const { visible, currentItem = {} } = item;
const [saveLoading, setSaveLoading] = useState<boolean>(false);
const [type, setType] = useState<number>(2);
const { list: postList } = usePagination(getAllPostListApi, { pageSize: 999 }, {});
const [detailsDelay, setDetailsDelay] = useState<boolean>(true);
const { data: detailsData, setParams: setDetailsParams, loading } = useInitial(qalityDetail, {}, {}, detailsDelay);
// 选择岗位id
const [postId, setPostId] = useState<number>();
// 门店列表
const [shopList, setShopList] = useState<ShopList[]>([]);
// 人员查看模块
const [personModal, setPersonModal] = useState<QualitySetteing.Person>({
visible: false,
postId: 0,
shopIds: "",
shopNames: "",
});
// 存储角色列表
const { list } = usePagination(systemListApi, { current: 1, pageSize: 500 });
const onCel = () => {
onClose?.(false);
setPersonModal({ ...personModal, postId: 0, shopIds: "", shopNames: "" });
};
// 在这里发起获取详情数据的请求,拿到数据再写一个生命周期监听获取的数据
useEffect(() => {
if (visible && currentItem.id) {
setDetailsParams({ id: currentItem.id }, true);
setDetailsDelay(false);
getDealerList(currentItem.postId);
setPersonModal({
postId: currentItem.postId,
shopIds: currentItem.shopIds.join(","),
visible: false,
shopNames: currentItem.shopNames.join(","),
});
setType(currentItem.type);
}
}, [visible]);
// 监听到数据变化后将数据处理同时赋给表单,loading直接用详情的loading,有id就用详情的loading,实现了数据获取之前loading的加载,没有id直接写死fasle
useEffect(() => {
if (detailsData) {
const result = transformFormData(detailsData, roleList, list);
if (result.type == 1) {
result.rank = "";
result.details.forEach((item: any) => {
item.capPersonPenaltyScore = "";
item.capPersonPenaltyMoney = "";
item.awardScore = "";
item.capPersonAwardScore = "";
item.capAwardScore = "";
item.awardMoney = "";
item.capPersonAwardMoney = "";
item.capAwardMoney = "";
});
}
setItem({ ...item, currentItem: { ...result } });
form.setFieldsValue({ ...result });
}
}, [detailsData]);
// console.log("currentItem", currentItem);
function fetchSave(pa: any) {
setSaveLoading(true);
saveQualitySetteing(pa)
.then((res) => {
setSaveLoading(false);
message.success(res.result);
onClose?.(true);
})
.catch((e) => {
setSaveLoading(false);
message.error(e.message);
});
}
function handleSave(values: any) {
const pa = transformDTO(values);
if (currentItem.id) {
pa.id = currentItem.id;
}
console.log("tijiao", pa);
if (pa.type == 2) {
pa.details.forEach((item: any) => {
if (
item.capPersonPenaltyScore == undefined ||
item.capPersonPenaltyMoney == undefined ||
item.awardScore == undefined ||
item.capPersonAwardScore == undefined ||
item.capAwardScore == undefined ||
item.awardMoney == undefined ||
item.capPersonAwardMoney == undefined ||
item.capAwardMoney == undefined
) {
message.error("考核详情中存在没有填的内容");
} else {
fetchSave(pa);
}
});
} else {
delete pa.rank;
pa.details.forEach((item: any) => {
delete item.capPersonPenaltyScore;
delete item.capPersonPenaltyMoney;
delete item.awardScore;
delete item.capPersonAwardScore;
delete item.capAwardScore;
delete item.awardMoney;
delete item.capPersonAwardMoney;
delete item.capAwardMoney;
});
fetchSave(pa);
}
}
// 根据岗位查门店
function getDealerList(postId: number) {
api
.queryShopByPost(postId)
.then((res) => {
setShopList(res.data || []);
console.log("res", res.data);
})
.catch((e) => {
message.error(e.message);
});
}
// 人员查看
const personView = () => {
if (!personModal.postId) {
message.error("请选择岗位");
return;
}
if (!personModal.shopIds) {
message.error("请选择门店");
return;
}
setPersonModal({ ...personModal, visible: true });
};
return (
<>
<Modal
title={`${currentItem.id ? "编辑" : "新增"}人员质量考核`}
open={visible}
onOk={form.submit}
onCancel={() => onCel()}
maskClosable={false}
getContainer={false}
confirmLoading={saveLoading}
afterClose={() => form.resetFields()}
width={1200}
>
<Spin spinning={currentItem.id ? loading : false}>
<Form
form={form}
onFinish={handleSave}
// labelCol={{ span: 6 }}
// wrapperCol={{ span: 15 }}
style={{ width: "70%", marginLeft: 200 }}
>
<Form.Item name="post" label="岗位" rules={[{ required: true, message: "请选择岗位" }]}>
<Select
labelInValue
placeholder="请选择岗位"
allowClear
showSearch
optionFilterProp="children"
onChange={(post: { label: string; value: number; key: number }) => {
setPersonModal({
postId: post.value,
visible: false,
shopIds: "",
shopNames: "",
});
setPostId(post.value);
form.setFieldsValue({ shop: [] });
// 根据岗位查门店
if (post) {
getDealerList(post.value);
}
}}
>
{postList.map((item) => (
<Option value={item.id}>{item.postName}</Option>
))}
</Select>
</Form.Item>
<Form.Item name="shop" label="门店" rules={[{ required: true, message: "请选择门店" }]}>
<ShopSelectNew
multiple
shopIds={shopList.map((item) => item.shopId)}
type={2}
onChange={(
shops: {
key: number;
label: string;
value: number;
}[]
) => {
const shopIds = shops.map((item) => item.value).join(",");
const shopNames = shops.map((item) => item.label).join(",");
setPersonModal({ ...personModal, shopIds, shopNames });
}}
/>
</Form.Item>
<Form.Item name="type" label="人员状态" rules={[{ required: true, message: "请选择人员状态" }]}>
<Radio.Group>
<Radio value={1}>星级为D级员工</Radio>
<Radio value={2}>转正后保护期员工</Radio>
</Radio.Group>
</Form.Item>
<Form.Item noStyle shouldUpdate={(prevValues, currentValues) => prevValues.type !== currentValues.type}>
{({ getFieldValue }) => {
const newType = getFieldValue("type");
setType(newType);
return newType === 2 ? (
<Form.Item name="rank" label="排名目标" rules={[{ required: true, message: "请填写排名目标" }]}>
<InputNumber addonAfter="名" min={1} precision={0} style={{ width: "720px" }} />
</Form.Item>
) : null;
}}
</Form.Item>
<div style={{ marginBottom: 20 }}>
<a onClick={() => personView()}>{`人员清单 >`}</a>
</div>
<Form.Item name="details" label="考核详情" rules={[{ required: true }]}>
<IndivatorsTable
postId={postId}
personModal={personModal}
type={type}
currentItem={currentItem}
loading={loading}
/>
</Form.Item>
</Form>
</Spin>
</Modal>
<PersonModal item={personModal} setPersonModal={setPersonModal} type={type} />
</>
);
}