Blame view

src/pages/performance/EvaGroupSetting/EditComfirm/components/AddCommissionParamsModal.tsx 13.7 KB
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
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
  import React, { useEffect, useState } from "react";
  import { Modal, Form, Select, InputNumber, message, Spin, Radio, Input, Button } from "antd";
  import { saveRewardsListApi } from "../RewardsList/api";
  import { useStore } from "../index";
  import { queryPostIndicatorApi, queryShopIndicatorApi } from "@/pages/performance/EvaGroupSetting/EditComfirm/api";
  import _ from "lodash";
  import useInitail from "@/hooks/useInitail";
  import { EvaGroupSetteing } from "@/pages/performance/EvaGroupSetting/interface";
  import { TargetType, TargetTypeEnum } from "@/pages/performance/entity";
  
  const Option = Select.Option;
  interface Props {
    // visible: boolean;
    // onCancel: Function;
    // postId?: number;
    // shopIds?: string;
    // onOk: (vales: any) => void;
    // currentItem: KpiGroupSetteing.Item;
    // comItem: KpiGroupSetteing.CommissionParams;
    addComVisible: boolean;
    onCancel: Function;
    postId?: number;
    shopIds?: string;
    onOk: (vales: any) => void;
    comItem: Commission;
    setItemId: Function;
    scopeType: number;
d82a09c8   曾柯   考评预览报表及bugfix
28
    isOne: number;
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
29
30
31
  }
  type Commission = EvaGroupSetteing.CommissionParams;
  export default function AddCommissionParamsModal(props: Props) {
7722662b   曾柯   考评1524
32
    const percent = /^\d\.([1-9]{1,2}|[0-9][1-9])$|^[1-9]\d{0,1}(\.\d{1,2}){0,1}$|^100(\.0{1,2}){0,1}$/;
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
33
34
    const Momney = /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/;
    const [form] = Form.useForm();
3b951d34   曾柯   时间校验
35
    const { selectedIndicators, setParamAlias, setSelectedIndicators, stagesLength, multiStage } = useStore();
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
36
37
38
  
    const [isTarget, setIsTarget] = useState(false);
    // console.log(form);
d82a09c8   曾柯   考评预览报表及bugfix
39
    const { addComVisible, onCancel, postId, shopIds, onOk, comItem, setItemId, scopeType, isOne } = props;
35f42afa   曾柯   考评设置
40
    // 保存选中绩效指标需要配置的绩效考核目标值类型
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
41
42
43
44
45
46
47
48
    const [targetType, setTargetType] = useState<number>();
    // 保存选中指标是否考评类型
    const [codeType, setCodeType] = useState<number>();
    const [dataType, setDataType] = useState<number>();
    // 保存过滤后指标列表
    const [newIndicators, setNewIndicators] = useState<EvaGroupSetteing.IndicatorByPost[]>([]);
    const [indicatorName, setIndicatorName] = useState("");
    const [id, setId] = useState(0);
a3b0f319   曾柯   之前的绩效薪酬考评配置修改
49
    const [delay, setDelay] = useState(true);
c307b0cc   曾柯   考评组配置
50
    const { data: indicatorsList, setParams, loading } = useInitail(queryPostIndicatorApi, [], {}, delay);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
51
    useEffect(() => {
c307b0cc   曾柯   考评组配置
52
      setParams({ reward: false, withCombination: true }, true);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
53
54
55
56
      setDelay(false);
      setTargetType(1);
    }, [addComVisible]);
    // 修改
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
57
58
59
60
    useEffect(() => {
      if (indicatorsList && indicatorsList.length > 0 && !comItem.code) {
        const res = indicatorsList.filter((item) => !selectedIndicators.find((y) => y === item.code));
        setNewIndicators([...res]);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
61
62
      }
      if (addComVisible && comItem.code) {
c5c0ea29   曾柯   考评2002
63
        const indTar = indicatorsList.find((item: any) => item.code == comItem.code)?.targetType;
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
64
65
        setTargetType(indTar);
        setIndicatorName(comItem.name);
27123514   曾柯   考评组排名倒数
66
67
        setDataType(comItem.dataType);
        setCodeType(comItem.codeType);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
68
69
70
71
72
73
        form.setFieldsValue({
          ...comItem,
          commissionParams: {
            value: comItem.code,
            label: comItem.name,
          },
d82a09c8   曾柯   考评预览报表及bugfix
74
          proportion: comItem.proportion !== undefined ? comItem.proportion : isOne == 1 ? 100 : null,
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
75
76
77
78
79
        });
      }
      if (comItem.targetValue && comItem.targetCalcType) {
        setIsTarget(true);
      }
7722662b   曾柯   考评1524
80
81
82
      if (comItem.extraTargetValue && comItem.extraTargetCalcType) {
        setIsTarget(true);
      }
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    }, [indicatorsList]);
    useEffect(() => {
      if (targetType === TargetTypeEnum["无"]) {
        setIsTarget(false);
      }
    }, [targetType]);
    useEffect(() => {
      setIsTarget(false);
    }, [id]);
    // 校验表单数据
    function transformDTO(formData: any) {
      let detail = {};
      _.each(formData, (value: any, key: string) => {
        switch (key) {
          case "commissionParams":
            const _options = value || {};
ccdb0384   曾柯   考评组配置及数据导入
99
            console.log(_options);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
100
            detail.code = _options.key;
ccdb0384   曾柯   考评组配置及数据导入
101
            detail.name = _options.label[0];
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
102
103
104
105
106
107
108
109
110
111
112
            detail.code = _options.value;
            break;
          default:
            detail[key] = value;
            break;
        }
      });
      return detail;
    }
    function handSubmit(fieldsValue: any) {
      const pa: any = transformDTO(fieldsValue);
3b951d34   曾柯   时间校验
113
      pa.targetType = targetType;
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
114
115
116
117
118
119
120
121
      pa.codeType = codeType;
      pa.dataType = dataType;
      console.log("100pa", pa);
      const newItemId = pa.code;
      // 编辑时,不需要push id
      if (!comItem.code) {
        const tmpIds = [...selectedIndicators];
        tmpIds.push(newItemId);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
122
123
124
125
      } else {
        pa.code = comItem.code;
        pa.name = comItem.name;
      }
7722662b   曾柯   考评1524
126
127
128
      pa.extraTargetType = pa.targetType;
      if (comItem.codeType == 1 && multiStage) {
        if (pa.targetValue) {
c5c0ea29   曾柯   考评2002
129
          pa.targetType = targetType;
7722662b   曾柯   考评1524
130
          pa.targetCalcType = 3;
c5c0ea29   曾柯   考评2002
131
132
        } else {
          pa.targetType = 1;
7722662b   曾柯   考评1524
133
134
        }
        if (pa.extraTargetValue) {
c5c0ea29   曾柯   考评2002
135
          pa.extraTargetType = targetType;
7722662b   曾柯   考评1524
136
          pa.extraTargetCalcType = 4;
c5c0ea29   曾柯   考评2002
137
138
        } else {
          pa.extraTargetType = 1;
7722662b   曾柯   考评1524
139
        }
44b8cb0b   曾柯   考评
140
      }
7722662b   曾柯   考评1524
141
142
      onOk(pa);
      onCancel && onCancel();
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
143
    }
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
144
145
    return (
      <Modal
e9118a9b   曾柯   pc新版配置
146
        open={addComVisible}
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
147
148
149
150
151
152
153
154
155
156
157
        title={`${comItem.code ? "编辑" : "新增"}固定得分指标`}
        maskClosable={false}
        afterClose={() => {
          form.resetFields();
          onCancel();
        }}
        onCancel={() => onCancel()}
        onOk={form.submit}
        width={1000}
      >
        <Spin spinning={loading}>
23989b1c   曾柯   表单样式调整
158
159
          <Form
            form={form}
23989b1c   曾柯   表单样式调整
160
161
162
            onFinish={handSubmit}
            style={{ width: "70%", marginLeft: 150 }}
          >
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
163
164
            <Form.Item name="commissionParams" label="计分指标" rules={[{ required: true, message: "计分指标" }]}>
              <Select
ccdb0384   曾柯   考评组配置及数据导入
165
                placeholder="选择指标(*为考评指标,无*为绩效指标)"
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
166
167
168
169
170
171
172
                labelInValue
                disabled={!!comItem.code}
                onChange={(value, Option: any) => {
                  setTargetType(Option.targetType);
                  setItemId(Option.key);
                  setId(Option.key);
                  setIndicatorName(Option.children);
ccdb0384   曾柯   考评组配置及数据导入
173
                  setParamAlias(Option.name);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
174
175
176
177
178
179
180
181
182
183
184
185
186
                  setCodeType(Option.codeType);
                  setDataType(Option.dataType);
                }}
                showSearch
                optionFilterProp="children"
              >
                {newIndicators.map((item) => (
                  <Option
                    value={item.code}
                    key={item.id}
                    targetType={item.targetType}
                    dataType={item.dataType}
                    codeType={item.codeType}
ccdb0384   曾柯   考评组配置及数据导入
187
                    name={item.name}
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
188
                  >
23989b1c   曾柯   表单样式调整
189
190
                    {item.name}
                    {item.codeType == 2 ? "*" : ""}
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
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
                  </Option>
                ))}
              </Select>
            </Form.Item>
            <div style={{ display: "flex", justifyContent: "flex-start" }}>
              <Form.Item
                name="proportion"
                label="占比"
                rules={[
                  { pattern: percent, message: "请输入大于0小于等于100的数(最多保留两位小数)" },
                  { required: true, message: "请输入占比数" },
                ]}
                style={{ width: "100%" }}
              >
                <InputNumber style={{ width: "100%" }} addonAfter="%" />
              </Form.Item>
            </div>
            <Form.Item name="cap" label="是否封顶" rules={[{ required: true, message: "请选择" }]}>
              <Radio.Group>
                <Radio value>是</Radio>
                <Radio value={false}>否</Radio>
              </Radio.Group>
            </Form.Item>
            {(targetType === TargetTypeEnum["百分比"] ||
              targetType === TargetTypeEnum["金额"] ||
              targetType === TargetTypeEnum["数量"]) && (
23989b1c   曾柯   表单样式调整
217
              <div>
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
218
                <Button type="link" onClick={() => setIsTarget(true)}>
35f42afa   曾柯   考评设置
219
                  考核目标值设置(可选项)
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
220
221
222
                </Button>
                {isTarget && (
                  <Button type="link" onClick={() => setIsTarget(false)}>
35f42afa   曾柯   考评设置
223
                    删除该项考核目标设置
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
224
225
226
227
228
229
                  </Button>
                )}
              </div>
            )}
            {isTarget && (
              <>
35f42afa   曾柯   考评设置
230
                <Form.Item label="考核目标名称" name="targetName">
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
231
232
                  <Select disabled defaultValue={indicatorName} />
                </Form.Item>
44b8cb0b   曾柯   考评
233
234
235
236
237
                {comItem.codeType == 1 && multiStage ? (
                  <>
                    <Form.Item
                      noStyle
                      shouldUpdate={(prevValues, currentValues) =>
7722662b   曾柯   考评1524
238
                        prevValues.extraTargetValue !== currentValues.extraTargetValue
44b8cb0b   曾柯   考评
239
240
241
                      }
                    >
                      {({ getFieldValue }) => {
7722662b   曾柯   考评1524
242
                        const extraTargetValue = getFieldValue("extraTargetValue");
44b8cb0b   曾柯   考评
243
244
245
                        return (
                          <>
                            <Form.Item
7722662b   曾柯   考评1524
246
                              label="阶段目标考核值"
44b8cb0b   曾柯   考评
247
248
                              name="targetValue"
                              rules={[
7722662b   曾柯   考评1524
249
                                { required: !extraTargetValue, message: "请输入阶段目标考核值" },
44b8cb0b   曾柯   考评
250
251
252
253
254
255
256
257
258
259
                                {
                                  pattern: targetType === TargetTypeEnum["百分比"] ? percent : Momney,
                                  message:
                                    targetType === TargetTypeEnum["百分比"]
                                      ? "请输入大于0小于等于100的数(保留两位小数)"
                                      : "请输入大于0的数(保留两位小数)",
                                },
                              ]}
                            >
                              <InputNumber
7722662b   曾柯   考评1524
260
                                placeholder="请输入阶段目标考核值"
44b8cb0b   曾柯   考评
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
                                style={{ width: "100%" }}
                                addonAfter={
                                  targetType === TargetTypeEnum["百分比"]
                                    ? "%"
                                    : targetType === TargetTypeEnum["金额"]
                                    ? "元"
                                    : "台"
                                }
                              />
                            </Form.Item>
                          </>
                        );
                      }}
                    </Form.Item>
                    <Form.Item
                      noStyle
7722662b   曾柯   考评1524
277
                      shouldUpdate={(prevValues, currentValues) => prevValues.targetValue !== currentValues.targetValue}
44b8cb0b   曾柯   考评
278
279
                    >
                      {({ getFieldValue }) => {
7722662b   曾柯   考评1524
280
                        const targetValue = getFieldValue("targetValue");
44b8cb0b   曾柯   考评
281
282
283
                        return (
                          <>
                            <Form.Item
7722662b   曾柯   考评1524
284
                              label="时间进度目标值"
44b8cb0b   曾柯   考评
285
286
                              name="extraTargetValue"
                              rules={[
7722662b   曾柯   考评1524
287
                                { required: !targetValue, message: "请输入时间进度目标值" },
44b8cb0b   曾柯   考评
288
289
290
291
292
293
294
295
296
297
                                {
                                  pattern: targetType === TargetTypeEnum["百分比"] ? percent : Momney,
                                  message:
                                    targetType === TargetTypeEnum["百分比"]
                                      ? "请输入大于0小于等于100的数(保留两位小数)"
                                      : "请输入大于0的数(保留两位小数)",
                                },
                              ]}
                            >
                              <InputNumber
7722662b   曾柯   考评1524
298
                                placeholder="请输入时间进度目标值"
44b8cb0b   曾柯   考评
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
                                style={{ width: "100%" }}
                                addonAfter={
                                  targetType === TargetTypeEnum["百分比"]
                                    ? "%"
                                    : targetType === TargetTypeEnum["金额"]
                                    ? "元"
                                    : "台"
                                }
                              />
                            </Form.Item>
                          </>
                        );
                      }}
                    </Form.Item>
                  </>
3b951d34   曾柯   时间校验
314
                ) : (
44b8cb0b   曾柯   考评
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
                  <>
                    <Form.Item
                      label="考核目标计算类型"
                      name="targetCalcType"
                      rules={[{ required: true, message: "请选择考核目标计算类型" }]}
                    >
                      <Radio.Group>
                        <Radio value={1}>考核目标值计算 </Radio>
                        <Radio value={2}>最低要求计算</Radio>
                      </Radio.Group>
                    </Form.Item>
                    <Form.Item
                      label="考核目标值"
                      name="targetValue"
                      rules={[
                        { required: true, message: "请输入考核目标值" },
                        {
                          pattern: targetType === TargetTypeEnum["百分比"] ? percent : Momney,
                          message:
                            targetType === TargetTypeEnum["百分比"]
                              ? "请输入大于0小于等于100的数(保留两位小数)"
                              : "请输入大于0的数(保留两位小数)",
                        },
                      ]}
                    >
                      <InputNumber
                        placeholder="请输入考核目标值"
                        style={{ width: "100%" }}
                        addonAfter={
                          targetType === TargetTypeEnum["百分比"]
                            ? "%"
                            : targetType === TargetTypeEnum["金额"]
                            ? "元"
                            : "台"
                        }
                      />
                    </Form.Item>
                  </>
3b951d34   曾柯   时间校验
353
                )}
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
354
355
356
357
358
359
360
              </>
            )}
          </Form>
        </Spin>
      </Modal>
    );
  }