NodeEdit.jsx 19.9 KB
Newer Older
邓超's avatar
邓超 committed
1 2 3 4 5 6 7 8
import React, { useEffect, useState } from 'react';
import {
  getFlowNode,
  loadRollbackNodes,
  loadEventTypeTable,
  loadEventFields,
  loadFeedbackType,
  editFlowNodeExtend,
邓超's avatar
邓超 committed
9
} from '@/services/flow/flow';
邓超's avatar
邓超 committed
10 11 12 13 14 15 16 17 18

import {
  Form,
  Input,
  Radio,
  Select,
  notification,
  Checkbox,
  Button,
19
  message,
皮倩雯's avatar
皮倩雯 committed
20 21
  Drawer,
  Space,
22
  Tooltip,
23
  Switch,
邓超's avatar
邓超 committed
24
} from 'antd';
25
import { PlusOutlined, InfoCircleOutlined } from '@ant-design/icons';
邓超's avatar
邓超 committed
26 27 28 29 30 31 32 33 34 35 36 37 38
import Fieldselection from './nodeEditComponents/Fieldselection';
import styles from '../flowNode.less';
const { Option } = Select;

const NodeEdit = props => {
  const { onSubumit, handleCancel, visible, msg } = props;
  const [fieldList, setFieldList] = useState([]); // 当前选择库字段列表
  const [showField, setShowField] = useState(false); // 选择字段弹窗
  const [fieldName, setFieldName] = useState(); // 编辑的字段
  const [backNodes, setBackNodes] = useState([]); // 允许返回的节点
  const [backType, setBackType] = useState([]); // 反馈类型
  const [eventTable, setEventTable] = useState([]); // 表名
  const [isDisable, setIsDisable] = useState(); // 允许回退是否可选择
39
  const [filedData, setFiledData] = useState([]); // 已选字段列表
40
  const [filedList, setFiledList] = useState([]); // 当前选择表的所有字段
41 42
  const [visibleChecked, setVisibleChecked] = useState(false);
  const [visibleChecked1, setVisibleChecked1] = useState(false);
43
  const [visibleChecked2, setVisibleChecked2] = useState(true);
44 45
  const [visibleChecked3, setVisibleChecked3] = useState(false);
  const [autoClose, setAutoClose] = useState(false);
46
  const [transfer, setTransfer] = useState(false);
47

邓超's avatar
邓超 committed
48 49 50 51 52 53 54 55 56 57 58
  const [form] = Form.useForm();
  useEffect(() => {
    if (visible) {
      // 获取表单回显
      getFormData();
      // 获取返回步骤
      rollBackNodes();
      // 获取表名
      getTableName();
      // 获取反馈类型
      getFeedbackName();
59 60
    } else {
      form.resetFields();
61 62 63 64
      setVisibleChecked(false);
      setVisibleChecked1(false);
      setVisibleChecked2(false);
      setVisibleChecked3(false);
65
      setTransfer(false);
邓超's avatar
邓超 committed
66 67 68 69 70 71
    }
  }, [visible]);
  // 获取表单回显
  const getFormData = () => {
    getFlowNode({ flowNodeId: msg.ID }).then(res => {
      if (res.code === 0) {
72 73
        // 结束节点
        if (res.data.Type == 2) {
74
          if (res.data.Extend && res.data.Extend.AutoClose === '是') {
75 76
            res.data.Extend.AutoClose = true;
            setVisibleChecked3(true);
77
          } else if (res.data.Extend && res.data.Extend.AutoClose === '否') {
78 79 80
            res.data.Extend.AutoClose = false;
            setVisibleChecked3(false);
          }
81 82 83 84
          setAutoClose(true);
        } else {
          setAutoClose(false);
        }
85 86 87 88 89
        if (res.data.Type == 1) {
          setTransfer(true);
        } else {
          setTransfer(false);
        }
邓超's avatar
邓超 committed
90 91 92 93
        let obj = {
          ...res.data.Extend,
          FlowName: res.data.FlowName,
        };
邓超's avatar
邓超 committed
94
        if (res.data.Extend && res.data.Extend.Rollbackable) {
邓超's avatar
邓超 committed
95 96 97 98
          setIsDisable(false);
        } else {
          setIsDisable(true);
        }
99
        changTable(obj.TableName);
100 101 102 103
        if (res.data.Extend != null) {
          obj.NodeAliasName = obj.NodeAliasName || res.data.Name;
          obj.Transferable = obj.Transferable == 1;
          setVisibleChecked(obj.Transferable == 1);
104
          if (obj.EventsInformation) {
105 106 107 108 109 110 111
            if (obj.EventsInformation == 1) {
              obj.EventsInformation = true;
              setVisibleChecked1(true);
            } else {
              obj.EventsInformation = false;
              setVisibleChecked1(false);
            }
112 113 114 115
          } else {
            obj.EventsInformation = true;
            setVisibleChecked1(true);
          }
116 117 118 119 120 121 122 123
          if (obj.IsSendMessage == 0 || obj.IsSendMessage == 1) {
            if (obj.IsSendMessage == 1) {
              obj.IsSendMessage = true;
              setVisibleChecked2(true);
            } else {
              obj.IsSendMessage = false;
              setVisibleChecked2(false);
            }
124 125 126 127 128 129 130 131
          } else {
            obj.IsSendMessage = true;
            setVisibleChecked2(true);
          }

          if (!obj.Handover) {
            obj.Handover = '移交选择人';
          }
132 133 134 135 136
          form.setFieldsValue(obj);
        } else {
          setVisibleChecked(false);
          setVisibleChecked1(true);
          setVisibleChecked2(true);
137

138 139 140 141 142 143
          form.setFieldsValue({
            FlowName: res.data.FlowName,
            NodeAliasName: res.data.Name,
            Handover: '移交选择人',
          });
        }
邓超's avatar
邓超 committed
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
      }
    });
  };
  // 获取反馈类型
  const getFeedbackName = () => {
    loadFeedbackType().then(res => {
      if (res.code === 0) {
        setBackType(res.data);
      }
    });
  };
  // 获取表名
  const getTableName = () => {
    loadEventTypeTable({ flowNodeId: msg.ID }).then(res => {
      if (res.code === 0) {
        setEventTable(res.data);
      }
    });
  };
  // 加载修改流程节点配置允许退回列表
  const rollBackNodes = () => {
    loadRollbackNodes({ flowNodeId: msg.ID }).then(res => {
      if (res.code === 0) {
        setBackNodes(res.data);
      }
    });
  };
  // 字段配置
  const deployField = val => {
173 174 175 176 177
    let value = form.getFieldsValue(true);
    if (!value.TableName) {
      message.error('请先选择表');
      return;
    }
邓超's avatar
邓超 committed
178
    setFieldName(val);
179 180
    loadEventFields({ eventTableName: value.TableName }).then(res => {
      if (res.code === 0) {
181
        let defaultCheckedList = value[val] ? value[val].split(',') : [];
182 183 184

        // 保存所有的字段用于右侧显示
        setFiledData(defaultCheckedList);
185
        let allFields = []; // 所有得字段用来判断是否为外部字段
皮倩雯's avatar
皮倩雯 committed
186 187 188
        // 处理树形结构
        let checkList = res.data.map(item => {
          let plainOptions = [];
189
          // 存入没个组得字段
皮倩雯's avatar
皮倩雯 committed
190 191 192
          item.root.forEach(ele => {
            plainOptions = [...plainOptions, ele.fieldName];
          });
193 194
          // 存所有得字段
          allFields = [...allFields, ...plainOptions];
皮倩雯's avatar
皮倩雯 committed
195 196 197 198 199
          return {
            groupName: item.groupName,
            plainOptions,
            defaultCheckedList: [],
          };
200
        });
201 202 203 204 205 206 207
        let externalFields = {
          groupName: '外部字段',
          indeterminate: false,
          checkAll: true,
          plainOptions: [],
          defaultCheckedList: [],
        }; // 外部字段
208
        defaultCheckedList.forEach(item => {
209 210 211 212 213 214
          // 添加外部字段
          let isExternal = allFields.some(checkName => checkName === item);
          if (!isExternal) {
            externalFields.plainOptions.push(item);
            externalFields.defaultCheckedList.push(item);
          }
215 216
          checkList.forEach(element => {
            // 当前得模块是否有当前字段
217
            let indeterminate = element.plainOptions.some(checkName => checkName === item);
218 219
            // 处理已选中的字段
            if (indeterminate) {
皮倩雯's avatar
皮倩雯 committed
220
              element.defaultCheckedList.push(item);
221 222
            }
            if (
皮倩雯's avatar
皮倩雯 committed
223 224
              element.defaultCheckedList.length > 0 &&
              element.defaultCheckedList.length < element.plainOptions.length
225
            ) {
皮倩雯's avatar
皮倩雯 committed
226
              element.indeterminate = true;
227
            } else {
皮倩雯's avatar
皮倩雯 committed
228
              element.indeterminate = false;
229 230
            }
            // 处理是否全选字段
231
            if (element.defaultCheckedList.length === element.plainOptions.length) {
皮倩雯's avatar
皮倩雯 committed
232
              element.checkAll = true;
233
            } else {
皮倩雯's avatar
皮倩雯 committed
234
              element.checkAll = false;
235
            }
邓超's avatar
邓超 committed
236
          });
237
        });
238 239 240 241
        // 添加外部字段
        if (externalFields.plainOptions.length > 0) {
          checkList.push(externalFields);
        }
242 243 244 245 246
        setFieldList(checkList);
        setTimeout(() => {
          setShowField(true);
        }, 0);
      }
邓超's avatar
邓超 committed
247 248 249 250 251 252 253 254 255
    });
  };
  // 字段修改后回调函数
  const setFiled = val => {
    let Fields = '';
    val.forEach((item, index) => {
      if (index === val.length - 1) {
        Fields = `${Fields + item}`;
      } else {
256
        Fields = `${Fields + item},`;
邓超's avatar
邓超 committed
257 258 259 260 261
      }
    });
    let obj = {};
    obj[fieldName] = Fields;
    form.setFieldsValue(obj);
262
    saveOutFieldsLength(fieldName, filedList);
邓超's avatar
邓超 committed
263 264 265 266 267 268
    setShowField(false);
  };
  // 提交表单
  const onFinish = () => {
    form.validateFields().then(validate => {
      if (validate) {
269
        console.log(validate);
270 271 272 273
        validate.Transferable = visibleChecked ? 1 : 0;
        validate.EventsInformation = visibleChecked1 ? 1 : 0;
        validate.IsSendMessage = visibleChecked2 ? 1 : 0;
        validate.AutoClose = visibleChecked3 ? '是' : '否';
274
        console.log(validate);
邓超's avatar
邓超 committed
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
        editFlowNodeExtend({ ...validate, flowNodeId: msg.ID })
          .then(res => {
            if (res.code === 0) {
              notification.success({
                message: '提示',
                duration: 3,
                description: '编辑成功',
              });
              onSubumit();
            } else {
              notification.error({
                message: '提示',
                duration: 3,
                description: res.msg,
              });
            }
          })
          .catch(() => {
            notification.error({
              message: '提示',
              duration: 3,
              description: '网络异常',
            });
          });
      }
    });
  };
  // 表单监听
  const onValuesChange = val => {
    if (Object.keys(val)[0] === 'Rollbackable') {
      if (val.Rollbackable) {
        setIsDisable(false);
      } else {
        setIsDisable(true);
      }
    }
  };
312 313 314 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 353 354 355 356 357 358 359 360
  // 表切换
  const changTable = val => {
    loadEventFields({ eventTableName: val }).then(res => {
      if (res.code === 0) {
        let initList = [];
        res.data.forEach(item => {
          item.root.forEach(ele => {
            initList.push(ele.fieldName);
          });
        });
        // 处理外部字段
        Object.keys(form.getFieldsValue()).forEach(key => {
          saveOutFieldsLength(key, initList);
        });
        setFiledList(initList);
      }
    });
  };
  // 保存外部字段个数
  const saveOutFieldsLength = (key, initList) => {
    switch (key) {
      case 'Fields':
        form.setFieldsValue({ OutFields: dealExternal(key, initList) });
        break;
      case 'SeeFields':
        form.setFieldsValue({ OutSeeFields: dealExternal(key, initList) });
        break;
      default:
        break;
    }
  };
  // 处理外部字段
  const dealExternal = (fileds, list) => {
    let isExternal;
    let externalLength = 0;
    if (form.getFieldValue(fileds)) {
      form
        .getFieldValue(fileds)
        .split(',')
        .forEach(item => {
          isExternal = list.some(val => val === item);
          if (!isExternal && item !== '') {
            // eslint-disable-next-line no-plusplus
            externalLength++;
          }
        });
    }
    return externalLength;
  };
361 362 363 364 365 366 367 368 369 370 371 372
  const change = e => {
    console.log(e);
    setVisibleChecked(e);
  };
  const change1 = e => {
    console.log(e);
    setVisibleChecked1(e);
  };
  const change2 = e => {
    console.log(e);
    setVisibleChecked2(e);
  };
373 374 375 376
  const change3 = e => {
    console.log(e);
    setVisibleChecked3(e);
  };
邓超's avatar
邓超 committed
377
  return (
皮倩雯's avatar
皮倩雯 committed
378
    <Drawer
邓超's avatar
邓超 committed
379
      title="流程节点配置"
皮倩雯's avatar
皮倩雯 committed
380 381
      width="500px"
      onClose={handleCancel}
382
      destroyOnClose
邓超's avatar
邓超 committed
383
      visible={visible}
皮倩雯's avatar
皮倩雯 committed
384 385 386 387 388 389 390 391
      footer={
        <Space>
          <Button onClick={handleCancel}>取消</Button>
          <Button onClick={onFinish} type="primary">
            确定
          </Button>
        </Space>
      }
邓超's avatar
邓超 committed
392 393 394 395 396 397 398 399 400 401 402 403
    >
      <Form
        form={form}
        labelCol={{ span: 5 }}
        wrapperCol={{ span: 18 }}
        initialValues={{ remember: true }}
        className={styles.formData}
        onValuesChange={onValuesChange}
      >
        <Form.Item label="流程节点" name="FlowName">
          <Input disabled />
        </Form.Item>
404 405 406 407 408
        <Form.Item
          label="节点别名"
          name="NodeAliasName"
          rules={[{ required: true, message: '请填写节点别名' }]}
        >
邓超's avatar
邓超 committed
409
          <Input placeholder="请输入节点别名" />
邓超's avatar
邓超 committed
410 411 412
        </Form.Item>
        <Form.Item label="节点类型">
          <Form.Item name="NodeType" style={{ marginBottom: '10px' }}>
邓超's avatar
邓超 committed
413
            <Select placeholder="请选择节点类型">
邓超's avatar
邓超 committed
414 415 416 417 418 419 420
              <Option value="办理">办理</Option>
              <Option value="上报">上报</Option>
              <Option value="分派">分派</Option>
              <Option value="审核">审核</Option>
              <Option value="办理关单">办理关单</Option>
            </Select>
          </Form.Item>
421
          <Form.Item name="EditableLater" valuePropName="checked" style={{ marginBottom: 0 }}>
邓超's avatar
邓超 committed
422 423 424 425 426 427 428 429 430 431 432 433 434
            <Checkbox>允许补正(事后修改)</Checkbox>
          </Form.Item>
          <div style={{ display: 'flex' }}>
            <Form.Item
              name="Rollbackable"
              valuePropName="checked"
              style={{ marginBottom: 0, width: '150px' }}
            >
              <Checkbox>允许回退至</Checkbox>
            </Form.Item>
            <Form.Item
              name="RollbackNode"
              style={{ marginBottom: 0, width: '100%' }}
435
              initialValue="(上一节点)"
邓超's avatar
邓超 committed
436
            >
邓超's avatar
邓超 committed
437
              <Select disabled={isDisable} placeholder="请选择回退节点">
邓超's avatar
邓超 committed
438 439 440 441 442 443 444 445 446
                {backNodes.map(item => (
                  <Option value={item.Name} key={item.ID}>
                    {item.Name}
                  </Option>
                ))}
              </Select>
            </Form.Item>
          </div>
        </Form.Item>
邓超's avatar
邓超 committed
447
        <Form.Item label="工单主表" name="TableName">
448
          <Select placeholder="请选择工单主表" onChange={changTable} showSearch>
邓超's avatar
邓超 committed
449 450 451 452 453 454 455
            {eventTable.map(item => (
              <Option value={item.Name} key={item.ID}>
                {item.Name}
              </Option>
            ))}
          </Select>
        </Form.Item>
邓超's avatar
邓超 committed
456
        <Form.Item label="移交方式" name="Handover">
457 458 459 460 461 462
          <Radio.Group>
            <Radio value="移交选择人">移交选择人</Radio>
            <Radio value="自处理">自处理</Radio>
            <Radio value="移交默认人">移交默认人</Radio>
            <Radio value="移交发起人">移交发起人</Radio>
            {/* <Option value="移交选择人">移交选择人</Option>
邓超's avatar
邓超 committed
463 464 465
            <Option value="自处理">自处理</Option>
            <Option value="自处理或者移交选择人">自处理或者移交选择人</Option>
            <Option value="移交默认人">移交默认人</Option>
466
            <Option value="移交发起人">移交发起人</Option>
邓超's avatar
邓超 committed
467 468
            <Option value="跨站移交">跨站移交</Option>
            <Option value="处理站点移交">处理站点移交</Option>
469 470
            <Option value="本人站点移交">本人站点移交</Option> */}
          </Radio.Group>
邓超's avatar
邓超 committed
471
        </Form.Item>
472
        {/* <Form.Item label="检查前面在办" name="aheadHandle">
邓超's avatar
邓超 committed
473 474 475 476 477 478 479 480 481 482 483
          <Select>
            <Option value={0}>前面有在办也能移交</Option>
            <Option value={1}>前面有在办不能移交</Option>
          </Select>
        </Form.Item>
        <Form.Item label="节点办理情况" name="NodeHandling">
          <Select>
            <Option value={0}>多人接收,多人办理</Option>
            <Option value={1}>多人接收,一人办理</Option>
            <Option value={2}>一人接收,一人办理</Option>
          </Select>
484
        </Form.Item> */}
485 486 487 488 489 490
        <Form.Item label="转办" name="Transferable">
          <Switch
            checkedChildren="是"
            unCheckedChildren="否"
            checked={visibleChecked}
            onChange={change}
491
            disabled={transfer}
492 493
          />
          {/* <Radio.Group>
邓超's avatar
邓超 committed
494 495
            <Radio value="0">否</Radio>
            <Radio value="1">是</Radio>
496
          </Radio.Group> */}
邓超's avatar
邓超 committed
497
        </Form.Item>
498

499
        <Form.Item label="显示事件信息" name="EventsInformation">
500 501 502 503 504 505 506
          <Switch
            checkedChildren="是"
            unCheckedChildren="否"
            checked={visibleChecked1}
            onChange={change1}
          />
          {/* <Radio.Group>
邓超's avatar
邓超 committed
507 508
            <Radio value="0">否</Radio>
            <Radio value="1">是</Radio>
509
          </Radio.Group> */}
邓超's avatar
邓超 committed
510
        </Form.Item>
511
        <Form.Item label="是否发送短信" name="IsSendMessage">
512 513 514 515 516 517 518
          <Switch
            checkedChildren="是"
            unCheckedChildren="否"
            checked={visibleChecked2}
            onChange={change2}
          />
          {/* <Radio.Group>
519 520
            <Radio value={0}>否</Radio>
            <Radio value={1}>是</Radio>
521
          </Radio.Group> */}
522
        </Form.Item>
523 524 525 526 527 528 529 530 531 532
        {autoClose && (
          <Form.Item label="自动关单" name="AutoClose">
            <Switch
              checkedChildren="是"
              unCheckedChildren="否"
              checked={visibleChecked3}
              onChange={change3}
            />
          </Form.Item>
        )}
邓超's avatar
邓超 committed
533

534 535 536
        <Form.Item
          label={
            <div className={styles.formData_label}>
537
              {form.getFieldValue('OutFields') ? (
538 539 540 541 542 543 544 545 546 547
                <Tooltip title={`外部字段${form.getFieldValue('OutFields')}个`}>
                  <InfoCircleOutlined style={{ color: 'red', padding: '0.2rem 0.2rem 0 0' }} />
                </Tooltip>
              ) : (
                ''
              )}
              <span>字段编辑</span>
            </div>
          }
        >
邓超's avatar
邓超 committed
548 549
          <div className={styles.filedListItem}>
            <Form.Item name="Fields" style={{ marginBottom: 0, width: '100%' }}>
550
              <Input placeholder="请选编辑字段" allowClear />
邓超's avatar
邓超 committed
551 552 553 554 555 556 557 558 559 560
            </Form.Item>
            <Button
              type="dashed"
              icon={<PlusOutlined />}
              onClick={() => {
                deployField('Fields');
              }}
            />
          </div>
        </Form.Item>
561
        {/* <Form.Item
562 563
          label={
            <div className={styles.formData_label}>
564 565
              {form.getFieldValue('OutSeeFields') ? (
                <Tooltip title={`外部字段${form.getFieldValue('OutSeeFields')}个`}>
566 567 568 569 570 571 572 573 574
                  <InfoCircleOutlined style={{ color: 'red', padding: '0.2rem 0.2rem 0 0' }} />
                </Tooltip>
              ) : (
                ''
              )}
              <span>查看字段</span>
            </div>
          }
        >
邓超's avatar
邓超 committed
575
          <div className={styles.filedListItem}>
576
            <Form.Item name="SeeFields" style={{ marginBottom: 0, width: '100%' }}>
皮倩雯's avatar
皮倩雯 committed
577
              <Input placeholder="请选择查看字段(工程模型)" allowClear />
邓超's avatar
邓超 committed
578 579 580 581 582 583 584 585 586
            </Form.Item>
            <Button
              type="dashed"
              icon={<PlusOutlined />}
              onClick={() => {
                deployField('SeeFields');
              }}
            />
          </div>
587
        </Form.Item> */}
588
        <Form.Item label="前端视图" name="WebPage">
邓超's avatar
邓超 committed
589 590
          <Input placeholder="请配置前端视图" />
        </Form.Item>
591
        {/* <Form.Item label="手持视图" name="MobilePage">
邓超's avatar
邓超 committed
592 593 594 595
          <Input placeholder="请配置手持视图" />
        </Form.Item>
        <Form.Item label="视图参数" name="PageParam">
          <Input placeholder="请配置视图参数" />
596
        </Form.Item> */}
邓超's avatar
邓超 committed
597
        <Form.Item label="反馈类型" name="FeedbackName">
598
          <Select placeholder="请选择反馈类型" allowClear>
邓超's avatar
邓超 committed
599 600 601 602 603 604 605
            {backType.map(item => (
              <Option value={item.value} key={item.value}>
                {item.value}
              </Option>
            ))}
          </Select>
        </Form.Item>
606
        {/* <Form.Item
邓超's avatar
邓超 committed
607 608 609 610 611
          name="FeedbackToEvent"
          valuePropName="checked"
          wrapperCol={{ offset: 5, span: 18 }}
        >
          <Checkbox>将反馈信息显示到事件级别</Checkbox>
612
        </Form.Item> */}
邓超's avatar
邓超 committed
613 614 615 616 617 618 619
      </Form>
      {/* 字段集选择 */}
      <Fieldselection
        visible={showField}
        handleCancel={() => setShowField(false)}
        fieldList={fieldList}
        onSubumit={val => setFiled(val)}
620
        filedData={filedData}
邓超's avatar
邓超 committed
621
      />
皮倩雯's avatar
皮倩雯 committed
622
    </Drawer>
邓超's avatar
邓超 committed
623 624 625
  );
};
export default NodeEdit;