WorkflowHomePage.jsx 18.3 KB
Newer Older
邓超's avatar
邓超 committed
1 2 3
import React, { useEffect, useState, useRef } from 'react';
import { useHistory } from 'react-router-dom';
import classnames from 'classnames';
4
import { Tabs, Input, message, Modal, Button, Anchor, Tooltip, notification } from 'antd';
邓超's avatar
邓超 committed
5 6 7 8 9
import {
  PlusOutlined,
  EditOutlined,
  DeleteOutlined,
  ExclamationCircleOutlined,
10
  HighlightOutlined,
邓超's avatar
邓超 committed
11
  UnorderedListOutlined,
12
  FilePdfOutlined,
邓超's avatar
邓超 committed
13
} from '@ant-design/icons';
14 15
import gsap, { TweenMax, TimelineMax, ScrollToPlugin } from 'gsap/all';

邓超's avatar
邓超 committed
16 17
import FlowModal from './workFlowComponents/FlowModal';
import FlowGroupModal from './workFlowComponents/FlowGroupModal';
邓超's avatar
邓超 committed
18
import Order from './workFlowComponents/Order';
邓超's avatar
邓超 committed
19 20
import styles from './WorkflowHomePage.less';
import { WFGetAllFlow, GetFlowNode, DeleteFlow } from '@/services/workflow/workflow';
21
import { UpdateFlowGroup } from '@/services/workflow/workflow';
22
const plugins = [ScrollToPlugin];
邓超's avatar
邓超 committed
23
const { Search } = Input;
24
const { Link } = Anchor;
邓超's avatar
邓超 committed
25
const { confirm } = Modal;
26
const path = require('path');
邓超's avatar
邓超 committed
27 28 29 30 31 32

const WorkflowHomePage = () => {
  const history = useHistory();
  const [flowList, setFlowList] = useState([]); // 流程列表
  const [currentList, setCurrentList] = useState([]); // 当前tab显示列表

33
  const [modalType, setModalType] = useState(null); // 弹窗类型是编辑还是新增
邓超's avatar
邓超 committed
34 35
  const [editMsg, setEditMsg] = useState({}); // 弹窗编辑回显
  const [editIndex, setEditIndex] = useState(); // 编辑流程组得索引
36
  const [hoverIndex, setHoverIndex] = useState();
邓超's avatar
邓超 committed
37
  const [flowNames, setFlowNames] = useState([]);
38
  const [flowTableScroll, setFlowTableScroll] = useState(0);
邓超's avatar
邓超 committed
39 40 41
  const [visible, setVisible] = useState({
    FlowModal: false,
    FlowGroupModal: false,
邓超's avatar
邓超 committed
42
    order: false,
邓超's avatar
邓超 committed
43 44 45
  }); // 弹窗显示
  const [flag, setFlag] = useState(0);
  const activeKey = useRef(null);
46 47
  const isClick = useRef(false);
  const scrollTimer = useRef();
邓超's avatar
邓超 committed
48
  useEffect(() => {
49
    gsap.registerPlugin(ScrollToPlugin);
邓超's avatar
邓超 committed
50
    getFlowList();
51
    let flowTable = document.querySelector(`.${styles.flowTable}`);
52 53 54 55 56
    flowTable.addEventListener('scroll', setScroll);

    return () => {
      flowTable.removeEventListener('scroll', setScroll);
    };
邓超's avatar
邓超 committed
57
  }, []);
58

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  useEffect(() => {
    clearTimeout(scrollTimer.current);
    scrollTimer.current = setTimeout(() => {
      // todo something scroll end
      isClick.current = false;
    }, 50);
    console.log(isClick.current, 'isClick.current');
    if (isClick.current) {
      return;
    }
    flowList.forEach(item => {
      let groupSrolltop = document.getElementById(`${item.name}`)?.offsetTop;
      if (groupSrolltop <= flowTableScroll) {
        activeKey.current = item.name;
        setFlag(flag + 1);
      }
    });
  }, [flowTableScroll]);

邓超's avatar
邓超 committed
78 79
  useEffect(() => {
    console.log(history.location.state, 'history.location.state');
80 81 82 83 84 85 86 87 88 89 90
    if (modalType) {
      if (modalType === 'add') {
        console.log('addsaasddfas');
        isClick.current = true;
        setTimeout(() => {
          TweenMax.to(`.${styles.flowTable}`, 0.5, { scrollTo: { y: `#${activeKey.current}` } });
        }, 0);
      }
      setModalType(null);
      return;
    }
邓超's avatar
邓超 committed
91
    if (history.location.state) {
邓超's avatar
邓超 committed
92
      console.log(document.querySelector(`.${styles.flowTable}`));
93 94
      activeKey.current = history.location.state.activeKey;
      isClick.current = true;
邓超's avatar
邓超 committed
95
      setTimeout(() => {
96 97 98 99 100
        TweenMax.to(`.${styles.flowTable}`, 0.5, {
          scrollTo: { y: history.location.state.scrollTop },
        });
        // let flowTable = document.querySelector(`.${styles.flowTable}`);
        // document.querySelector(`.${styles.flowTable}`).scrollTop = history.location.state.scrollTop;
邓超's avatar
邓超 committed
101
      }, 0);
邓超's avatar
邓超 committed
102
    }
邓超's avatar
邓超 committed
103
  }, [flowList]);
104 105 106 107
  const setScroll = () => {
    let flowTable = document.querySelector(`.${styles.flowTable}`);
    setFlowTableScroll(flowTable.scrollTop);
  };
邓超's avatar
邓超 committed
108 109 110 111 112
  // 获取所有数据
  const getFlowList = () => {
    WFGetAllFlow().then(res => {
      if (res.code === 0) {
        let flowNameList = [];
113
        let list = res.data.map((item, index) => {
邓超's avatar
邓超 committed
114 115 116 117
          item.children.forEach(ele => {
            flowNameList.push(ele.FlowName);
          });
          item.isOld = true;
118
          item.bgType = (index + 1) % 5;
邓超's avatar
邓超 committed
119 120 121 122
          return item;
        });
        setFlowList(list);
        console.log(activeKey.current, 'activeKey');
123 124 125 126 127 128
        // if (activeKey.current) {
        //   setCurrentList(list.filter(item => item.name === activeKey.current));
        // } else {
        //   setCurrentList(list);
        // }
        setCurrentList(list);
邓超's avatar
邓超 committed
129 130
        console.log(flowNameList, 'flowNameList');
        setFlowNames(flowNameList);
131 132
      } else {
        message.error(res.msg);
邓超's avatar
邓超 committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
      }
    });
  };

  // 弹窗显示控制
  const showModal = (key, value) => {
    setVisible({ ...visible, [key]: value });
  };
  // 查看所有
  const chageAll = () => {
    // setActiveKey(null);
    activeKey.current = null;
    setCurrentList(flowList);
  };
  // 搜索
  const onSearch = val => {
149 150 151 152 153
    // let copyList = JSON.parse(JSON.stringify(flowList));
    // let list = activeKey.current
    //   ? copyList.filter(item => item.name === activeKey.current)
    //   : copyList;
    let list = JSON.parse(JSON.stringify(flowList));
邓超's avatar
邓超 committed
154 155 156 157 158
    if (val) {
      list.forEach(item => {
        item.children = item.children.filter(ele => ele.FlowName.includes(val));
      });
    }
159 160
    isClick.current = true;
    activeKey.current = list[0].name;
邓超's avatar
邓超 committed
161 162
    setCurrentList(list);
    setFlag(flag + 1);
163 164 165
    setTimeout(() => {
      document.querySelector(`.${styles.flowTable}`).scrollTop = 0;
    }, 0);
邓超's avatar
邓超 committed
166 167 168
  };
  // 切换tab
  const onChange = val => {
169 170 171 172 173
    isClick.current = true;
    console.log(val);
    let flowTable = document.querySelector(`.${styles.flowTable}`);
    console.log(flowTable.scrollTop, 'flowTable');
    TweenMax.to(`.${styles.flowTable}`, 0.5, { scrollTo: { y: `#${val}` } });
邓超's avatar
邓超 committed
174 175 176
    let copyList = JSON.parse(JSON.stringify(flowList));
    let list = copyList.filter(item => item.name === val);
    activeKey.current = val;
177 178
    setFlag(flag + 1);
    // setCurrentList(list);
邓超's avatar
邓超 committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215

    // setActiveKey(val);
  };
  // 编辑流程
  const editFlow = (val, e) => {
    e.stopPropagation();
    showModal('FlowModal', true);
    setModalType('edit');
    setEditMsg(val);
  };
  // 新增流程
  const addFlow = val => {
    showModal('FlowModal', true);
    setEditMsg(val);
    setModalType('add');
  };
  // 添加流程组
  const addFlowGroup = () => {
    showModal('FlowGroupModal', true);
    setModalType('add');
  };
  // 编辑流程组
  const eiditFlowGroup = (val, index) => {
    setEditIndex(index);
    showModal('FlowGroupModal', true);
    setModalType('edit');
    setEditMsg(val);
  };
  // 编辑组回调
  const groupCallBack = val => {
    activeKey.current = val;
    showModal('FlowGroupModal', false);
    // 编辑老数据需要掉接口更新新数据手动修改数据,新增插入一条数据
    if (modalType === 'edit' && editMsg.isOld) {
      getFlowList();
    } else if (modalType === 'edit') {
      let newflowList = [...flowList];
216
      // newflowList[editIndex].name = val;
邓超's avatar
邓超 committed
217 218 219 220 221 222 223 224
      setFlowList(newflowList);
      setCurrentList(newflowList.filter(item => item.name === activeKey.current));
    } else {
      setCurrentList([{ name: val, children: [] }]);
      setFlowList([...flowList, { name: val }]);
    }
  };
  const chooseNode = val => {
邓超's avatar
邓超 committed
225
    let scroll = document.querySelector(`.${styles.flowTable}`).scrollTop;
邓超's avatar
邓超 committed
226 227 228 229 230
    GetFlowNode({ flowID: val.FlowID }).then(res => {
      if (res.code === 0) {
        res.data.Nodes.forEach(item => {
          item.nodeDetail = JSON.stringify(item);
        });
231
        setModalType(null);
邓超's avatar
邓超 committed
232 233 234
        history.push({
          pathname: '/biz/workflow/flowBoard',
          state: {
邓超's avatar
邓超 committed
235
            scrollTop: scroll,
邓超's avatar
邓超 committed
236 237 238 239
            flowData: { ...res.data, flowName: val.FlowName },
            flowID: val.FlowID,
            chartLoading: false,
            activeKey: activeKey.current,
240
            flowTree: flowList,
邓超's avatar
邓超 committed
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
          },
        });
      } else {
        message.error(res.msg);
      }
    });
  };
  // 删除流程
  const delFlow = (val, e) => {
    e.stopPropagation();
    confirm({
      title: '确定要删除吗?',
      icon: <ExclamationCircleOutlined />,
      content: '',
      okText: '是',
      okType: 'danger',
      cancelText: '否',
      onOk() {
        DeleteFlow({ FlowId: val.FlowID })
          .then(res => {
            if (res.code === 0) {
262
              setModalType('del');
邓超's avatar
邓超 committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
              getFlowList();
              message.success('删除成功');
            } else {
              message.error(res.msg);
            }
          })
          .catch(() => {
            message.error('网络异常请稍后再试');
          });
      },
      onCancel() {},
    });
  };
  // tab栏选项渲染
  const tabRender = (val, index) => (
    <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-around' }}>
      {val.name}({val.count})
邓超's avatar
邓超 committed
280
      {/* {val.name === activeKey.current ? (
邓超's avatar
邓超 committed
281 282 283
        <EditOutlined onClick={() => eiditFlowGroup(val, index)} style={{ marginLeft: '5px' }} />
      ) : (
        ''
邓超's avatar
邓超 committed
284
      )} */}
邓超's avatar
邓超 committed
285 286
    </div>
  );
287 288 289 290 291 292
  const toFlowGroup = (e, val) => {
    e.preventDefault();
    let flowTable = document.querySelector(`.${styles.flowTable}`);
    console.log(`.${styles.flowTable}`);
    TweenMax.to(`.${styles.flowTable}`, 1, { scrollTo: val.href });
  };
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
  const updateFlowGroup = (oldName, newName) => {
    if (oldName === newName) {
      return;
    }
    UpdateFlowGroup({
      oldName,
      newName,
    }).then(res => {
      if (res.code === 0) {
        notification.success({
          message: '提示',
          duration: 3,
          description: '编辑成功',
        });
        getFlowList();
      } else {
        notification.error({
          message: '提示',
          duration: 3,
          description: res.msg,
        });
      }
    });
  };
邓超's avatar
邓超 committed
317
  return (
318
    <div
319
      className={classnames(styles.pageContent, {
320 321
        [styles.pageOms]:
          sessionStorage.getItem('_omsticket') !== 'd438aaf9578f405299ae740c4eb75aae',
322 323
        [styles.pageEmbed]:
          sessionStorage.getItem('_omsticket') === 'd438aaf9578f405299ae740c4eb75aae',
324 325
      })}
    >
邓超's avatar
邓超 committed
326 327 328
      <div className={styles.headerBox}>
        <div className={styles.left}>
          <div
329 330
            className={classnames(styles.allFlows, { [styles.allFlowsChoose]: true })}
            // onClick={chageAll}
邓超's avatar
邓超 committed
331 332
          />
          <div className={styles.flows}>
333 334 335 336 337 338 339 340 341 342 343 344 345 346
            {/* <Anchor affix={false} onClick={toFlowGroup}>
              {flowList.map((item, index) => (
                <Link href={`#${item.name}`} title={item.name} key={item.name} />
              ))}
            </Anchor> */}
            <div className={styles.tabBox}>
              {flowList.map((item, index) => (
                <div
                  className={classnames(styles.tab, {
                    [styles.activeTab]: item.name === activeKey.current,
                  })}
                  onClick={() => onChange(item.name)}
                  key={item.name}
                >
邓超's avatar
邓超 committed
347
                  {item.name}({item.count})
348 349 350 351
                </div>
              ))}
            </div>
            {/* <Tabs activeKey={activeKey.current} type="card" onChange={onChange} animated={false}>
邓超's avatar
邓超 committed
352 353 354
              {flowList.map((item, index) => (
                <Tabs.TabPane tab={tabRender(item, index)} key={item.name} />
              ))}
355
            </Tabs> */}
邓超's avatar
邓超 committed
356 357
          </div>
        </div>
邓超's avatar
邓超 committed
358 359 360 361 362 363 364 365 366 367
        <div
          className={styles.right}
          onClick={() => {
            showModal('order', true);
          }}
        >
          {/* <div className={styles.icon} /> */}
          <UnorderedListOutlined style={{ marginRight: '5px' }} />
          <div>流程排序</div>
        </div>
邓超's avatar
邓超 committed
368 369 370 371 372 373 374 375
      </div>
      <div className={styles.controlBox}>
        <div className={styles.left}>
          总计:
          <span>{currentList.reduce((sum, p) => p.children.length + sum, 0)}</span>
        </div>
        <div className={styles.right}>
          <div className={styles.btn} onClick={() => addFlow(currentList[0])}>
邓超's avatar
邓超 committed
376
            <PlusOutlined style={{ marginRight: '5px' }} /> 新增流程
邓超's avatar
邓超 committed
377 378 379 380 381 382 383 384 385 386
          </div>
          <Search
            placeholder="输入关键字搜索"
            allowClear
            onSearch={onSearch}
            style={{
              width: 490,
            }}
          />
        </div>
387
        <div className={styles.showPDF}>
388
          <Tooltip title="点击查看对接文档">
389 390 391 392 393 394 395 396 397 398
            <a
              style={{ display: 'inline-block', marginTop: '5px', marginRight: '20px' }}
              target="_blank"
              href={path.join(__dirname, '/civmanage/第三方工单对接说明文档.pdf')}
              rel="noopener noreferer"
            >
              <FilePdfOutlined style={{ fontSize: '24px' }} />
            </a>
          </Tooltip>
        </div>
邓超's avatar
邓超 committed
399 400 401
      </div>
      <div className={styles.flowTable}>
        {currentList.map((item, index) => (
402
          <div className={styles.flowGroup} key={item.name} id={item.name}>
邓超's avatar
邓超 committed
403 404 405 406 407
            <div
              className={styles.header}
              style={{ display: item.children.length > 0 ? 'flex' : 'none' }}
            >
              <div className={styles.line} />
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
              <div className={styles.name} contenteditable="true">
                <Input
                  style={{
                    width: item.name.length*14 + 'px',
                    fontSize: '14px',
                    padding: '0'
                  }}
                  placeholder="请输入分组名称"
                  onBlur={e => {
                    updateFlowGroup(item.name, e.currentTarget.value);
                  }}
                  bordered={false}
                  defaultValue={item.name}
                  onInput= {e=> {
                    e.currentTarget.style.width = (e.currentTarget.value.length) * 14 + "px";
                  }}
                  // onPressEnter={e => {
                  //   console.log(e, '触发咯');
                  // }}
                />
邓超's avatar
邓超 committed
428 429 430 431 432
              </div>
              <EditOutlined
                style={{ marginLeft: '5px' }}
                onClick={() => eiditFlowGroup(item, index)}
              />
邓超's avatar
邓超 committed
433 434
            </div>
            <div className={styles.groupBox}>
435 436 437 438 439 440 441 442
              {item.children.map((ele, num) => (
                <div
                  className={styles.flowBox}
                  type={item.bgType}
                  key={ele.Code}
                  onMouseEnter={() => setHoverIndex(JSON.stringify([index, num]))}
                  onMouseLeave={() => setHoverIndex(null)}
                >
邓超's avatar
邓超 committed
443 444
                  <div className={styles.header}>
                    <div className={styles.title}>{ele.FlowName}</div>
445

邓超's avatar
邓超 committed
446 447
                    <div className={styles.editBtn} onClick={e => editFlow(ele, e)}>
                      <EditOutlined />
448
                      修改
邓超's avatar
邓超 committed
449 450 451
                    </div>
                  </div>
                  <div className={styles.imgBox}>
452 453 454 455 456 457 458 459 460 461
                    <div
                      className={classnames(styles.mask, {
                        [styles.maskHover]: JSON.stringify([index, num]) === hoverIndex,
                      })}
                    />
                    <div
                      className={classnames(styles.buttonBox, {
                        [styles.buttonHover]: JSON.stringify([index, num]) === hoverIndex,
                      })}
                    >
462
                      <div className={styles.lookDetail}>
463 464 465 466 467
                        <Button
                          type="primary"
                          onClick={() => chooseNode(ele)}
                          style={{ background: '#3D78FF', color: '#fff', opacity: 1 }}
                        >
468 469 470 471 472 473 474
                          设计
                        </Button>

                        {/* <HighlightOutlined onClick={e => chooseNode(ele, e)} /> */}
                      </div>
                      <div className={styles.delete}>
                        <Button
475 476 477 478 479 480
                          style={{
                            background: '#fff',
                            border: '1px solid #FF4D4F',
                            color: '#FF4D4F',
                            opacity: 1,
                          }}
481 482 483 484 485 486 487 488
                          type="primary"
                          onClick={e => delFlow(ele, e)}
                        >
                          删除
                        </Button>
                        {/* <DeleteOutlined onClick={e => delFlow(ele, e)} /> */}
                      </div>
                    </div>
489
                    {ele.PreviewImage ? (
490 491 492 493 494 495
                      // <img
                      //   src={`${
                      //     window.location.origin
                      //   }/PandaOMS/OMS/FileCenter/DownLoadFiles?filePath=${ele.PreviewImage}`}
                      // />
                      <img src={`${window.location.origin}/${ele.PreviewImage}`} />
496 497 498 499 500 501
                    ) : (
                      <img
                        className={styles.noDataImg}
                        src={require('../../../../assets/images/common/noData.png')}
                      />
                    )}
邓超's avatar
邓超 committed
502 503
                  </div>
                  <div className={styles.bottom}>
邓超's avatar
邓超 committed
504
                    <div className={styles.left}>{ele.CreateUser || ''}</div>
邓超's avatar
邓超 committed
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
                    <div className={styles.right}>更新于{ele.UpdateTime || '--'}</div>
                  </div>
                </div>
              ))}
            </div>
          </div>
        ))}
      </div>
      {/* 添加流程弹窗 */}
      <FlowModal
        visible={visible.FlowModal}
        msg={editMsg}
        modalType={modalType}
        handleCancel={() => showModal('FlowModal', false)}
        keep={flowNames}
        treeData={flowList}
521 522
        onSubumit={val => {
          activeKey.current = val;
邓超's avatar
邓超 committed
523 524 525 526 527 528 529 530 531 532 533 534 535 536
          showModal('FlowModal', false);
          getFlowList();
        }}
      />
      {/* 创建分组弹窗 */}
      <FlowGroupModal
        visible={visible.FlowGroupModal}
        msg={editMsg}
        modalType={modalType}
        handleCancel={() => showModal('FlowGroupModal', false)}
        treeData={flowList}
        keep={flowNames}
        onSubumit={val => groupCallBack(val)}
      />
邓超's avatar
邓超 committed
537 538 539 540 541 542 543 544 545 546 547
      {/* 排序弹窗 */}
      <Order
        visible={visible.order}
        processData={flowList}
        handleCancel={() => showModal('order', false)}
        submitCallBack={() => {
          // activeKey.current = currentList[0];
          showModal('order', false);
          getFlowList();
        }}
      />
邓超's avatar
邓超 committed
548 549 550 551 552
    </div>
  );
};

export default WorkflowHomePage;