Blame view

src/pages/performance/EvaGroupSetting/EditComfirm/components/AddCondModal.tsx 8.88 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
28
29
30
31
32
33
34
35
36
  /* 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 { saveRewardsListApi } from "../RewardsList/api";
  import { useStore } from "../index";
  import { queryPostIndicatorApi, queryShopIndicatorApi } from "../api";
  import _ from "lodash";
  import useInitail from "@/hooks/useInitail";
  import CondLaddersTable from "./CondLaddersTable";
  import CommissionParams from "@/pages/performance/KpiGroupSetting/EditComfirm/components/CommissionParams";
  import { EvaGroupSetteing } from "@/pages/performance/EvaGroupSetting/interface";
  import { TargetType, TargetTypeEnum } from "@/pages/performance/entity";
  // import { transformDTOCond } from "../../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;
  }
  type Commission = EvaGroupSetteing.CommissionParams;
  export default function AddCondModal(props: Props) {
    const { selectedIndicatorsConds, setSelectedIndicatorsConds, setPreconditionAlias } = useStore();
    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}$/;
    const Momney = /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/;
    const [form] = Form.useForm();
    const [isTarget, setIsTarget] = useState(false);
    // console.log(form);
    const { addComVisible, onCancel, postId, shopIds, onOk, comItem, setItemId, scopeType } = props;
    const [delay, setDelay] = useState(true);
35f42afa   曾柯   考评设置
37
    // 保存选中绩效指标需要配置的绩效考核目标值类型
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
38
39
40
41
42
43
44
45
46
47
48
49
50
    const [targetType, setTargetType] = useState<number>();
    // 保存选中指标是否考评类型
    const [codeType, setCodeType] = useState<number>();
    const [dataType, setDataType] = useState<number>();
    // 保存过滤后指标列表
    const [newIndicators, setNewIndicators] = useState<EvaGroupSetteing.IndicatorByPost[]>([]);
    const [name, setIndicatorName] = useState("");
    const [id, setId] = useState(0);
    const {
      data: indicatorsList,
      setParams,
      loading,
    } = useInitail(
f3e17a99   曾柯   考评0221
51
      scopeType == 1 ? queryPostIndicatorApi : queryShopIndicatorApi,
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
52
      [],
f3e17a99   曾柯   考评0221
53
      scopeType == 1 ? { postId } : {},
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
54
55
56
      delay
    );
    useEffect(() => {
f3e17a99   曾柯   考评0221
57
      setParams(scopeType == 1 ? { postId } : {}, true);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
      setDelay(false);
      setTargetType(1);
    }, [addComVisible]);
    // 修改
  
    useEffect(() => {
      if (indicatorsList && indicatorsList.length > 0 && !comItem.code) {
        const res = indicatorsList.filter((item) => !selectedIndicatorsConds.find((y) => y === item.code));
        setNewIndicators([...res]);
      }
      if (addComVisible && comItem.code) {
        const indTar = indicatorsList.find((item) => item.code == comItem.code)?.targetType;
        console.log("indTar", indTar);
        console.log("comItem.targetType", comItem.targetType);
        setTargetType(indTar);
        setIndicatorName(comItem.name);
27123514   曾柯   考评组排名倒数
74
75
        setDataType(comItem.dataType);
        setCodeType(comItem.codeType);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
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
        form.setFieldsValue({
          ...comItem,
          conds: {
            value: comItem.code,
            label: comItem.name,
          },
        });
      }
      if (comItem.targetValue && comItem.targetCalcType) {
        setIsTarget(true);
      }
    }, [indicatorsList]);
    useEffect(() => {
      if (targetType === TargetTypeEnum["无"]) {
        setIsTarget(false);
      }
    }, [targetType]);
    useEffect(() => {
      setIsTarget(false);
    }, [id]);
    // 校验表单数据
    function transformDTO(formData: any) {
      console.log("前置条件", formData);
      let detail: any = {};
      _.each(formData, (value: any, key: string) => {
        switch (key) {
          case "conds":
            const _options = value || {};
ccdb0384   曾柯   考评组配置及数据导入
104
            detail.name = _options.label[0];
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
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
            detail.code = _options.value;
            break;
          default:
            detail[key] = value;
            break;
        }
      });
      return detail;
    }
    function handSubmit(fieldsValue: any) {
      const pa: any = transformDTO(fieldsValue);
      pa.targetType = targetType;
      pa.codeType = codeType;
      pa.dataType = dataType;
      console.log("前置条件", pa);
      const newItemId = pa.code;
      // 编辑时,不需要push id
      if (!comItem.code) {
        const tmpIds = [...selectedIndicatorsConds];
        tmpIds.push(newItemId);
        setSelectedIndicatorsConds([...tmpIds]);
      } else {
        pa.code = comItem.code;
        pa.name = comItem.name;
      }
      onOk(pa);
      onCancel && onCancel();
    }
    return (
      <Modal
        visible={addComVisible}
        title={`${comItem.code ? "编辑" : "新增"}前置条件`}
        maskClosable={false}
        afterClose={() => {
          form.resetFields();
          onCancel();
        }}
        onCancel={() => onCancel()}
        onOk={form.submit}
        width={1000}
      >
        <Spin spinning={loading}>
          <Form
            form={form}
            labelCol={{ span: 6 }}
            wrapperCol={{ span: 18 }}
            onFinish={handSubmit}
            initialValues={{
              ladders: [{ lower: 0, scorePercent: 0, key: 0 }],
            }}
          >
            <Form.Item name="conds" label="前置条件配置" rules={[{ required: true, message: "前置条件配置" }]}>
              <Select
ccdb0384   曾柯   考评组配置及数据导入
158
                placeholder="选择指标(*为考评指标,无*为绩效指标)"
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
159
160
161
162
163
164
165
166
167
                labelInValue
                disabled={!!comItem.code}
                onChange={(value, Option: any) => {
                  setTargetType(Option.targetType);
                  // 最外层id
                  setItemId(Option.key);
                  // 列表id
                  setId(Option.key);
                  setIndicatorName(Option.children);
ccdb0384   曾柯   考评组配置及数据导入
168
                  setPreconditionAlias(Option.name);
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
169
170
171
172
173
174
175
                  setCodeType(Option.codeType);
                  setDataType(Option.dataType);
                }}
                showSearch
                optionFilterProp="children"
              >
                {newIndicators.map((item) => (
ccdb0384   曾柯   考评组配置及数据导入
176
177
178
179
180
181
182
183
                  <Option
                    value={item.code}
                    key={item.id}
                    targetType={item.targetType}
                    codeType={item.codeType}
                    dataType={item.dataType}
                    name={item.name}
                  >
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
184
                    {item.name}
ccdb0384   曾柯   考评组配置及数据导入
185
                    {item.codeType == 2 ? "*" : ""}
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
186
187
188
189
190
191
192
193
194
                  </Option>
                ))}
              </Select>
            </Form.Item>
            {(targetType === TargetTypeEnum["百分比"] ||
              targetType === TargetTypeEnum["金额"] ||
              targetType === TargetTypeEnum["数量"]) && (
              <div style={{ marginLeft: 65 }}>
                <Button type="link" onClick={() => setIsTarget(true)}>
35f42afa   曾柯   考评设置
195
                  考核目标值设置(可选项)
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
196
197
198
                </Button>
                {isTarget && (
                  <Button type="link" onClick={() => setIsTarget(false)}>
35f42afa   曾柯   考评设置
199
                    删除该项考核目标设置
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
200
201
202
203
204
205
                  </Button>
                )}
              </div>
            )}
            {isTarget && (
              <>
35f42afa   曾柯   考评设置
206
                <Form.Item label="考核目标名称" name="targetName">
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
207
208
209
                  <Select disabled defaultValue={name} />
                </Form.Item>
                <Form.Item
35f42afa   曾柯   考评设置
210
                  label="考核目标计算类型"
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
211
                  name="targetCalcType"
35f42afa   曾柯   考评设置
212
                  rules={[{ required: true, message: "请选择考核目标计算类型" }]}
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
213
214
                >
                  <Radio.Group>
35f42afa   曾柯   考评设置
215
                    <Radio value={1}>考核目标值计算 </Radio>
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
216
217
218
219
                    <Radio value={2}>最低要求计算</Radio>
                  </Radio.Group>
                </Form.Item>
                <Form.Item
35f42afa   曾柯   考评设置
220
                  label="考核目标值"
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
221
222
                  name="targetValue"
                  rules={[
35f42afa   曾柯   考评设置
223
                    { required: true, message: "请输入考核目标值" },
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
224
225
226
227
228
229
230
231
232
233
                    {
                      pattern: targetType === TargetTypeEnum["百分比"] ? percent : Momney,
                      message:
                        targetType === TargetTypeEnum["百分比"]
                          ? "请输入大于0小于等于100的数(保留两位小数)"
                          : "请输入大于0的数(保留两位小数)",
                    },
                  ]}
                >
                  <InputNumber
35f42afa   曾柯   考评设置
234
                    placeholder="请输入考核目标值"
4fb6f6b2   曾柯   考评组配置提成参数与前置条件
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
                    style={{ width: "100%" }}
                    addonAfter={
                      targetType === TargetTypeEnum["百分比"]
                        ? "%"
                        : targetType === TargetTypeEnum["金额"]
                        ? "元"
                        : "数量"
                    }
                  />
                </Form.Item>
              </>
            )}
            <Form.Item name="ladders" label="前置条件阶梯" rules={[{ required: true, message: "前置条件阶梯" }]}>
              <CondLaddersTable visible={addComVisible} />
            </Form.Item>
          </Form>
        </Spin>
      </Modal>
    );
  }