AddEvaGroupModal.tsx
9.68 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/* eslint-disable no-return-assign */
/* eslint-disable no-return-assign */
import React, { useEffect, useState } from "react";
import { Modal, Form, Select, InputNumber, message, Spin, Radio, Input, Button, DatePicker } from "antd";
import { saveRewardsListApi } from "../RewardsList/api";
import { useStore } from "../index";
import _ from "lodash";
import useInitail from "@/hooks/useInitail";
import { EvaGroupSetteing } from "@/pages/performance/EvaGroupSetting/interface";
import * as api from "@/pages/performance/KpiGroupSetting/EditComfirm/api";
import ShopSelectNew from "@/components/ShopSelectNew";
import PersonModal from "@/pages/performance/KpiGroupSetting/components/PersonModal";
import { transformDTO } from "../entity";
import IndivatorsTable from "./IndivatorsTable";
import RewardsTableSal from "./RewardsTableSal";
import moment from "moment";
import { getManagerRoleListApi } from "@/common/api";
const Option = Select.Option;
const { RangePicker } = DatePicker;
interface Props {
visible: boolean;
onCancel: Function;
onOk: (vales: any) => void;
evaItem: EvaGroupSetteing.EvalGroups;
scopeType: number;
setScopeType: Function;
}
export default function AddIndicatorsModal(props: Props) {
const { postList, readOnly } = useStore();
const [roleList, setRoleList] = useState<any>([]);
const { visible, onCancel, onOk, evaItem, scopeType, setScopeType } = props;
const [form] = Form.useForm();
// 选择岗位id
const [postId, setPostId] = useState<number>();
// 门店列表
const [shopList, setShopList] = useState<EvaGroupSetteing.ShopList[]>([]);
// 人员查看模块
const [personModal, setPersonModal] = useState<EvaGroupSetteing.Person>({
visible: false,
postId: undefined,
shopIds: "",
});
// visible变化时(修改等)
useEffect(() => {
getRoleList();
if (visible && evaItem.name) {
if (evaItem.shop) {
const shopIds = evaItem.shop.map((item) => item.value);
setPersonModal({
shopIds: shopIds.join(","),
visible: false,
});
}
if (evaItem.shop && evaItem.post) {
const shopIds = evaItem.shop.map((item) => item.value);
const postId = evaItem.post.value;
setPersonModal({
postId,
shopIds: shopIds.join(","),
visible: false,
});
}
console.log("evaItem", evaItem);
form.setFieldsValue({
...evaItem,
});
}
}, [visible]);
// 查询门店
useEffect(() => {
if (evaItem.post) {
getDealerList(evaItem.post.value);
}
}, [evaItem]);
console.log("shopList", shopList);
// 查询管理角色
function getRoleList() {
getManagerRoleListApi()
.then((res) => {
setRoleList(res.data || []);
})
.catch((e) => {
message.error(e.message);
});
}
// 根据岗位查门店
function getDealerList(postId: number) {
api
.queryShopByPost(postId)
.then((res) => {
setShopList(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 });
};
function handSubmit(fieldsValue: any) {
const res = transformDTO(fieldsValue);
let pa = { ...res, force: true };
onOk(pa);
console.log("考评组", pa);
onCancel && onCancel();
}
return (
<Modal
title={`${evaItem.name ? "编辑" : "新增"}考评组`}
visible={visible}
maskClosable={false}
afterClose={() => {
form.resetFields();
onCancel();
}}
onCancel={() => onCancel()}
onOk={form.submit}
width={1400}
>
<Form form={form} labelCol={{ span: 6 }} wrapperCol={{ span: 16 }} onFinish={handSubmit}>
<Form.Item name="name" label="考评组名称" rules={[{ required: true, message: "请输入名称" }]}>
<Input placeholder="请输入考评组名称" disabled={readOnly} />
</Form.Item>
<Form.Item label="考评时间" name="time" rules={[{ required: true, message: "请选择考评时间" }]}>
<RangePicker
style={{ width: 900 }}
disabled={readOnly}
disabledDate={(current) => current && current < moment().add(-1, "days").endOf("day")}
/>
</Form.Item>
<Form.Item label="考评范围" name="scopeType" rules={[{ required: true, message: "请选择考评范围" }]}>
<Radio.Group disabled={readOnly} onChange={(e) => setScopeType(e.target.value)}>
<Radio value={1}>人员考评</Radio>
<Radio value={2}>门店考评</Radio>
</Radio.Group>
</Form.Item>
<Form.Item
noStyle
shouldUpdate={(prevValues, currentValues) => prevValues.scopeType !== currentValues.scopeType}
>
{({ getFieldValue }) =>
getFieldValue("scopeType") === 1 ? (
<Form.Item name="post" label="岗位" rules={[{ required: true, message: "请选择岗位" }]}>
<Select
labelInValue
placeholder="请选择岗位"
allowClear
disabled={readOnly}
showSearch
optionFilterProp="children"
onChange={(post: { label: string; value: number; key: number }) => {
setPersonModal({
postId: post.value,
visible: false,
shopIds: "",
});
setPostId(post.value);
form.setFieldsValue({ shop: [] });
// 根据岗位查门店
if (post) {
getDealerList(post.value);
}
}}
>
{postList.map((item) => (
<Option value={item.id}>{item.postName}</Option>
))}
</Select>
</Form.Item>
) : null
}
</Form.Item>
<Form.Item
noStyle
shouldUpdate={(prevValues, currentValues) => prevValues.scopeType !== currentValues.scopeType}
>
{({ getFieldValue }) => {
const scopeType = getFieldValue("scopeType");
return (
<Form.Item name="shop" label="门店" rules={[{ required: true, message: "请选择门店" }]}>
<ShopSelectNew
multiple
disabled={readOnly}
shopIds={scopeType === 1 ? shopList.map((item) => item.shopId) : []}
type={scopeType === 1 ? 2 : 1}
onChange={(
shops: {
key: number;
label: string;
value: number;
}[]
) => {
const shopIds = shops.map((item) => item.value).join(",");
setPersonModal({ ...personModal, shopIds });
}}
/>
</Form.Item>
);
}}
</Form.Item>
<Form.Item
noStyle
shouldUpdate={(prevValues, currentValues) => prevValues.scopeType !== currentValues.scopeType}
>
{({ getFieldValue }) =>
getFieldValue("scopeType") === 1 ? (
<div style={{ marginBottom: 20, marginLeft: 250 }}>
<a onClick={() => personView()}>{`人员查看 >`}</a>
</div>
) : null
}
</Form.Item>
<Form.Item
noStyle
shouldUpdate={(prevValues, currentValues) => prevValues.scopeType !== currentValues.scopeType}
>
{({ getFieldValue }) =>
getFieldValue("scopeType") === 2 ? (
<Form.Item name="role" label="门店奖惩分配" rules={[{ required: true, message: "请选择管理角色" }]}>
<Select
labelInValue
placeholder="请选择管理角色"
allowClear
disabled={readOnly}
showSearch
optionFilterProp="children"
>
{roleList.map((item) => (
<Option value={item.roleCode}>{item.roleName}</Option>
))}
</Select>
</Form.Item>
) : null
}
</Form.Item>
<Form.Item noStyle shouldUpdate={(prevValues, currentValues) => prevValues.rewards !== currentValues.rewards}>
{({ getFieldValue }) => {
const rewards = getFieldValue("rewards");
return (
<Form.Item name="indicators" label="考评指标" rules={[{ required: !(rewards && rewards.length > 0) }]}>
<IndivatorsTable postId={postId} personModal={personModal} scopeType={scopeType} />
</Form.Item>
);
}}
</Form.Item>
<Form.Item
noStyle
shouldUpdate={(prevValues, currentValues) => prevValues.indicators !== currentValues.indicators}
>
{({ getFieldValue }) => {
const indicators = getFieldValue("indicators");
return (
<Form.Item name="rewards" label="考评奖惩" rules={[{ required: !(indicators && indicators.length > 0) }]}>
<RewardsTableSal postId={postId} personModal={personModal} scopeType={scopeType} />
</Form.Item>
);
}}
</Form.Item>
</Form>
<PersonModal item={personModal} setPersonModal={setPersonModal} />
</Modal>
);
}