Timelimit.jsx 5.53 KB
Newer Older
邓超's avatar
邓超 committed
1
import React, { useEffect, useState } from 'react';
2
import { reloadFlowTimers, removeFlowTimer, reloadFlowNodes } from '@/services/flow/flow';
邓超's avatar
邓超 committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import {
  Table,
  Modal,
  Space,
  Tooltip,
  Popconfirm,
  Button,
  notification,
  message,
  Spin,
} from 'antd';
import { EditTwoTone, PlusOutlined, DeleteOutlined } from '@ant-design/icons';
import AddModal from './timelimitComponents/AddModal';
import styles from '../flow.less';

const Timelimit = props => {
  const { handleCancel, visible, msg } = props;
  const [tableData, setTableData] = useState([]); // 回显的表格
  const [viewModal, setViewModal] = useState(false); // 编辑模态框
  const [modalType, setModalType] = useState(''); // 模态框是编辑还是修改的状态
  const [editMsg, setEditMsg] = useState({}); // 保存编辑的信息
  const [title, setTitle] = useState('');
25
  const [finishNodes, setFinishNodes] = useState([]);
邓超's avatar
邓超 committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  const [flowId, setFlowId] = useState('');
  const [loading, setLoading] = useState(false);
  useEffect(() => {
    if (visible) {
      console.log(msg);
      setFlowId(msg.ID);
      setTitle(`${msg.name}`);
      getData();
    }
  }, [visible]);
  // 数据初始化
  const getData = () => {
    setLoading(true);
    reloadFlowTimers({ flowName: msg.name }).then(res => {
      setLoading(false);
      if (res.code === 0) {
        setTableData(res.data);
43 44

        setFinishNodes(res.data.map(item => item.EndNode));
邓超's avatar
邓超 committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
      }
    });
  };
  // 编辑
  const toEdit = val => {
    setViewModal(true);
    setModalType('edit');
    setEditMsg(val);
  };
  // 删除
  const delRow = record => {
    removeFlowTimer({ flowTimerID: record.ID })
      .then(res => {
        if (res.code === 0) {
          getData();
          notification.success({
            message: '提示',
            duration: 3,
            description: '删除成功',
          });
        } else {
          notification.error({
            message: '提示',
            duration: 3,
            description: res.msg,
          });
        }
      })
      .catch(() => {
        notification.error({
          message: '提示',
          duration: 3,
          description: '网络异常',
        });
      });
  };

  // 定义表格
  const columns = [
    {
      title: '规则名称',
      dataIndex: 'Name',
      align: 'center',
    },
    {
      title: '开始节点',
      dataIndex: 'StartNode',
      align: 'center',
    },
    {
      title: '结束节点',
      dataIndex: 'EndNode',
      align: 'center',
    },
    {
      title: '默认时限',
      dataIndex: 'TimeLimit',
      align: 'center',
    },
    {
      title: '时限指派字段',
皮倩雯's avatar
皮倩雯 committed
106
      dataIndex: 'TimeLimitField',
邓超's avatar
邓超 committed
107 108
      align: 'center',
      render: text => (
109
        <span style={{ color: text === '(未配置)' ? 'grey' : '#0000009D' }}>{text}</span>
邓超's avatar
邓超 committed
110 111 112 113 114 115 116
      ),
    },
    {
      title: '超时记录字段',
      dataIndex: 'TimeoutField',
      align: 'center',
      render: text => (
117
        <span style={{ color: text === '(未配置)' ? 'grey' : '#0000009D' }}>{text}</span>
邓超's avatar
邓超 committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
      ),
    },
    {
      title: '操作',
      align: 'center',
      ellipsis: true,
      render: record => (
        <>
          <Space>
            <Tooltip title="修改流程时限配置">
              <EditTwoTone
                onClick={() => toEdit(record)}
                style={{ fontSize: '16px', color: '#1890FF' }}
              />
            </Tooltip>
            <Tooltip title="删除流程时限配置">
              <Popconfirm
                title="是否删除改流程时限配置?"
                onConfirm={() => delRow(record)}
                onCancel={() => message.error('取消清除')}
                okText="是"
                cancelText="否"
              >
141
                <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} />
邓超's avatar
邓超 committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
              </Popconfirm>
            </Tooltip>
          </Space>
        </>
      ),
    },
  ];
  return (
    <Modal
      title={`${title}-流程时限配置`}
      visible={visible}
      width="1200px"
      onCancel={handleCancel}
      maskClosable={false}
      centered
      footer={null}
      destroyOnClose
    >
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
      <div className={styles.timelimitBox}>
        <div className={styles.buttonList}>
          <Button
            type="primary"
            onClick={() => {
              setViewModal(true);
              setModalType('add');
            }}
            icon={<PlusOutlined />}
          >
            新增流程时限配置
          </Button>
        </div>
        <Spin spinning={loading} tip="loading...">
          <Table
            dataSource={tableData}
            columns={columns}
            rowKey={record => record.ID}
            bordered
            size="small"
            scroll={{ y: '400px' }}
            onRow={record => ({
              onDoubleClick: () => {
                toEdit(record);
              },
            })}
            pagination={{
              showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`,
              pageSizeOptions: [10, 20, 50, 100],
              defaultPageSize: 10,
              showQuickJumper: true,
              showSizeChanger: true,
            }}
          />
        </Spin>
邓超's avatar
邓超 committed
195 196 197 198 199 200 201 202
      </div>

      <AddModal
        visible={viewModal}
        msg={editMsg}
        title={title}
        flowId={flowId}
        modalType={modalType}
203
        finishNodes={finishNodes}
邓超's avatar
邓超 committed
204 205 206 207 208 209 210 211 212 213
        handleCancel={() => setViewModal(false)}
        onSubumit={() => {
          setViewModal(false);
          getData();
        }}
      />
    </Modal>
  );
};
export default Timelimit;