Blame view

src/pages/approval/FLowSetting/components/Modal.tsx 21.6 KB
c73b19bb   赵凤   审批=》回显bugfix
1
  import React, { useEffect, useState, useRef } from "react";
60c0e139   赵凤   审批
2
  import PostSelect from "@/components/PostSelect";
bbf93a83   赵凤   条件审批回显
3
4
5
6
7
8
9
10
11
12
  import {
    Modal,
    Select,
    InputNumber,
    Spin,
    message,
    Form,
    Input,
    FormInstance,
  } from "antd";
60c0e139   赵凤   审批
13
  import { TriggerType, TriggerAll } from "../entity";
e36d7a99   赵凤   bugfix
14
  import _ from "lodash";
168e9eb2   赵凤   按业态查询门店
15
16
  // ShopSelect;
  import ShopSelect from "@/components/ShopSelect";
e36d7a99   赵凤   bugfix
17
  
87e1b4f2   赵凤   审批角色添加顺序
18
  interface PostItem {
9320084a   赵凤   条件审批add资金账户、配件区域库
19
20
    type: number; //岗位大类编码
    typeName: string; //岗位大类名称
60c0e139   赵凤   审批
21
  }
9f41d7fd   赵凤   条件审批-》配置流程
22
23
24
25
26
27
28
29
30
31
32
33
  const { Option } = Select;
  const FormItem = Form.Item;
  interface Interval {
    min?: number;
    max?: number;
  }
  
  interface Props {
    loading: boolean;
    onOk: (data: any, cb: () => any) => any;
    onCancel: () => any;
    show: boolean;
9f41d7fd   赵凤   条件审批-》配置流程
34
35
    data: any[];
    allShopList: any[];
60c0e139   赵凤   审批
36
37
    allPost: CommonApi.RoleCodeVO[]; //角色列表
    postTypeList: PostItem[]; //岗位大类
9f41d7fd   赵凤   条件审批-》配置流程
38
39
40
41
42
    postList: any[];
    storageList: any[];
    form: FormInstance;
    eidt?: boolean;
    readOnly?: boolean;
e36d7a99   赵凤   bugfix
43
    // preConditonList: any[];
724d1102   赵凤   add能力提升业务类型
44
    abilityList: PartStorageSpace.AbilityPageVO[]; // 能力提升列表;
ae0a4b0e   赵凤   add款项
45
    foundList: PartStorageSpace.FoundPageVO[]; //款项列表
bbf93a83   赵凤   条件审批回显
46
    preCondition: any[];
9320084a   赵凤   条件审批add资金账户、配件区域库
47
48
    fittingsList: PartStorageSpace.PageVO[];
    accountList: SpecialAccount.AccountInfo[];
9f41d7fd   赵凤   条件审批-》配置流程
49
50
51
52
53
54
55
56
57
  }
  
  export default function setModal(props: Props) {
    const {
      loading,
      onCancel,
      onOk,
      show,
      allShopList,
60c0e139   赵凤   审批
58
      postTypeList,
9f41d7fd   赵凤   条件审批-》配置流程
59
60
61
62
63
64
65
      data,
      allPost,
      postList,
      storageList,
      form,
      eidt,
      readOnly,
bbf93a83   赵凤   条件审批回显
66
      preCondition,
9320084a   赵凤   条件审批add资金账户、配件区域库
67
68
      accountList,
      fittingsList,
724d1102   赵凤   add能力提升业务类型
69
      abilityList,
ae0a4b0e   赵凤   add款项
70
      foundList,
9f41d7fd   赵凤   条件审批-》配置流程
71
72
73
74
75
    } = props;
    const [newData, setNewData] = useState<ApprovalProcess.InstanceInfo[]>([]);
    const [deepData, setDeepData] = useState<ApprovalProcess.InstanceInfo[]>([]);
    /** 选择条件配置 */
    const [selectData, setSelectData] = useState<
c73b19bb   赵凤   审批=》回显bugfix
76
      { label: string; value: number }[]
9f41d7fd   赵凤   条件审批-》配置流程
77
    >([]);
9f41d7fd   赵凤   条件审批-》配置流程
78
  
9f41d7fd   赵凤   条件审批-》配置流程
79
80
    useEffect(() => {
      if (show) {
9f41d7fd   赵凤   条件审批-》配置流程
81
        if (eidt) {
c73b19bb   赵凤   审批=》回显bugfix
82
83
          /** 编辑回显已经填写条件值 */
          setDeepData([...data]);
bbf93a83   赵凤   条件审批回显
84
85
86
87
          if (preCondition && preCondition.length) {
            const _selectList = preCondition.map((item) => ({
              label: item.flowTriggerDto.name,
              value: item.triggerId,
bbf93a83   赵凤   条件审批回显
88
89
90
            }));
            setSelectData(_selectList);
          }
c73b19bb   赵凤   审批=》回显bugfix
91
92
93
94
95
          const conditionList = data.map((item) => item.triggerId);
          form.setFieldsValue({
            ...data[0],
            confList: conditionList,
          });
9f41d7fd   赵凤   条件审批-》配置流程
96
        } else {
bbf93a83   赵凤   条件审批回显
97
          // 新增
bbf93a83   赵凤   条件审批回显
98
          setNewData(data);
bbf93a83   赵凤   条件审批回显
99
100
101
102
103
104
          const tmpSelectList = data.map((item) => ({
            label: item.flowTriggerDto.name,
            value: item.triggerId,
            extral: item,
          }));
          setSelectData(tmpSelectList);
9f41d7fd   赵凤   条件审批-》配置流程
105
        }
9f41d7fd   赵凤   条件审批-》配置流程
106
      }
9f41d7fd   赵凤   条件审批-》配置流程
107
108
109
110
111
112
113
    }, [data]);
  
    /** 保存 */
    function save() {
      if (loading) {
        return;
      }
9f41d7fd   赵凤   条件审批-》配置流程
114
115
      if (
        deepData.filter(
60c0e139   赵凤   审批
116
117
          (item) =>
            !item.value ||
9f41d7fd   赵凤   条件审批-》配置流程
118
119
120
121
122
123
124
            JSON.parse(item.value) == null ||
            JSON.parse(item.value).length == 0
        ).length
      ) {
        message.error("请填写全部条件");
        return;
      }
89589be0   赵凤   条件审批查看配置流程
125
  
9f41d7fd   赵凤   条件审批-》配置流程
126
      const _data = deepData.length > 0 ? deepData : data;
9f41d7fd   赵凤   条件审批-》配置流程
127
128
129
130
131
132
133
134
135
136
137
  
      const params = _data.map((item: ApprovalProcess.InstanceInfo) => ({
        approvalConditionId: item.triggerId,
        value: item.value,
      }));
      onOk && onOk(params, hide);
      // setDeepData([]);
    }
  
    function hide() {
      onCancel && onCancel();
60c0e139   赵凤   审批
138
      form.resetFields();
9f41d7fd   赵凤   条件审批-》配置流程
139
      setDeepData([]);
bbf93a83   赵凤   条件审批回显
140
      setNewData([]);
9f41d7fd   赵凤   条件审批-》配置流程
141
142
143
144
145
146
147
148
    }
  
    function onChange(
      item: ApprovalProcess.InstanceInfo,
      // value: any,
      Values: any,
      index: number
    ) {
60c0e139   赵凤   审批
149
      // idOrCode;
9f41d7fd   赵凤   条件审批-》配置流程
150
      const newValue = Array.isArray(Values)
60c0e139   赵凤   审批
151
        ? Values.map((i) => ({ idOrCode: i.value, name: i.label }))
9f41d7fd   赵凤   条件审批-》配置流程
152
        : Values;
87e1b4f2   赵凤   审批角色添加顺序
153
  
9f41d7fd   赵凤   条件审批-》配置流程
154
      const { value, flowTriggerDto } = item;
9f41d7fd   赵凤   条件审批-》配置流程
155
156
157
  
      if ([2, 3, 4, 5, 6, 7, 8].includes(flowTriggerDto.judgeRule)) {
        const _item = { ...item, value: JSON.stringify(newValue) };
9f41d7fd   赵凤   条件审批-》配置流程
158
        deepData[index] = _item;
9f41d7fd   赵凤   条件审批-》配置流程
159
160
161
162
163
164
165
166
167
168
  
        setDeepData([...deepData]);
      } else {
        const _item = {
          ...item,
          value: JSON.stringify({
            ...JSON.parse(value || "{}"),
            ...newValue,
          }),
        };
c73b19bb   赵凤   审批=》回显bugfix
169
  
9f41d7fd   赵凤   条件审批-》配置流程
170
171
        deepData[index] = _item;
        setDeepData([...deepData]);
9f41d7fd   赵凤   条件审批-》配置流程
172
173
174
175
      }
    }
  
    /** 选择需要配置的预设条件 */
c73b19bb   赵凤   审批=》回显bugfix
176
177
178
179
    const _onChange = (value: any[], option) => {
      if (eidt) {
        let res1 = data.filter((item) => value.find((y) => y === item.triggerId)); //交集
        let res2 = value.filter((x) => !data.find((y) => y.triggerId === x)); //差集
e36d7a99   赵凤   bugfix
180
181
182
        let res3 = preCondition.filter((x) => {
          return res2.find((y) => y === x.triggerId);
        });
c73b19bb   赵凤   审批=》回显bugfix
183
184
185
186
187
  
        let res = res1.concat(res3);
        setDeepData([...res]);
      } else {
        const tempId = option.map((item) => item.extral.triggerId);
89589be0   赵凤   条件审批查看配置流程
188
  
60c0e139   赵凤   审批
189
190
        const tempList = newData.filter((item) =>
          tempId.includes(item.triggerId)
c73b19bb   赵凤   审批=》回显bugfix
191
192
193
194
        );
  
        setDeepData([...tempList]);
      }
9f41d7fd   赵凤   条件审批-》配置流程
195
    };
c73b19bb   赵凤   审批=》回显bugfix
196
  
9f41d7fd   赵凤   条件审批-》配置流程
197
198
199
200
201
    return (
      <Modal
        visible={show}
        onCancel={hide}
        onOk={save}
87e1b4f2   赵凤   审批角色添加顺序
202
        title={`${eidt ? "编辑" : "添加"}流程`}
9f41d7fd   赵凤   条件审批-》配置流程
203
        width={500}
9f41d7fd   赵凤   条件审批-》配置流程
204
205
        maskClosable={false}
        closable={readOnly}
9f41d7fd   赵凤   条件审批-》配置流程
206
207
208
        okButtonProps={{ disabled: readOnly }}
        cancelButtonProps={{ disabled: readOnly }}
      >
9f41d7fd   赵凤   条件审批-》配置流程
209
210
211
212
213
214
215
216
217
218
219
        <Spin tip="保存中" spinning={loading}>
          <Form layout="vertical" form={form} onFinish={save}>
            <Form.Item
              name="name"
              label="流程名称"
              rules={[{ required: true, message: "请输入流程名称" }]}
            >
              <Input placeholder="请输入" maxLength={64} disabled={readOnly} />
            </Form.Item>
            {/* 多选=》选择要配置的预设条件 */}
            <Form.Item
e2c1272a   赵凤   审批角色筛选
220
              label="触发条件"
9f41d7fd   赵凤   条件审批-》配置流程
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
              name="confList"
              rules={[{ required: true, message: "请选择需要配置的条件" }]}
            >
              <Select
                mode="multiple"
                allowClear
                style={{ width: "100%" }}
                placeholder="请选择"
                onChange={_onChange}
                disabled={readOnly}
              >
                {selectData.map((item, index) => (
                  <Option
                    value={item.value}
                    key={item.value}
9f41d7fd   赵凤   条件审批-》配置流程
236
237
238
239
240
241
242
243
244
245
                    extral={item.extral}
                  >
                    {item.label}
                  </Option>
                ))}
              </Select>
            </Form.Item>
  
            {deepData.map((item: ApprovalProcess.InstanceInfo, index: number) => {
              const data = item;
9f41d7fd   赵凤   条件审批-》配置流程
246
247
              const { flowTriggerDto, value } = data;
              const originalData = JSON.parse(value || "{}");
89589be0   赵凤   条件审批查看配置流程
248
  
9f41d7fd   赵凤   条件审批-》配置流程
249
              const {
9f41d7fd   赵凤   条件审批-》配置流程
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
                name,
                unit,
                judgeRule,
                type,
                // options,
              } = flowTriggerDto;
  
              const _maxRule =
                originalData && typeof originalData.max === "number"
                  ? originalData.max
                  : Infinity;
              const _minRule =
                originalData && typeof originalData.min === "number"
                  ? originalData.min
                  : -Infinity;
  
9f41d7fd   赵凤   条件审批-》配置流程
266
              return (
ae0a4b0e   赵凤   add款项
267
268
269
270
                <div
                  style={{ marginBottom: judgeRule === 1 ? 75 : 20 }}
                  key={`id_${index}`}
                >
81560396   赵凤   审批add能力提升
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
                  <React.Fragment key={`id_${index}`}>
                    <FormItem
                      label={`${index + 1}、${name || ""}(${
                        TriggerAll[judgeRule]
                      })`}
                      style={{ marginBottom: 20 }}
                    >
                      {judgeRule === 1 ? (
                        <div
                          style={{
                            height: 70,
                            width: "100%",
                          }}
                        >
                          <div>
                            <span>下限值(不包含,值为0则包含):</span>
                            <InputNumber
                              disabled={readOnly}
                              style={{ width: "100%" }}
                              placeholder="请输入"
                              precision={type === TriggerType["数量"] ? 0 : 2}
                              max={_maxRule}
                              value={originalData.min}
                              onChange={(value) =>
                                onChange(
                                  data,
                                  { min: value > _maxRule ? _maxRule : value },
                                  index
                                )
                              }
                            />
                          </div>
                          <div
                            style={{
                              width: "100%",
                              marginTop: 20,
                            }}
                          >
                            <span>上限值(包含):</span>
                            <InputNumber
                              disabled={readOnly}
                              style={{ width: "100%" }}
                              placeholder="请输入"
                              precision={type === TriggerType["数量"] ? 0 : 2}
                              min={_minRule}
                              value={originalData.max}
                              onChange={(value) =>
                                onChange(
                                  data,
                                  { max: value < _minRule ? _maxRule : value },
                                  index
                                )
                              }
                            />
                          </div>
                        </div>
                      ) : null}
                      {[2, 3, 4, 5, 6].includes(judgeRule) ? (
9f41d7fd   赵凤   条件审批-》配置流程
329
                        <div>
9f41d7fd   赵凤   条件审批-》配置流程
330
331
                          <InputNumber
                            disabled={readOnly}
87e1b4f2   赵凤   审批角色添加顺序
332
                            style={{ width: "100%" }}
9f41d7fd   赵凤   条件审批-》配置流程
333
334
                            placeholder="请输入"
                            precision={type === TriggerType["数量"] ? 0 : 2}
81560396   赵凤   审批add能力提升
335
336
337
338
339
                            min={_minRule}
                            value={
                              typeof originalData === "number"
                                ? originalData
                                : undefined
60c0e139   赵凤   审批
340
                            }
81560396   赵凤   审批add能力提升
341
                            onChange={(value) => onChange(data, value, index)}
9f41d7fd   赵凤   条件审批-》配置流程
342
343
                          />
                        </div>
81560396   赵凤   审批add能力提升
344
345
346
347
348
349
350
                      ) : null}
                      {type === TriggerType["门店"] && (
                        <div>
                          <ShopSelect
                            labelInValue
                            multiple
                            initType={1}
81560396   赵凤   审批add能力提升
351
352
353
354
355
356
357
                            value={
                              originalData.length > 0
                                ? originalData.map((i: any) => ({
                                    value: i.idOrCode,
                                    label: i.name,
                                  }))
                                : []
60c0e139   赵凤   审批
358
                            }
81560396   赵凤   审批add能力提升
359
360
361
362
                            onChange={(value) => {
                              console.log("value:", value);
                              onChange(data, value, index);
                            }}
9f41d7fd   赵凤   条件审批-》配置流程
363
                          />
81560396   赵凤   审批add能力提升
364
                          {/* <Select
9f41d7fd   赵凤   条件审批-》配置流程
365
366
367
368
369
370
                          disabled={readOnly}
                          optionFilterProp="children"
                          labelInValue
                          value={
                            originalData.length > 0
                              ? originalData.map((i: any) => ({
60c0e139   赵凤   审批
371
                                  value: i.idOrCode,
9f41d7fd   赵凤   条件审批-》配置流程
372
373
374
375
376
377
378
379
380
381
382
383
384
                                  label: i.name,
                                }))
                              : []
                          }
                          mode="multiple"
                          placeholder="请选择门店"
                          onChange={(value) => onChange(data, value, index)}
                        >
                          {allShopList.map((item) => (
                            <Option value={item.id} key={item.id}>
                              {item.name}
                            </Option>
                          ))}
168e9eb2   赵凤   按业态查询门店
385
                        </Select> */}
81560396   赵凤   审批add能力提升
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
                        </div>
                      )}
                      {type === TriggerType["角色"] && (
                        <div>
                          <Select
                            disabled={readOnly}
                            optionFilterProp="children"
                            labelInValue
                            value={
                              originalData.length > 0
                                ? originalData.map((i: any) => ({
                                    // idOrCode
                                    value: i.idOrCode,
                                    label: i.name,
                                  }))
                                : []
                            }
                            mode="multiple"
                            // style={{ width: '80%', marginTop: 10 }}
                            placeholder="请选择角色"
                            onChange={(value) => onChange(data, value, index)}
                            showSearch
                          >
                            {allPost.length &&
                              allPost.map((item) => (
                                <Option value={item.roleCode} key={item.roleCode}>
                                  {item.roleName}
                                </Option>
                              ))}
                          </Select>
                        </div>
                      )}
                      {type === TriggerType["岗位"] && (
                        <div>
                          <Select
                            disabled={readOnly}
                            optionFilterProp="children"
                            value={
                              originalData.length > 0
                                ? originalData.map((i: any) => ({
                                    value: i.idOrCode,
                                    label: i.name,
                                  }))
                                : []
                            }
                            labelInValue
                            mode="multiple"
                            placeholder="请选择岗位"
                            onChange={(value) => {
                              onChange(data, value, index);
                            }}
                          >
                            {postList.map((item) => (
                              <Option value={item.id} key={item.id}>
                                {item.postName}
60c0e139   赵凤   审批
441
442
                              </Option>
                            ))}
81560396   赵凤   审批add能力提升
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
                          </Select>
                        </div>
                      )}
                      {/* 岗位大类 */}
                      {type === TriggerType["岗位大类"] && (
                        <div>
                          <Select
                            disabled={readOnly}
                            optionFilterProp="children"
                            value={
                              originalData.length > 0
                                ? originalData.map((i: any) => ({
                                    value: i.idOrCode,
                                    label: i.name,
                                  }))
                                : []
                            }
                            labelInValue
                            mode="multiple"
                            placeholder="请选择岗位大类"
                            onChange={(value) => onChange(data, value, index)}
                          >
                            {postTypeList.map((item) => (
                              <Option value={item.type} key={item.type}>
                                {item.typeName}
                              </Option>
                            ))}
                          </Select>
                        </div>
                      )}
                      {type === TriggerType["车辆区域库"] && (
                        <div>
                          <Select
                            optionFilterProp="children"
                            disabled={readOnly}
                            labelInValue
                            value={
                              originalData.length > 0
                                ? originalData.map((i: any) => ({
                                    value: i.idOrCode,
                                    label: i.name,
                                  }))
                                : []
                            }
                            mode="multiple"
                            placeholder="请选择车辆区域库"
                            onChange={(value) => onChange(data, value, index)}
                          >
                            {storageList.map((item) => (
                              <Option value={item.id} key={item.id}>
                                {item.name}
                              </Option>
                            ))}
                          </Select>
                        </div>
                      )}
                      {/* 配件库房 */}
                      {type === TriggerType["配件库房"] && (
                        <div>
                          <Select
                            optionFilterProp="children"
                            disabled={readOnly}
                            labelInValue
                            value={
                              originalData.length > 0
                                ? originalData.map((i: any) => ({
                                    value: i.idOrCode,
                                    label: i.name,
                                  }))
                                : []
                            }
                            mode="multiple"
                            placeholder="请选择配件库房"
                            onChange={(value) => onChange(data, value, index)}
                          >
                            {fittingsList.map((item) => (
                              <Option
                                value={item.storageCode}
                                key={item.storageCode}
                              >
                                {item.storageName}
                              </Option>
                            ))}
                          </Select>
                        </div>
                      )}
                      {/* 资金账户 */}
                      {type === TriggerType["资金账户"] && (
                        <div>
                          <Select
                            optionFilterProp="children"
                            disabled={readOnly}
                            labelInValue
                            value={
                              originalData.length > 0
                                ? originalData.map((i: any) => ({
                                    value: i.idOrCode,
                                    label: i.name,
                                  }))
                                : []
                            }
                            mode="multiple"
                            placeholder="请选择资金账户"
                            onChange={(value) => onChange(data, value, index)}
                          >
                            {accountList.map((item) => (
                              <Option value={item.id} key={item.id}>
                                {item.name}
                              </Option>
                            ))}
                          </Select>
                        </div>
                      )}
81560396   赵凤   审批add能力提升
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
                      {/* 能力提升 */}
                      {type === TriggerType["能力提升业务类型"] && (
                        <div>
                          <Select
                            disabled={readOnly}
                            optionFilterProp="children"
                            value={
                              originalData.length > 0
                                ? originalData.map((i: any) => ({
                                    value: i.idOrCode,
                                    label: i.name,
                                  }))
                                : []
                            }
                            labelInValue
                            mode="multiple"
                            placeholder="请选择能力提升业务类型"
                            onChange={(value) => {
                              onChange(data, value, index);
                            }}
                          >
                            {abilityList.map((item) => (
                              <Option value={item.id} key={item.id}>
                                {item.name}
                              </Option>
                            ))}
                          </Select>
                        </div>
                      )}
ae0a4b0e   赵凤   add款项
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
                      {/* 款项 */}
  
                      {type === TriggerType["款项"] && (
                        <div>
                          <Select
                            disabled={readOnly}
                            optionFilterProp="children"
                            value={
                              originalData.length > 0
                                ? originalData.map((i: any) => ({
                                    value: i.idOrCode,
                                    label: i.name,
                                  }))
                                : []
                            }
                            labelInValue
                            mode="multiple"
                            placeholder="请选择款项类型"
                            onChange={(value) => {
                              onChange(data, value, index);
                            }}
                          >
                            {foundList.map((item) => (
                              <Option value={item.value} key={item.value}>
                                {item.name}
                              </Option>
                            ))}
                          </Select>
                        </div>
                      )}
81560396   赵凤   审批add能力提升
615
                    </FormItem>
81560396   赵凤   审批add能力提升
616
617
                  </React.Fragment>
                </div>
9f41d7fd   赵凤   条件审批-》配置流程
618
619
620
621
622
623
624
              );
            })}
          </Form>
        </Spin>
      </Modal>
    );
  }