Blame view

src/pages/performance/EvaGroupSetting/EditComfirm/components/AddRewardsModal.tsx 16.6 KB
cd477b8c   曾柯   考评0213
1
2
3
4
5
  import React, { useEffect, useState } from "react";
  import { Modal, Form, Select, InputNumber, message, Input, Button, Radio } from "antd";
  import { useStore } from "../index";
  import _ from "lodash";
  import Rule1 from "@/pages/performance/CompensateGroupConfig/components/Rule1";
0b59354a   曾柯   考评组设置1656
6
  import { EvaGroupSetteing } from "@/pages/performance/EvaGroupSetting/interface";
cd477b8c   曾柯   考评0213
7
  import SingleAmount from "@/pages/performance/CompensateGroupConfig/EditComfirm/components/SingleAmount";
5ac136b7   曾柯   考评组设置1620
8
  import TotalAmountSal from "./TotalAmountSal";
cd477b8c   曾柯   考评0213
9
  import FixedCommission from "@/pages/performance/CompensateGroupConfig/EditComfirm/components/FixedCommission";
5ac136b7   曾柯   考评组设置1620
10
11
  import CommissionParamsSal from "./CommissionParamsSal";
  import LadderParamsSal from "./LadderParamsSal";
4927eb1a   曾柯   考评组设置加列表及草稿
12
  import RankModal from "./RankModal";
cd477b8c   曾柯   考评0213
13
  import { Any } from "currency.js";
5ac136b7   曾柯   考评组设置1620
14
  import CondsSal from "./CondsSal";
cd477b8c   曾柯   考评0213
15
16
17
18
19
20
  
  const Option = Select.Option;
  interface Props {
    visible: boolean;
    onCancel: Function;
    onOk: (vales: any) => void;
0b59354a   曾柯   考评组设置1656
21
    currentItem: EvaGroupSetteing.Rewards;
cd477b8c   曾柯   考评0213
22
23
24
    indicatorsList?: any[];
    postId?: number;
    shopIds?: string;
5ac136b7   曾柯   考评组设置1620
25
    scopeType: number;
cd477b8c   曾柯   考评0213
26
27
28
29
30
31
32
33
34
  }
  
  export default function CreateModal(props: Props) {
    const [form] = Form.useForm();
    const {
      ladderParamAlias,
      setLadderParamAlias,
      commissionParamAlias,
      setCommissionParamAlias,
5ac136b7   曾柯   考评组设置1620
35
      preconditionAliasSal,
0b59354a   曾柯   考评组设置1656
36
      setPreconditionAliasSal,
4927eb1a   曾柯   考评组设置加列表及草稿
37
38
      calType,
      setCalType,
cd477b8c   曾柯   考评0213
39
    } = useStore();
5ac136b7   曾柯   考评组设置1620
40
    const { visible, onCancel, onOk, currentItem, indicatorsList = [], postId, shopIds, scopeType } = props;
cd477b8c   曾柯   考评0213
41
42
43
  
    // 是否为百分比
    const [isPercent, setIsPercent] = useState<number>(0);
4927eb1a   曾柯   考评组设置加列表及草稿
44
  
cd477b8c   曾柯   考评0213
45
46
47
48
49
50
51
    // 判断占比相加是否为100
    const [isHundred, setIsHundred] = useState(false);
    const [isHundredLadder, setIsHundredLadder] = useState(false);
    // 显示前置条件
    const [condsVisible, setCondsVisible] = useState(false);
  
    const [id, setItemId] = useState<number>();
f2dd0995   曾柯   考评编辑bugfix
52
    
cd477b8c   曾柯   考评0213
53
54
55
56
    useEffect(() => {
      if (visible && currentItem.name) {
        setLadderParamAlias(currentItem.ladderParamAlias);
        setCommissionParamAlias(currentItem.commissionParamAlias);
0b59354a   曾柯   考评组设置1656
57
        setPreconditionAliasSal(currentItem.preconditionAlias);
cd477b8c   曾柯   考评0213
58
59
        //编辑时存储当前薪酬项目的计算方式
        setCalType(currentItem.calMethod);
0b59354a   曾柯   考评组设置1656
60
61
62
        // if (currentItem.settings[0].stairKeyDesc !== undefined && currentItem.calMethod === 4) {
        //   setFixData(currentItem.settings);
        // }
cd477b8c   曾柯   考评0213
63
64
65
66
67
68
        if (currentItem.conds && currentItem.conds.length > 0) {
          setCondsVisible(true);
        } else {
          setCondsVisible(false);
        }
        form.setFieldsValue({
0b59354a   曾柯   考评组设置1656
69
          ...currentItem,
cd477b8c   曾柯   考评0213
70
71
72
73
74
75
76
        });
      }
      if (!currentItem.name) {
        setCondsVisible(false);
      }
    }, [visible]);
  
cd477b8c   曾柯   考评0213
77
78
    // 保存Modal
    function handSubmit(fieldsValue: any) {
4927eb1a   曾柯   考评组设置加列表及草稿
79
      const pa: any = fieldsValue;
cd477b8c   曾柯   考评0213
80
81
82
83
84
85
86
87
88
89
90
91
92
      // 校验标准分不能大于绩效分值
      // if (id) {
      //   pa.id = id;
      // } else {
      //   pa.id = pa.name;
      // }
      if (pa?.ladderParams && pa?.ladderParams.length > 0) {
        pa.ladderParamAlias = ladderParamAlias;
      }
      if (pa?.commissionParams && pa?.commissionParams.length > 0) {
        pa.commissionParamAlias = commissionParamAlias;
      }
      if (pa?.conds && pa?.conds.length > 0) {
5ac136b7   曾柯   考评组设置1620
93
        pa.preconditionAlias = preconditionAliasSal;
cd477b8c   曾柯   考评0213
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
      }
      let hundred = 0;
      let ladderHundred = 0;
      //设置sort
      if (pa?.commissionParams && pa?.commissionParams.length > 0) {
        pa?.commissionParams.forEach((item: any, index: number) => {
          Object.assign(item, { sort: index + 1 });
        });
        hundred = pa?.commissionParams.reduce((data: number, item: any) => {
          return data + item.proportion;
        }, 0);
      }
      if (pa?.ladderParams && pa?.ladderParams.length > 0) {
        pa?.ladderParams.forEach((item: any, index: number) => {
          Object.assign(item, { sort: index + 1 });
        });
        ladderHundred = pa?.ladderParams.reduce((data: number, item: any) => {
          return data + item.proportion;
        }, 0);
        if (isPercent == 0) {
          pa.laddersType = currentItem.laddersType;
        } else {
          pa.laddersType = isPercent;
        }
      }
      if (!pa?.ladderParams || pa?.ladderParams.length === 0) {
        pa.laddersType = 2;
      }
      if (pa?.conds) {
        pa?.conds.forEach((item: any, index: number) => {
          Object.assign(item, { sort: index + 1 });
        });
      }
      if (pa?.ladderParams && pa?.ladderParams.length > 0 && pa?.commissionParams && pa?.commissionParams.length > 0) {
        if (hundred === 100 && ladderHundred === 100) {
          setIsHundred(false);
          setIsHundredLadder(false);
          onOk(pa);
          console.log("100pa", pa);
          onCancel && onCancel();
        } else if (hundred === 100 && ladderHundred !== 100) {
          setIsHundred(false);
          setIsHundredLadder(true);
        } else if (hundred !== 100 && ladderHundred === 100) {
          setIsHundred(true);
          setIsHundredLadder(false);
        } else {
          setIsHundred(true);
          setIsHundredLadder(true);
        }
      } else if (!pa?.ladderParams && pa?.commissionParams && pa?.commissionParams.length > 0) {
        if (hundred === 100) {
          setIsHundred(false);
          onOk(pa);
          console.log("100pa", pa);
          onCancel && onCancel();
        } else {
          setIsHundred(true);
        }
      } else if (pa?.ladderParams && pa?.commissionParams && pa?.commissionParams.length === 0) {
        if (ladderHundred === 100) {
          setIsHundredLadder(false);
          onOk(pa);
          console.log("100pa", pa);
          onCancel && onCancel();
        } else {
          setIsHundredLadder(true);
        }
      } else if (pa?.ladderParams && pa?.commissionParams == undefined) {
        if (ladderHundred === 100) {
          setIsHundredLadder(false);
          onOk(pa);
          console.log("100pa", pa);
          onCancel && onCancel();
        } else {
          setIsHundredLadder(true);
        }
      } else if (pa?.commissionParams == undefined) {
        setIsHundred(false);
        onOk(pa);
        console.log("100pa", pa);
        onCancel && onCancel();
      } else if (pa?.commissionParams && pa?.commissionParams.length == 0) {
        setIsHundred(false);
        onOk(pa);
        console.log("100pa", pa);
        onCancel && onCancel();
      }
    }
  
cd477b8c   曾柯   考评0213
184
185
    return (
      <Modal
0b59354a   曾柯   考评组设置1656
186
        title={`${currentItem.name ? "编辑" : "新增"}考评奖惩`}
cd477b8c   曾柯   考评0213
187
188
189
190
191
192
193
194
195
196
        visible={visible}
        maskClosable={false}
        afterClose={() => {
          form.resetFields();
          onCancel();
        }}
        onCancel={() => onCancel()}
        onOk={form.submit}
        width={1200}
      >
5ac136b7   曾柯   考评组设置1620
197
198
199
200
201
        <Form
          form={form}
          labelCol={{ span: 4 }}
          wrapperCol={{ span: 20 }}
          onFinish={handSubmit}
a34f5d4b   曾柯   考评bugfix
202
203
204
          initialValues={{
            ladders: [{ lower: 0, money: 0, key: 0 }],
          }}
5ac136b7   曾柯   考评组设置1620
205
        >
0b59354a   曾柯   考评组设置1656
206
          <Form.Item name="name" label="考评奖惩指标名称" rules={[{ required: true, message: "请输入指标名称" }]}>
cd477b8c   曾柯   考评0213
207
208
209
210
211
            <Input placeholder="请输入指标名称" />
          </Form.Item>
  
          <Form.Item
            noStyle
4927eb1a   曾柯   考评组设置加列表及草稿
212
            shouldUpdate={(prevValues, currentValues) => prevValues.calMethod !== currentValues.calMethod}
cd477b8c   曾柯   考评0213
213
214
215
216
217
218
219
220
221
          >
            {({ getFieldValue }) => {
              return (
                <Form.Item name="calMethod" label="计算方式" rules={[{ required: true, message: "请选择计算方式" }]}>
                  <Select
                    placeholder="选择计算方式"
                    onChange={(value) => {
                      const _type = value;
                      setCalType(_type);
4927eb1a   曾柯   考评组设置加列表及草稿
222
                      console.log(calType);
cd477b8c   曾柯   考评0213
223
224
225
                    }}
                  >
                    <Option value={1} key={1}>
0b59354a   曾柯   考评组设置1656
226
                      排名正负激励
cd477b8c   曾柯   考评0213
227
228
                    </Option>
                    <Option value={2} key={2}>
0b59354a   曾柯   考评组设置1656
229
                      固定值
cd477b8c   曾柯   考评0213
230
231
232
233
234
                    </Option>
                    <Option value={3} key={3}>
                      阶梯
                    </Option>
                    <Option value={4} key={4}>
0b59354a   曾柯   考评组设置1656
235
236
237
238
                      总金额占比
                    </Option>
                    <Option value={5} key={5}>
                      阶梯翻倍
cd477b8c   曾柯   考评0213
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
                    </Option>
                  </Select>
                </Form.Item>
              );
            }}
          </Form.Item>
  
          <div style={{ marginLeft: 95, marginBottom: 20 }}>
            <span>是否添加前置条件设置:</span>
            <Radio.Group
              onChange={(e) => {
                setCondsVisible(e.target.value);
              }}
              value={condsVisible}
            >
              <Radio value>是</Radio>
              <Radio value={false}>否</Radio>
            </Radio.Group>
          </div>
5ac136b7   曾柯   考评组设置1620
258
          {condsVisible && (
cd477b8c   曾柯   考评0213
259
            <Form.Item name="conds" label="前置条件">
5ac136b7   曾柯   考评组设置1620
260
              <CondsSal postId={postId} shopIds={shopIds} setItemId={setItemId} scopeType={scopeType} />
cd477b8c   曾柯   考评0213
261
            </Form.Item>
5ac136b7   曾柯   考评组设置1620
262
263
          )}
          <Form.Item
cd477b8c   曾柯   考评0213
264
265
266
267
268
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.calMethod !== currentValues.calMethod}
          >
            {({ getFieldValue }) => {
              const caculateType = getFieldValue("calMethod");
a34f5d4b   曾柯   考评bugfix
269
              if (caculateType !== 1) {
cd477b8c   曾柯   考评0213
270
271
272
273
274
275
276
                return (
                  <>
                    <Form.Item
                      name="commissionParams"
                      label="提成指标"
                      rules={[{ required: caculateType == 2 || caculateType == 4, message: "请增加提成指标" }]}
                    >
5ac136b7   曾柯   考评组设置1620
277
                      <CommissionParamsSal
cd477b8c   曾柯   考评0213
278
279
280
281
                        postId={postId}
                        shopIds={shopIds}
                        setItemId={setItemId}
                        isHundred={isHundred}
5ac136b7   曾柯   考评组设置1620
282
                        scopeType={scopeType}
cd477b8c   曾柯   考评0213
283
284
285
286
287
288
289
290
                      />
                    </Form.Item>
                  </>
                );
              } else {
                return null;
              }
            }}
5ac136b7   曾柯   考评组设置1620
291
292
          </Form.Item>
          <Form.Item
cd477b8c   曾柯   考评0213
293
294
295
296
297
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.calMethod !== currentValues.calMethod}
          >
            {({ getFieldValue }) => {
              const caculateType = getFieldValue("calMethod");
5ac136b7   曾柯   考评组设置1620
298
              if (caculateType == 1) {
cd477b8c   曾柯   考评0213
299
                return (
5ac136b7   曾柯   考评组设置1620
300
                  <>
a34f5d4b   曾柯   考评bugfix
301
302
303
304
305
306
307
308
309
310
311
312
313
                    <Form.Item
                      name="ladderParams"
                      label="台阶条件指标"
                      rules={[{ required: true, message: "请增加台阶条件指标" }]}
                    >
                      <LadderParamsSal
                        postId={postId}
                        shopIds={shopIds}
                        setItemId={setItemId}
                        isHundredLadder={isHundredLadder}
                        scopeType={scopeType}
                      />
                    </Form.Item>
5ac136b7   曾柯   考评组设置1620
314
315
316
317
318
319
                    <Form.Item name="rankType" label="排名方式" rules={[{ required: true, message: "请选择排名方式" }]}>
                      <Radio.Group>
                        <Radio value={1}>按固定值 </Radio>
                        <Radio value={2}>按比例</Radio>
                      </Radio.Group>
                    </Form.Item>
27123514   曾柯   考评组排名倒数
320
321
322
323
324
325
                    {/* <Form.Item name="rankOrderType" label="排名顺序" rules={[{ required: true, message: "请选择排名顺序" }]}>
                      <Radio.Group>
                        <Radio value={1}>正数</Radio>
                        <Radio value={2}>倒数</Radio>
                      </Radio.Group>
                    </Form.Item> */}
5ac136b7   曾柯   考评组设置1620
326
                    <Form.Item
4927eb1a   曾柯   考评组设置加列表及草稿
327
328
                      noStyle
                      shouldUpdate={(prevValues, currentValues) => prevValues.rankType !== currentValues.rankType}
5ac136b7   曾柯   考评组设置1620
329
                    >
4927eb1a   曾柯   考评组设置加列表及草稿
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
                      {({ getFieldValue }) => {
                        const rankType = getFieldValue("rankType");
                        if (rankType == 1) {
                          setIsPercent(1);
                        } else {
                          setIsPercent(2);
                        }
                        return null;
                      }}
                    </Form.Item>
                    <Form.Item
                      noStyle
                      shouldUpdate={(prevValues, currentValues) => prevValues.rankType !== currentValues.rankType}
                    >
                      {({ getFieldValue }) => {
                        const rankType = getFieldValue("rankType");
a34f5d4b   曾柯   考评bugfix
346
                        if (rankType == 1 && !currentItem.ladders) {
27123514   曾柯   考评组排名倒数
347
                          form.setFieldValue("ladders", [{ lower: 1, money: 0, key: 0, rankOrderType: 1 }]);
a34f5d4b   曾柯   考评bugfix
348
                        } else if (rankType == 2 && !currentItem.ladders) {
27123514   曾柯   考评组排名倒数
349
                          form.setFieldValue("ladders", [{ lower: 0, money: 0, key: 0, rankOrderType: 1 }]);
4927eb1a   曾柯   考评组设置加列表及草稿
350
351
352
353
354
355
356
                        }
                        return (
                          <Form.Item
                            name="ladders"
                            label="排名设置"
                            rules={[{ required: true, message: "请配置排名" }]}
                            style={{ width: "100%" }}
4927eb1a   曾柯   考评组设置加列表及草稿
357
358
359
360
                          >
                            <RankModal
                              visible
                              isPercent={isPercent}
27123514   曾柯   考评组排名倒数
361
                              laddersType={currentItem?.laddersType}
4927eb1a   曾柯   考评组设置加列表及草稿
362
363
364
365
366
367
                              calType={calType}
                              rankType={rankType}
                            />
                          </Form.Item>
                        );
                      }}
5ac136b7   曾柯   考评组设置1620
368
                    </Form.Item>
5ac136b7   曾柯   考评组设置1620
369
                  </>
cd477b8c   曾柯   考评0213
370
                );
5ac136b7   曾柯   考评组设置1620
371
              } else if (caculateType == 2 || caculateType == 4) {
cd477b8c   曾柯   考评0213
372
                return (
5ac136b7   曾柯   考评组设置1620
373
374
375
376
377
378
379
380
381
382
                  <>
                    <Form.Item
                      label="金额"
                      name="money"
                      rules={[{ required: true, message: "请输入金额" }]}
                      style={{ marginLeft: 0 }}
                    >
                      <InputNumber style={{ width: 960 }} addonAfter="元" />
                    </Form.Item>
                  </>
cd477b8c   曾柯   考评0213
383
                );
5ac136b7   曾柯   考评组设置1620
384
              } else if (caculateType == 3 || caculateType == 5) {
cd477b8c   曾柯   考评0213
385
386
387
388
389
390
391
                return (
                  <>
                    <Form.Item
                      name="ladderParams"
                      label="台阶条件指标"
                      rules={[{ required: true, message: "请增加台阶条件指标" }]}
                    >
5ac136b7   曾柯   考评组设置1620
392
                      <LadderParamsSal
cd477b8c   曾柯   考评0213
393
394
395
396
                        postId={postId}
                        shopIds={shopIds}
                        setItemId={setItemId}
                        isHundredLadder={isHundredLadder}
5ac136b7   曾柯   考评组设置1620
397
                        scopeType={scopeType}
cd477b8c   曾柯   考评0213
398
399
400
401
402
                      />
                    </Form.Item>
                  </>
                );
              }
cd477b8c   曾柯   考评0213
403
404
              return null;
            }}
5ac136b7   曾柯   考评组设置1620
405
406
407
          </Form.Item>
  
          <Form.Item
cd477b8c   曾柯   考评0213
408
409
410
411
412
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.ladderParams !== currentValues.ladderParams}
          >
            {({ getFieldValue }) => {
              const ladderParams = getFieldValue("ladderParams");
4927eb1a   曾柯   考评组设置加列表及草稿
413
414
              const calMethod = getFieldValue("calMethod");
              if (ladderParams && ladderParams.length > 0 && (calMethod == 3 || calMethod == 5)) {
cd477b8c   曾柯   考评0213
415
416
417
418
419
420
421
422
423
424
425
426
427
428
                console.log("ladderParams", ladderParams);
                if (ladderParams.length > 1) {
                  setIsPercent(2);
                } else if (ladderParams[0].targetValue) {
                  setIsPercent(2);
                } else if (ladderParams[0].dataType === 2) {
                  setIsPercent(2);
                } else if (ladderParams[0].dataType === 1 || ladderParams[0].dataType === 3) {
                  console.log("hasvdhjasvhdj");
                  setIsPercent(1);
                }
              }
              return null;
            }}
5ac136b7   曾柯   考评组设置1620
429
430
          </Form.Item>
          <Form.Item
cd477b8c   曾柯   考评0213
431
            noStyle
4927eb1a   曾柯   考评组设置加列表及草稿
432
            shouldUpdate={(prevValues, currentValues) => prevValues.calMethod !== currentValues.calMethod}
cd477b8c   曾柯   考评0213
433
434
435
436
          >
            {({ getFieldValue }) => {
              const caculateType = getFieldValue("calMethod");
              //阶梯(总)
4927eb1a   曾柯   考评组设置加列表及草稿
437
              if (caculateType == 3 || caculateType == 5) {
a34f5d4b   曾柯   考评bugfix
438
                if (caculateType == 3 && !currentItem.ladders) {
4927eb1a   曾柯   考评组设置加列表及草稿
439
                  form.setFieldValue("ladders", [{ lower: 0, money: 0, key: 0 }]);
a34f5d4b   曾柯   考评bugfix
440
                } else if (caculateType == 5 && !currentItem.ladders) {
4927eb1a   曾柯   考评组设置加列表及草稿
441
442
                  form.setFieldValue("ladders", [{ lower: 0, money: 0, capMoney: 0, key: 0 }]);
                }
a34f5d4b   曾柯   考评bugfix
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
                  return (
                    <>
                      <Form.Item
                        name="ladders"
                        label="阶梯条件"
                        rules={[{ required: true, message: "请配置阶梯" }]}
                        style={{ width: "100%" }}
                      >
                        <TotalAmountSal
                          visible
                          isPercent={isPercent}
                          laddersType={currentItem.laddersType}
                          calType={calType}
                        />
                      </Form.Item>
                    </>
                  );
              }
cd477b8c   曾柯   考评0213
461
462
              return null;
            }}
5ac136b7   曾柯   考评组设置1620
463
          </Form.Item>
cd477b8c   曾柯   考评0213
464
465
466
467
        </Form>
      </Modal>
    );
  }