Blame view

src/pages/performance/EvaGroupSetting/EditComfirm/components/AddLadderParamsModalSal.tsx 9.11 KB
5ac136b7   曾柯   考评组设置1620
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  /* 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 } from "antd";
  import { useStore } from "../index";
  import { queryPostIndicatorApi, queryShopIndicatorApi } from "../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 {
    addComVisible: boolean;
    onCancel: Function;
    postId?: number;
    shopIds?: string;
    onOk: (vales: any) => void;
    comItem: Commission;
    setItemId: Function;
    scopeType: number;
d82a09c8   曾柯   考评预览报表及bugfix
22
    isOne: number;
5ac136b7   曾柯   考评组设置1620
23
24
25
  }
  type Commission = EvaGroupSetteing.CommissionParams;
  export default function AddLadderParamsModal(props: Props) {
7722662b   曾柯   考评1524
26
    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}$/;
5ac136b7   曾柯   考评组设置1620
27
28
    const Momney = /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/;
    const [form] = Form.useForm();
3b951d34   曾柯   时间校验
29
    const { selectedIndicatorsLadderSal, setSelectedIndicatorsLadderSal, setLadderParamAlias, multiStage } = useStore();
5ac136b7   曾柯   考评组设置1620
30
31
32
33
  
    const [isTarget, setIsTarget] = useState(false);
    const [dataType, setDataType] = useState<number>(2);
    // console.log(form);
d82a09c8   曾柯   考评预览报表及bugfix
34
    const { addComVisible, onCancel, postId, shopIds, onOk, comItem, setItemId, scopeType, isOne } = props;
5ac136b7   曾柯   考评组设置1620
35
36
37
38
39
40
41
42
43
    const [delay, setDelay] = useState(true);
    // 保存选中绩效指标需要配置的绩效考核目标值类型
    const [targetType, setTargetType] = useState<number>();
    // 保存选中指标是否考评类型
    const [codeType, setCodeType] = useState<number>();
    // 保存过滤后指标列表
    const [newIndicators, setNewIndicators] = useState<EvaGroupSetteing.IndicatorByPost[]>([]);
    const [name, setIndicatorName] = useState("");
    const [id, setId] = useState(0);
c307b0cc   曾柯   考评组配置
44
    const { data: indicatorsList, setParams, loading } = useInitail(queryPostIndicatorApi, [], {}, delay);
5ac136b7   曾柯   考评组设置1620
45
    useEffect(() => {
c307b0cc   曾柯   考评组配置
46
      setParams({ reward: true, withCombination: true }, true);
5ac136b7   曾柯   考评组设置1620
47
48
49
50
51
52
53
54
55
56
57
      setDelay(false);
      setTargetType(1);
    }, [addComVisible]);
    // 修改
  
    useEffect(() => {
      if (indicatorsList && indicatorsList.length > 0 && !comItem.code) {
        const res = indicatorsList.filter((item) => !selectedIndicatorsLadderSal.find((y) => y === item.code));
        setNewIndicators([...res]);
      }
      if (addComVisible && comItem.code) {
c5c0ea29   曾柯   考评2002
58
        const indTar = indicatorsList.find((item: any) => item.code == comItem.code)?.targetType;
5ac136b7   曾柯   考评组设置1620
59
60
        setTargetType(indTar);
        setIndicatorName(comItem.name);
27123514   曾柯   考评组排名倒数
61
        setCodeType(comItem.codeType);
5ac136b7   曾柯   考评组设置1620
62
63
64
65
66
67
68
        form.setFieldsValue({
          ...comItem,
          ladderParams: {
            value: comItem.code,
            label: comItem.name,
            dataType: comItem.dataType,
          },
d82a09c8   曾柯   考评预览报表及bugfix
69
          proportion: comItem.proportion !== undefined ? comItem.proportion : isOne == 1 ? 100 : null,
5ac136b7   曾柯   考评组设置1620
70
71
72
73
74
        });
      }
      if (comItem.targetValue && comItem.targetCalcType) {
        setIsTarget(true);
      }
7722662b   曾柯   考评1524
75
76
77
      if (comItem.extraTargetValue && comItem.extraTargetCalcType) {
        setIsTarget(true);
      }
5ac136b7   曾柯   考评组设置1620
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    }, [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 "ladderParams":
            const _options = value || {};
ccdb0384   曾柯   考评组配置及数据导入
94
            detail.name = _options.label[0];
5ac136b7   曾柯   考评组设置1620
95
96
97
98
99
100
101
102
103
104
105
            detail.code = _options.value;
            break;
          default:
            detail[key] = value;
            break;
        }
      });
      return detail;
    }
    function handSubmit(fieldsValue: any) {
      const pa: any = transformDTO(fieldsValue);
72f930c4   曾柯   考评bugfix
106
107
108
109
110
      if (pa.targetValue !== undefined) {
        pa.targetType = targetType;
      } else {
        pa.targetType = 1;
      }
5ac136b7   曾柯   考评组设置1620
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
      pa.codeType = codeType;
      if (comItem.dataType) {
        pa.dataType = comItem.dataType;
      }
      if (!comItem.dataType) {
        pa.dataType = dataType;
      }
      console.log("100pa", pa);
      const newItemId = pa.code;
      // 编辑时,不需要push id
      if (!comItem.code) {
        const tmpIds = [...selectedIndicatorsLadderSal];
        tmpIds.push(newItemId);
        setSelectedIndicatorsLadderSal([...tmpIds]);
      } else {
        pa.code = comItem.code;
        pa.name = comItem.name;
      }
7722662b   曾柯   考评1524
129
130
      onOk(pa);
      onCancel && onCancel();
5ac136b7   曾柯   考评组设置1620
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
    }
    return (
      <Modal
        visible={addComVisible}
        title={`${comItem.code ? "编辑" : "新增"}台阶得分指标`}
        maskClosable={false}
        afterClose={() => {
          form.resetFields();
          onCancel();
        }}
        onCancel={() => onCancel()}
        onOk={form.submit}
        width={1000}
      >
        <Spin spinning={loading}>
72f930c4   曾柯   考评bugfix
146
          <Form form={form} onFinish={handSubmit} style={{ width: "70%", marginLeft: 150 }}>
5ac136b7   曾柯   考评组设置1620
147
148
            <Form.Item name="ladderParams" label="计分指标" rules={[{ required: true, message: "计分指标" }]}>
              <Select
ccdb0384   曾柯   考评组配置及数据导入
149
                placeholder="选择指标(*为考评指标,无*为绩效指标)"
5ac136b7   曾柯   考评组设置1620
150
151
152
153
154
155
156
                labelInValue
                disabled={!!comItem.code}
                onChange={(value, Option: any) => {
                  setTargetType(Option.targetType);
                  setItemId(Option.key);
                  setId(Option.key);
                  setIndicatorName(Option.children);
ccdb0384   曾柯   考评组配置及数据导入
157
                  setLadderParamAlias(Option.name);
5ac136b7   曾柯   考评组设置1620
158
159
160
161
162
163
164
165
166
167
168
169
170
                  setDataType(Option.dataType);
                  setCodeType(Option.codeType);
                }}
                showSearch
                optionFilterProp="children"
              >
                {newIndicators.map((item) => (
                  <Option
                    value={item.code}
                    key={item.code}
                    targetType={item.targetType}
                    dataType={item.dataType}
                    codeType={item.codeType}
ccdb0384   曾柯   考评组配置及数据导入
171
                    name={item.name}
5ac136b7   曾柯   考评组设置1620
172
173
                  >
                    {item.name}
ccdb0384   曾柯   考评组配置及数据导入
174
                    {item.codeType == 2 ? "*" : ""}
5ac136b7   曾柯   考评组设置1620
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
                  </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   曾柯   表单样式调整
201
              <div>
5ac136b7   曾柯   考评组设置1620
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
                <Button type="link" onClick={() => setIsTarget(true)}>
                  考核目标值设置(可选项)
                </Button>
                {isTarget && (
                  <Button type="link" onClick={() => setIsTarget(false)}>
                    删除该项考核目标设置
                  </Button>
                )}
              </div>
            )}
            {isTarget && (
              <>
                <Form.Item label="考核目标名称" name="targetName">
                  <Select disabled defaultValue={name} />
                </Form.Item>
72f930c4   曾柯   考评bugfix
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
                <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>
5ac136b7   曾柯   考评组设置1620
249
250
251
252
253
254
255
              </>
            )}
          </Form>
        </Spin>
      </Modal>
    );
  }