AddFlowsModal.jsx 12.1 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2 3 4 5 6 7 8 9
/* eslint-disable indent */
/* eslint-disable react/jsx-no-duplicate-props */
/* eslint-disable no-shadow */
/* eslint-disable no-undef */
/* eslint-disable eqeqeq */
/* eslint-disable array-callback-return */
/* eslint-disable guard-for-in */
/* eslint-disable no-restricted-syntax */
/* eslint-disable camelcase */
皮倩雯's avatar
皮倩雯 committed
10
import React, { useState, useEffect } from 'react';
皮倩雯's avatar
皮倩雯 committed
11 12 13 14 15 16 17 18 19 20 21 22
import {
  Modal,
  Form,
  Input,
  notification,
  message,
  Row,
  Col,
  Select,
  Drawer,
  Space,
  Button,
邓超's avatar
邓超 committed
23
  Tooltip,
皮倩雯's avatar
皮倩雯 committed
24
} from 'antd';
邓超's avatar
邓超 committed
25
import { PlusOutlined, InfoCircleOutlined } from '@ant-design/icons';
皮倩雯's avatar
皮倩雯 committed
26
import ChangeAddFlows from './ChangeAddFlows';
27
import RMSComponents from '@/components/RolePmSite/index';
皮倩雯's avatar
皮倩雯 committed
28 29 30 31 32 33
import {
  CM_Event_ReloadFlows,
  CM_Event_LoadDepartmentAndRoles,
  CM_Event_AddEvenFlow,
  CM_Event_EditEvenFlow,
} from '@/services/standingBook/api';
皮倩雯's avatar
皮倩雯 committed
34
import styles from './incident.less';
皮倩雯's avatar
皮倩雯 committed
35 36

const { Option } = Select;
37
const { TextArea } = Input;
皮倩雯's avatar
皮倩雯 committed
38
const AddFlowsModal = props => {
皮倩雯's avatar
皮倩雯 committed
39
  const {
田翔's avatar
田翔 committed
40
    callBackSubmit = () => { },
皮倩雯's avatar
皮倩雯 committed
41 42 43 44 45 46 47 48 49 50
    type,
    visible,
    onClose,
    formObj,
    obj,
    maxLength,
    record,
  } = props;
  const [form] = Form.useForm();
  const { Item } = Form;
皮倩雯's avatar
皮倩雯 committed
51

皮倩雯's avatar
皮倩雯 committed
52 53 54 55 56 57 58 59 60 61
  const [filed1, setFiled1] = useState({}); // 传给子组件列表数据
  const [standingTable, setStandingTable] = useState([]);
  const [visible1, setVisible1] = useState(false);
  const [pickItem, setPickItem] = useState('');
  const [checkedList1, setCheckedList1] = useState([]);
  const [nu1, setNu1] = useState([]);
  const [inputValue, setInputValue] = useState({ Roles: '' });
  const [selectValue, setSelectValue] = useState('');
  const [characterValue, setCharacterValue] = useState('');
  const [strr, setStrr] = useState('');
62 63
  const [groupName, setGroupName] = useState('角色');
  const [chooseGroupName, setChooseGroupName] = useState(['角色', '部门', '站点']);
64
  const [keepFiled, setKeepFiled] = useState([]);
皮倩雯's avatar
皮倩雯 committed
65

皮倩雯's avatar
皮倩雯 committed
66 67 68
  useEffect(() => {
    getRole();
    CM_Event_ReloadFlows({ eventTypeId: obj }).then(res => {
邓超's avatar
邓超 committed
69 70 71 72 73
      if (res.code === 0) {
        res.data.forEach(item => {
          item.System = item.System.split('\\')[0];
        });
        console.log(res.data);
皮倩雯's avatar
皮倩雯 committed
74
        let arr = formateArrDataA(res.data, 'System');
邓超's avatar
邓超 committed
75 76 77 78 79 80 81 82 83 84 85 86 87

        console.log(arr, 'arr');
        let newArr = Object.keys(arr).map((item, index) => {
          // newArr.push(item);
          arr[item].sort((a, b) => b.IsOptional - a.IsOptional);
          return {
            label: item,
            options: arr[item].map(ele => ({
              label: ele.FlowName,
              value: ele.FlowName,
              disabled: !ele.IsOptional,
            })),
          };
皮倩雯's avatar
皮倩雯 committed
88
        });
邓超's avatar
邓超 committed
89 90 91 92
        // Object.keys(arr).map((item, index) => {
        //   newArr.push(arr[item]);
        // });
        console.log(newArr, 'newArr');
皮倩雯's avatar
皮倩雯 committed
93 94 95 96 97 98 99 100 101 102 103 104 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
        setStandingTable(newArr);
      }
    });
    if (type === 'add') {
      setInputValue({ Roles: '' });
      setFiled1({});
      form.resetFields();
    } else if (type === 'edit') {
      setStrr(record.FlowRoles);
      setInputValue({
        Roles: record.FlowRoles,
      });
      setSelectValue(record.FlowName);
    }
  }, [visible]);
  const formateArrDataA = (initialArr, name) => {
    // 判定传参是否符合规则
    if (!(initialArr instanceof Array)) {
      return '请传入正确格式的数组';
    }
    if (!name) {
      return '请传入对象属性';
    }
    // 先获取一下这个数组中有多少个"name"
    let nameArr = [];
    for (let i in initialArr) {
      if (nameArr.indexOf(initialArr[i][`${name}`]) === -1) {
        nameArr.push(initialArr[i][`${name}`]);
      }
    }
    // 新建一个包含多个list的结果对象
    let tempObj = {};
    // 根据不同的"name"生成多个数组
    for (let k in nameArr) {
      for (let j in initialArr) {
        if (initialArr[j][`${name}`] == nameArr[k]) {
          // 每次外循环时新建一个对应"name"的数组, 内循环时当前数组不变
          tempObj[nameArr[k]] = tempObj[nameArr[k]] || [];
          tempObj[nameArr[k]].push(initialArr[j]);
皮倩雯's avatar
皮倩雯 committed
132
        }
皮倩雯's avatar
皮倩雯 committed
133
      }
皮倩雯's avatar
皮倩雯 committed
134
    }
皮倩雯's avatar
皮倩雯 committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    for (let keys in tempObj) {
      let arr = [];
      tempObj[keys].map((item, index) => {
        tempObj[keys] = arr;
        item.key = index;
        arr.push(item);
      });
    }
    return tempObj;
  };
  const formateArrDataA1 = (initialArr, name) => {
    let aa = [];
    let a1 = [];
    let a2;
    let a3 = [];
皮倩雯's avatar
皮倩雯 committed
150
    initialArr.data.map(i => {
皮倩雯's avatar
皮倩雯 committed
151 152 153 154 155 156 157 158 159 160 161 162 163
      a2 = i.groupType;
      a1 = i.root;
      a1.map(j => {
        j.group = a2;
      });
      aa.push(i.root);
    });
    aa.map(p => {
      p.map(o => {
        a3.push(o);
      });
    });
    console.log(a3);
皮倩雯's avatar
皮倩雯 committed
164

皮倩雯's avatar
皮倩雯 committed
165 166 167
    // 判定传参是否符合规则
    if (!(a3 instanceof Array)) {
      return '请传入正确格式的数组';
皮倩雯's avatar
皮倩雯 committed
168
    }
皮倩雯's avatar
皮倩雯 committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    if (!name) {
      return '请传入对象属性';
    }
    // 先获取一下这个数组中有多少个"name"
    let nameArr = [];
    a3.map(i => {
      if (nameArr.indexOf(i.group) === -1) {
        nameArr.push(i.group);
      }
    });
    console.log(nameArr);
    // 新建一个包含多个list的结果对象
    let tempObj = {};
    // 根据不同的"name"生成多个数组
    for (let k in nameArr) {
      for (let j in a3) {
        if (a3[j].group == nameArr[k]) {
          // 每次外循环时新建一个对应"name"的数组, 内循环时当前数组不变
          tempObj[nameArr[k]] = tempObj[nameArr[k]] || [];
          tempObj[nameArr[k]].push(a3[j]);
皮倩雯's avatar
皮倩雯 committed
189
        }
皮倩雯's avatar
皮倩雯 committed
190
      }
皮倩雯's avatar
皮倩雯 committed
191
    }
皮倩雯's avatar
皮倩雯 committed
192 193 194 195 196 197 198
    console.log(tempObj);
    for (let key in tempObj) {
      let arr = [];
      tempObj[key].map(item => {
        tempObj[key] = arr;
        arr.push(item.Name);
      });
皮倩雯's avatar
皮倩雯 committed
199
    }
皮倩雯's avatar
皮倩雯 committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    return tempObj;
  };
  const onSumbit = () => {
    callBackSubmit();
    // setLoading(true);
    let aa = form.getFieldsValue().FlowName;
    if (type == 'add') {
      let index = aa.lastIndexOf('\\');
      aa = aa.substring(index + 1, aa.length);
      CM_Event_AddEvenFlow({
        eventTypeId: formObj.ID,
        flowName: aa,
        roles: inputValue.Roles,
        order: maxLength,
      })
        .then(res => {
          // setLoading(false);
          if (res.msg === 'Ok') {
            form.resetFields();
            callBackSubmit();
            notification.success({
              message: '提示',
              duration: 3,
              description: '新增成功',
            });
          } else {
            notification.error({
              message: '提示',
              duration: 3,
              description: res.msg,
            });
          }
232
        })
皮倩雯's avatar
皮倩雯 committed
233 234 235 236 237 238 239 240
        .catch(error => {
          notification.error({
            message: '提示',
            duration: 3,
            description: '新增失败',
          });
          // setLoading(false);
        });
皮倩雯's avatar
皮倩雯 committed
241
    }
皮倩雯's avatar
皮倩雯 committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    if (type == 'edit') {
      CM_Event_EditEvenFlow({
        eventTypeId: formObj.ID,
        eventFlowId: record.ID,
        roles: inputValue.Roles,
      })
        .then(res => {
          // setLoading(false);
          if (res.msg === '') {
            form.resetFields();
            callBackSubmit();
            notification.success({
              message: '提示',
              duration: 3,
              description: '编辑成功',
            });
          } else {
皮倩雯's avatar
皮倩雯 committed
259
            notification.error({
皮倩雯's avatar
皮倩雯 committed
260 261 262
              message: '提示',
              duration: 3,
              description: res.msg,
皮倩雯's avatar
皮倩雯 committed
263
            });
皮倩雯's avatar
皮倩雯 committed
264 265 266 267 268 269 270 271
          }
        })
        .catch(error => {
          notification.error({
            message: '提示',
            duration: 3,
            description: '编辑失败',
          });
272
          // setLoading(false);
皮倩雯's avatar
皮倩雯 committed
273 274 275 276 277 278 279 280
        });
    }
  };

  const getRole = () => {
    CM_Event_LoadDepartmentAndRoles().then(res => {
      if (res.msg === 'Ok') {
        setNu1(res.data);
281 282
        // setFiled1(formateArrDataA1(res.data, 'groupType'));
        setKeepFiled(groupArr(res.data, 'groupType'));
皮倩雯's avatar
皮倩雯 committed
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
        console.log(res.data);
      }
    });
  };
  const changeText = (e, type) => {
    let inputText = { ...inputValue };
    inputText[type] = e.target.value;
    setInputValue(inputText);
  };
  const pickFiled1 = fileds => {
    // setTypes('app')
    let pp = formateArrDataA1(nu1, 'group');
    let ab = inputValue[fileds].split(',');
    console.log(pp);
    let arr = Object.keys(pp);
    let b = [];
    let a = [];
    arr.map((item, index) => {
      pp[item].map((i, j) => {
        b.push(i);
      });
    });
    console.log(ab);
    ab.map((item, index) => {
      if (b.includes(item) == false) {
        if (item == '') {
          a = [];
皮倩雯's avatar
皮倩雯 committed
310
        } else {
皮倩雯's avatar
皮倩雯 committed
311
          a.push(item);
皮倩雯's avatar
皮倩雯 committed
312
        }
皮倩雯's avatar
皮倩雯 committed
313 314
      }
    });
315 316 317 318 319
    // if (a.length > 0) {
    //   pp.外部字段 = a;
    //   console.log(pp);
    //   arr.push('外部字段');
    // }
皮倩雯's avatar
皮倩雯 committed
320 321
    console.log(a);
    console.log(pp);
322 323
    setKeepFiled(groupArr(nu1, 'group'));
    // setFiled1(pp);
皮倩雯's avatar
皮倩雯 committed
324 325 326 327 328 329
    console.log(fileds);
    setCharacterValue(inputValue[fileds]);
    setCheckedList1(inputValue[fileds].split(','));
    setPickItem(fileds);
    setVisible1(true);
  };
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347

  const groupArr = (initialArr, name) => {
    let list = {};
    initialArr.data.map(i => {
      console.log(i);
      let ar = [];
      i.root.map(j => {
        let ss = {};
        ss.label = j.Name;
        ss.value = j.ID.toString();
        ar.push(ss);
        // console.log(ss);
      });
      list[i.groupType] = ar;
    });
    console.log(list);
    return list;
  };
皮倩雯's avatar
皮倩雯 committed
348
  const onOKk = prop => {
349 350 351 352 353 354
    setVisible1(false);
    let inputText = { ...inputValue };
    inputText[prop.pickItem] = prop.str;
    setStrr(prop.str);
    setCheckedList1(prop.stt);
    setInputValue(inputText);
皮倩雯's avatar
皮倩雯 committed
355 356 357 358 359
  };
  return (
    <Drawer
      title={type === 'add' ? '添加受理流程' : '编辑受理流程'}
      visible={visible}
360
      width="500px"
皮倩雯's avatar
皮倩雯 committed
361 362 363 364 365 366 367 368 369 370 371 372
      onClose={onClose}
      destroyOnClose
      footer={
        <Space>
          <Button onClick={onSumbit} type="primary">
            确定
          </Button>
        </Space>
      }
    >
      <Form form={form} labelCol={{ span: 7 }} style={{ overflowY: 'scroll' }}>
        <Row>
373
          <Col span={24}>
邓超's avatar
邓超 committed
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
            <Item
              label={
                <div style={{ display: 'flex', alignItems: 'center' }}>
                  <Tooltip title="若存在不可用流程,请检查流程配置">
                    <InfoCircleOutlined
                      style={{
                        color: '#1890ff',
                      }}
                    />
                  </Tooltip>
                  <span>受理流程</span>
                </div>
              }
              name="FlowName"
              labelCol={{ span: 5 }}
            >
              <Select
                options={standingTable}
                placeholder="选择受理流程"
                disabled={type === 'edit'}
              />
            </Item>
皮倩雯's avatar
皮倩雯 committed
396
          </Col>
397
          {/* <Col span={24}>
邓超's avatar
邓超 committed
398
            <Item label="受理权限" name="Roles" labelCol={{ span: 5 }}>
399 400
              <div style={{ display: 'flex', alignContent: 'flex-start' }}>
                <TextArea
皮倩雯's avatar
皮倩雯 committed
401 402 403 404 405 406 407 408 409 410
                  style={{ width: '83%' }}
                  placeholder="请选择受理权限"
                  onChange={e => changeText(e, 'Roles')}
                  value={inputValue.Roles}
                  allowClear
                />
                <Button
                  type="dashed"
                  onClick={() => pickFiled1('Roles')}
                  icon={<PlusOutlined style={{ marginTop: '5px' }} />}
411
                  style={{ marginLeft: '5px', width: '58px', height: '54px' }}
皮倩雯's avatar
皮倩雯 committed
412 413 414
                />
              </div>
            </Item>
415
          </Col> */}
皮倩雯's avatar
皮倩雯 committed
416 417
        </Row>
      </Form>
418
      {/* <ChangeAddFlows
皮倩雯's avatar
皮倩雯 committed
419 420 421 422
        visible={visible1}
        onCancel={() => setVisible1(false)}
        callBackSubmit={onOKk}
        newCheckedList={checkedList1}
423
        filed11={filed1}
皮倩雯's avatar
皮倩雯 committed
424
        pickItem={pickItem}
425 426 427 428 429 430 431 432 433
      /> */}
      <RMSComponents
        visible={visible1}
        onCancel={() => setVisible1(false)}
        callBackSubmit={onOKk}
        newCheckedList={checkedList1} // 单选框中的值
        pickItem={pickItem}
        groupName={groupName} // 打开组件展示的分组名,用来首次获取数据
        chooseGroupName={chooseGroupName} // 可选分组名
434
        keepFiled={keepFiled}
435
        dataType="name"
皮倩雯's avatar
皮倩雯 committed
436 437 438 439 440
      />
    </Drawer>
  );
};
export default AddFlowsModal;