WorkflowHomePage.jsx 16.7 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 } 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
const plugins = [ScrollToPlugin];
邓超's avatar
邓超 committed
22
const { Search } = Input;
23
const { Link } = Anchor;
邓超's avatar
邓超 committed
24
const { confirm } = Modal;
25
const path = require('path');
邓超's avatar
邓超 committed
26 27 28 29 30 31

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

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

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

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  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
77 78
  useEffect(() => {
    console.log(history.location.state, 'history.location.state');
79 80 81 82 83 84 85 86 87 88 89
    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
90
    if (history.location.state) {
邓超's avatar
邓超 committed
91
      console.log(document.querySelector(`.${styles.flowTable}`));
92 93
      activeKey.current = history.location.state.activeKey;
      isClick.current = true;
邓超's avatar
邓超 committed
94
      setTimeout(() => {
95 96 97 98 99
        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
100
      }, 0);
邓超's avatar
邓超 committed
101
    }
邓超's avatar
邓超 committed
102
  }, [flowList]);
103 104 105 106
  const setScroll = () => {
    let flowTable = document.querySelector(`.${styles.flowTable}`);
    setFlowTableScroll(flowTable.scrollTop);
  };
邓超's avatar
邓超 committed
107 108 109 110 111
  // 获取所有数据
  const getFlowList = () => {
    WFGetAllFlow().then(res => {
      if (res.code === 0) {
        let flowNameList = [];
112
        let list = res.data.map((item, index) => {
邓超's avatar
邓超 committed
113 114 115 116
          item.children.forEach(ele => {
            flowNameList.push(ele.FlowName);
          });
          item.isOld = true;
117
          item.bgType = (index + 1) % 5;
邓超's avatar
邓超 committed
118 119 120 121
          return item;
        });
        setFlowList(list);
        console.log(activeKey.current, 'activeKey');
122 123 124 125 126 127
        // if (activeKey.current) {
        //   setCurrentList(list.filter(item => item.name === activeKey.current));
        // } else {
        //   setCurrentList(list);
        // }
        setCurrentList(list);
邓超's avatar
邓超 committed
128 129
        console.log(flowNameList, 'flowNameList');
        setFlowNames(flowNameList);
130 131
      } else {
        message.error(res.msg);
邓超's avatar
邓超 committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
      }
    });
  };

  // 弹窗显示控制
  const showModal = (key, value) => {
    setVisible({ ...visible, [key]: value });
  };
  // 查看所有
  const chageAll = () => {
    // setActiveKey(null);
    activeKey.current = null;
    setCurrentList(flowList);
  };
  // 搜索
  const onSearch = val => {
148 149 150 151 152
    // 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
153 154 155 156 157
    if (val) {
      list.forEach(item => {
        item.children = item.children.filter(ele => ele.FlowName.includes(val));
      });
    }
158 159
    isClick.current = true;
    activeKey.current = list[0].name;
邓超's avatar
邓超 committed
160 161
    setCurrentList(list);
    setFlag(flag + 1);
162 163 164
    setTimeout(() => {
      document.querySelector(`.${styles.flowTable}`).scrollTop = 0;
    }, 0);
邓超's avatar
邓超 committed
165 166 167
  };
  // 切换tab
  const onChange = val => {
168 169 170 171 172
    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
173 174 175
    let copyList = JSON.parse(JSON.stringify(flowList));
    let list = copyList.filter(item => item.name === val);
    activeKey.current = val;
176 177
    setFlag(flag + 1);
    // setCurrentList(list);
邓超's avatar
邓超 committed
178 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

    // 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];
215
      // newflowList[editIndex].name = val;
邓超's avatar
邓超 committed
216 217 218 219 220 221 222 223
      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
224
    let scroll = document.querySelector(`.${styles.flowTable}`).scrollTop;
邓超's avatar
邓超 committed
225 226 227 228 229
    GetFlowNode({ flowID: val.FlowID }).then(res => {
      if (res.code === 0) {
        res.data.Nodes.forEach(item => {
          item.nodeDetail = JSON.stringify(item);
        });
230
        setModalType(null);
邓超's avatar
邓超 committed
231 232 233
        history.push({
          pathname: '/biz/workflow/flowBoard',
          state: {
邓超's avatar
邓超 committed
234
            scrollTop: scroll,
邓超's avatar
邓超 committed
235 236 237 238
            flowData: { ...res.data, flowName: val.FlowName },
            flowID: val.FlowID,
            chartLoading: false,
            activeKey: activeKey.current,
239
            flowTree: flowList,
邓超's avatar
邓超 committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
          },
        });
      } 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) {
261
              setModalType('del');
邓超's avatar
邓超 committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
              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
279
      {/* {val.name === activeKey.current ? (
邓超's avatar
邓超 committed
280 281 282
        <EditOutlined onClick={() => eiditFlowGroup(val, index)} style={{ marginLeft: '5px' }} />
      ) : (
        ''
邓超's avatar
邓超 committed
283
      )} */}
邓超's avatar
邓超 committed
284 285
    </div>
  );
286 287 288 289 290 291
  const toFlowGroup = (e, val) => {
    e.preventDefault();
    let flowTable = document.querySelector(`.${styles.flowTable}`);
    console.log(`.${styles.flowTable}`);
    TweenMax.to(`.${styles.flowTable}`, 1, { scrollTo: val.href });
  };
邓超's avatar
邓超 committed
292
  return (
293 294 295 296 297 298 299
    <div
      className={classnames(styles.pageContent,{
        [styles.pageOms]:
          sessionStorage.getItem('_omsticket') !== 'd438aaf9578f405299ae740c4eb75aae',
        [styles.pageEmbed]: sessionStorage.getItem('_omsticket') === 'd438aaf9578f405299ae740c4eb75aae',
      })}
    >
邓超's avatar
邓超 committed
300 301 302
      <div className={styles.headerBox}>
        <div className={styles.left}>
          <div
303 304
            className={classnames(styles.allFlows, { [styles.allFlowsChoose]: true })}
            // onClick={chageAll}
邓超's avatar
邓超 committed
305 306
          />
          <div className={styles.flows}>
307 308 309 310 311 312 313 314 315 316 317 318 319 320
            {/* <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
321
                  {item.name}({item.count})
322 323 324 325
                </div>
              ))}
            </div>
            {/* <Tabs activeKey={activeKey.current} type="card" onChange={onChange} animated={false}>
邓超's avatar
邓超 committed
326 327 328
              {flowList.map((item, index) => (
                <Tabs.TabPane tab={tabRender(item, index)} key={item.name} />
              ))}
329
            </Tabs> */}
邓超's avatar
邓超 committed
330 331
          </div>
        </div>
邓超's avatar
邓超 committed
332 333 334 335 336 337 338 339 340 341
        <div
          className={styles.right}
          onClick={() => {
            showModal('order', true);
          }}
        >
          {/* <div className={styles.icon} /> */}
          <UnorderedListOutlined style={{ marginRight: '5px' }} />
          <div>流程排序</div>
        </div>
邓超's avatar
邓超 committed
342 343 344 345 346 347 348 349
      </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
350
            <PlusOutlined style={{ marginRight: '5px' }} /> 新增流程
邓超's avatar
邓超 committed
351 352 353 354 355 356 357 358 359 360
          </div>
          <Search
            placeholder="输入关键字搜索"
            allowClear
            onSearch={onSearch}
            style={{
              width: 490,
            }}
          />
        </div>
361 362 363 364 365 366 367 368 369 370 371 372
        <div className={styles.showPDF}>
        <Tooltip title="点击查看对接文档">
            <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
373 374 375
      </div>
      <div className={styles.flowTable}>
        {currentList.map((item, index) => (
376
          <div className={styles.flowGroup} key={item.name} id={item.name}>
邓超's avatar
邓超 committed
377 378 379 380 381
            <div
              className={styles.header}
              style={{ display: item.children.length > 0 ? 'flex' : 'none' }}
            >
              <div className={styles.line} />
邓超's avatar
邓超 committed
382 383 384 385 386 387 388
              <div className={styles.name} onClick={() => eiditFlowGroup(item, index)}>
                {item.name}
              </div>
              <EditOutlined
                style={{ marginLeft: '5px' }}
                onClick={() => eiditFlowGroup(item, index)}
              />
邓超's avatar
邓超 committed
389 390
            </div>
            <div className={styles.groupBox}>
391 392 393 394 395 396 397 398
              {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
399 400
                  <div className={styles.header}>
                    <div className={styles.title}>{ele.FlowName}</div>
401

邓超's avatar
邓超 committed
402 403
                    <div className={styles.editBtn} onClick={e => editFlow(ele, e)}>
                      <EditOutlined />
404
                      修改
邓超's avatar
邓超 committed
405 406 407
                    </div>
                  </div>
                  <div className={styles.imgBox}>
408 409 410 411 412 413 414 415 416 417
                    <div
                      className={classnames(styles.mask, {
                        [styles.maskHover]: JSON.stringify([index, num]) === hoverIndex,
                      })}
                    />
                    <div
                      className={classnames(styles.buttonBox, {
                        [styles.buttonHover]: JSON.stringify([index, num]) === hoverIndex,
                      })}
                    >
418
                      <div className={styles.lookDetail}>
419 420 421 422 423
                        <Button
                          type="primary"
                          onClick={() => chooseNode(ele)}
                          style={{ background: '#3D78FF', color: '#fff', opacity: 1 }}
                        >
424 425 426 427 428 429 430
                          设计
                        </Button>

                        {/* <HighlightOutlined onClick={e => chooseNode(ele, e)} /> */}
                      </div>
                      <div className={styles.delete}>
                        <Button
431 432 433 434 435 436
                          style={{
                            background: '#fff',
                            border: '1px solid #FF4D4F',
                            color: '#FF4D4F',
                            opacity: 1,
                          }}
437 438 439 440 441 442 443 444
                          type="primary"
                          onClick={e => delFlow(ele, e)}
                        >
                          删除
                        </Button>
                        {/* <DeleteOutlined onClick={e => delFlow(ele, e)} /> */}
                      </div>
                    </div>
邓超's avatar
邓超 committed
445
                    <img
邓超's avatar
邓超 committed
446 447 448
                      src={`${
                        window.location.origin
                      }/PandaOMS/OMS/FileCenter/DownLoadFiles?filePath=${ele.PreviewImage}`}
邓超's avatar
邓超 committed
449 450 451 452
                      alt=""
                    />
                  </div>
                  <div className={styles.bottom}>
邓超's avatar
邓超 committed
453
                    <div className={styles.left}>{ele.CreateUser || ''}</div>
邓超's avatar
邓超 committed
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
                    <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}
470 471
        onSubumit={val => {
          activeKey.current = val;
邓超's avatar
邓超 committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485
          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
486 487 488 489 490 491 492 493 494 495 496
      {/* 排序弹窗 */}
      <Order
        visible={visible.order}
        processData={flowList}
        handleCancel={() => showModal('order', false)}
        submitCallBack={() => {
          // activeKey.current = currentList[0];
          showModal('order', false);
          getFlowList();
        }}
      />
邓超's avatar
邓超 committed
497 498 499 500 501
    </div>
  );
};

export default WorkflowHomePage;