patrolFeedback.jsx 14.1 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2
/* eslint-disable react-hooks/rules-of-hooks */
/* eslint-disable camelcase */
3
import React, { useState, useEffect } from 'react';
4
import { Space, Table, Popconfirm, Tooltip, Button, notification, Spin, Card } from 'antd';
5
import {
皮倩雯's avatar
皮倩雯 committed
6 7 8
  CM_Feedback_LoadPatrolFeedbacks,
  CM_Feedback_RemovePatrolFeedback,
} from '@/services/PatrolFeedback/api';
9 10 11 12 13 14 15 16 17
import {
  EditTwoTone,
  DeleteOutlined,
  PlusOutlined,
  OrderedListOutlined,
  DoubleLeftOutlined,
  DoubleRightOutlined,
} from '@ant-design/icons';
import classnames from 'classnames';
皮倩雯's avatar
皮倩雯 committed
18
import styles from './patrolFeedback.less';
皮倩雯's avatar
皮倩雯 committed
19
import AddModal from './AddModal';
20
import SortModal from './SortModal';
皮倩雯's avatar
皮倩雯 committed
21
import DragTable from '@/components/DragTable/DragTable';
22

皮倩雯's avatar
皮倩雯 committed
23
const patrolFeedback = () => {
皮倩雯's avatar
皮倩雯 committed
24 25 26 27 28 29
  const [addVisible, setAddVisible] = useState(false);
  const [type, setType] = useState('');
  const [formObj, setFormObj] = useState('');
  const [treeLoading, setTreeLoading] = useState(false);
  const [flag, setFlag] = useState(0);
  const [tableData, setTableData] = useState([]);
皮倩雯's avatar
皮倩雯 committed
30
  const [keepTableData, setKeepTableData] = useState([]);
皮倩雯's avatar
皮倩雯 committed
31 32
  const [sortVisible, setSortVisible] = useState(false);
  const [selectedRowKeys, setSelectedRowKeys] = useState([]); // 已选用户数,机构改变时重置
33 34 35 36
  const [groupName, setGroupName] = useState(['区域巡检', 'DMA巡检']);
  const [treeVisible, setTreeVisible] = useState(true); // 左边列表是否可见
  const [pickItem, setPickItem] = useState('区域巡检');
  const [hoverItemIndex, setHoverItemIndex] = useState('');
37

皮倩雯's avatar
皮倩雯 committed
38 39
  const columns = [
    {
皮倩雯's avatar
皮倩雯 committed
40 41 42
      title: '巡检对象',
      dataIndex: 'layerName',
      key: 'layerName',
43 44 45 46 47 48 49 50 51 52
      width: 150,
      onCell: () => ({
        style: {
          maxWidth: 150,
          overflow: 'hidden',
          whiteSpace: 'nowrap',
          textOverflow: 'ellipsis',
          cursor: 'pointer',
        },
      }),
皮倩雯's avatar
皮倩雯 committed
53
      align: 'center',
54 55 56 57 58
      render: record => (
        <Tooltip placement="topLeft" title={record}>
          {record}
        </Tooltip>
      ),
皮倩雯's avatar
皮倩雯 committed
59
    },
60 61 62 63 64 65
    {
      title: '分组',
      dataIndex: 'groupType',
      key: 'groupType',
      align: 'center',
    },
皮倩雯's avatar
皮倩雯 committed
66
    {
皮倩雯's avatar
皮倩雯 committed
67 68 69
      title: 'GIS图层',
      dataIndex: 'gisLayer',
      key: 'gisLayer',
70 71 72 73 74 75 76 77 78 79
      width: 100,
      onCell: () => ({
        style: {
          maxWidth: 100,
          overflow: 'hidden',
          whiteSpace: 'nowrap',
          textOverflow: 'ellipsis',
          cursor: 'pointer',
        },
      }),
皮倩雯's avatar
皮倩雯 committed
80
      align: 'center',
81 82 83 84 85
      render: record => (
        <Tooltip placement="topLeft" title={record}>
          {record}
        </Tooltip>
      ),
皮倩雯's avatar
皮倩雯 committed
86 87
    },
    {
皮倩雯's avatar
皮倩雯 committed
88 89 90
      title: 'GIS条件',
      dataIndex: 'gisFilterValue',
      key: 'gisFilterValue',
91 92 93 94 95 96 97 98 99 100
      width: 100,
      onCell: () => ({
        style: {
          maxWidth: 100,
          overflow: 'hidden',
          whiteSpace: 'nowrap',
          textOverflow: 'ellipsis',
          cursor: 'pointer',
        },
      }),
皮倩雯's avatar
皮倩雯 committed
101
      align: 'center',
102 103 104 105 106
      render: record => (
        <Tooltip placement="topLeft" title={record}>
          {record}
        </Tooltip>
      ),
皮倩雯's avatar
皮倩雯 committed
107 108
    },
    {
皮倩雯's avatar
皮倩雯 committed
109 110 111
      title: '反馈表',
      dataIndex: 'tableName',
      key: 'tableName',
112
      width: 200,
皮倩雯's avatar
皮倩雯 committed
113 114
      onCell: () => ({
        style: {
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
          maxWidth: 200,
          overflow: 'hidden',
          whiteSpace: 'nowrap',
          textOverflow: 'ellipsis',
          cursor: 'pointer',
        },
      }),
      align: 'center',
      render: record => (
        <Tooltip placement="topLeft" title={record}>
          {record}
        </Tooltip>
      ),
    },
    {
130
      title: '关联事件',
131 132 133 134 135 136
      dataIndex: 'relationEvent',
      key: 'relationEvent',
      width: 200,
      onCell: () => ({
        style: {
          maxWidth: 200,
皮倩雯's avatar
皮倩雯 committed
137 138 139 140 141 142
          overflow: 'hidden',
          whiteSpace: 'nowrap',
          textOverflow: 'ellipsis',
          cursor: 'pointer',
        },
      }),
皮倩雯's avatar
皮倩雯 committed
143
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
144 145 146 147 148
      render: record => (
        <Tooltip placement="topLeft" title={record}>
          {record}
        </Tooltip>
      ),
皮倩雯's avatar
皮倩雯 committed
149 150
    },
    {
皮倩雯's avatar
皮倩雯 committed
151 152 153
      title: '字段集',
      dataIndex: 'fields',
      key: 'fields',
154
      width: 80,
155
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
156
    },
皮倩雯's avatar
皮倩雯 committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170
    // {
    //   title: '异常值',
    //   dataIndex: 'exceptionValue',
    //   key: 'exceptionValue',
    //   width: 150,
    //   align: 'center',
    // },
    // {
    //   title: '触发事件',
    //   dataIndex: 'eventName',
    //   key: 'eventName',
    //   width: 150,
    //   align: 'center',
    // },
皮倩雯's avatar
皮倩雯 committed
171
    {
皮倩雯's avatar
皮倩雯 committed
172 173 174
      title: '权限',
      dataIndex: 'roles',
      key: 'roles',
皮倩雯's avatar
皮倩雯 committed
175
      align: 'center',
176
      width: 50,
皮倩雯's avatar
皮倩雯 committed
177
    },
皮倩雯's avatar
皮倩雯 committed
178 179 180 181 182 183
    // {
    //   title: '分组',
    //   dataIndex: 'groupType',
    //   key: 'groupType',
    //   align: 'center',
    // },
皮倩雯's avatar
皮倩雯 committed
184 185 186 187 188 189 190 191
    {
      title: '操作',
      ellipsis: true,
      key: 'action',
      align: 'center',
      render: (text, record) => (
        <Space>
          <Tooltip title="修改">
皮倩雯's avatar
皮倩雯 committed
192
            <EditTwoTone onClick={() => editEventType(record)} style={{ fontSize: '16px' }} />
皮倩雯's avatar
皮倩雯 committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
          </Tooltip>
          <Tooltip title="删除">
            <Popconfirm
              placement="bottomRight"
              title={<p>是否确认删除?</p>}
              okText="确认"
              cancelText="取消"
              onConfirm={() => deleteEventType(record)}
            >
              <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} />
            </Popconfirm>
          </Tooltip>
        </Space>
      ),
    },
  ];
209

皮倩雯's avatar
皮倩雯 committed
210 211
  useEffect(() => {
    setTreeLoading(true);
皮倩雯's avatar
皮倩雯 committed
212
    CM_Feedback_LoadPatrolFeedbacks({ pageIndex: 0, pageSize: 0 }).then(res => {
皮倩雯's avatar
皮倩雯 committed
213
      setTreeLoading(false);
皮倩雯's avatar
皮倩雯 committed
214 215
      if (res.code === 0) {
        console.log(res.data.list);
216 217 218 219 220 221 222 223 224 225
        let data = {};
        if (res.data.list.length > 0) {
          let area = [];
          let dma = [];
          let other = [];
          res.data.list.map(i => {
            if (i.businessGroup === '区域巡检') {
              area.push(i);
            } else if (i.businessGroup === 'DMA巡检') {
              dma.push(i);
226 227 228 229 230 231
            } else if (
              i.businessGroup === '区域巡检,DMA巡检' ||
              i.businessGroup === 'DMA巡检,区域巡检'
            ) {
              area.push(i);
              dma.push(i);
232 233 234 235 236 237 238
            } else {
              other.push(i);
            }
          });
          data.区域巡检 = area;
          data.DMA巡检 = dma;
          if (other.length > 0) {
239
            data.未分组 = other;
240
            setGroupName(['区域巡检', 'DMA巡检', '未分组']);
241 242
          } else {
            setGroupName(['区域巡检', 'DMA巡检']);
243 244 245 246 247 248
          }
        }
        console.log(data);
        console.log(data['区域巡检']);
        console.log(data.区域巡检);
        setTableData(data);
皮倩雯's avatar
皮倩雯 committed
249
        let list = [];
皮倩雯's avatar
皮倩雯 committed
250 251
        res.data.list.map(i => {
          list.push(i.layerName);
皮倩雯's avatar
皮倩雯 committed
252 253
        });
        setKeepTableData(list);
皮倩雯's avatar
皮倩雯 committed
254 255 256
      }
    });
  }, [flag]);
皮倩雯's avatar
皮倩雯 committed
257

皮倩雯's avatar
皮倩雯 committed
258 259 260 261 262 263 264 265 266 267
  const add = () => {
    setAddVisible(true);
    setType('add');
  };
  const editEventType = record => {
    setAddVisible(true);
    setType('edit');
    setFormObj(record);
  };
  const deleteEventType = record => {
皮倩雯's avatar
皮倩雯 committed
268 269
    CM_Feedback_RemovePatrolFeedback(record.id).then(res => {
      if (res.code === 0) {
皮倩雯's avatar
皮倩雯 committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
        notification.success({
          message: '提示',
          duration: 3,
          description: '删除成功',
        });
        setFlag(flag + 1);
      } else {
        notification.error({
          message: '提示',
          duration: 3,
          description: res.msg,
        });
      }
    });
  };
  const onSubmit = () => {
    setAddVisible(false);
    setFlag(flag + 1);
  };
289

皮倩雯's avatar
皮倩雯 committed
290 291 292 293
  const onOK = () => {
    setFlag(flag + 1);
  };

294 295 296 297
  const sort = () => {
    setSortVisible(true);
  };

皮倩雯's avatar
皮倩雯 committed
298 299 300 301 302 303 304 305 306 307 308 309
  // 复选框
  const rowSelection = {
    selectedRowKeys,
    onChange: (RowKeys, Rows) => {
      setSelectedRowKeys(RowKeys);
    },
  };

  const hasSelected = selectedRowKeys.length > 0;

  const de = () => {
    CM_Feedback_RemovePatrolFeedback(selectedRowKeys.toString()).then(res => {
310 311 312 313
      if (res.code === 0) {
        notification.success({
          message: '提示',
          duration: 3,
皮倩雯's avatar
皮倩雯 committed
314
          description: '批量删除成功',
315
        });
皮倩雯's avatar
皮倩雯 committed
316
        setSelectedRowKeys([]);
317 318 319 320 321 322 323 324 325 326
        setFlag(flag + 1);
      } else {
        notification.error({
          message: '提示',
          duration: 3,
          description: res.msg,
        });
      }
    });
  };
皮倩雯's avatar
皮倩雯 committed
327 328 329 330 331
  const dragCallBack = value => {
    if (value) {
      console.log(value);
    }
  };
332

皮倩雯's avatar
皮倩雯 committed
333
  return (
皮倩雯's avatar
皮倩雯 committed
334
    <div className={styles.PatrolFeedbackContainer}>
皮倩雯's avatar
皮倩雯 committed
335
      <div className={styles.contentContainers}>
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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
        {/* 左侧事件树 */}
        <Spin spinning={treeLoading} tip="loading...">
          <Card
            className={classnames({
              [styles.orgContainer]: true,
              [styles.orgContainerHide]: !treeVisible,
            })}
          >
            <div style={{ height: '100%', display: treeVisible ? 'block' : 'none' }}>
              <span
                style={{
                  fontSize: '15px ',
                  fontWeight: 'bold',
                }}
              >
                业务划分
              </span>
              <hr style={{ width: '100%', color: '#eeecec' }} />
              <div
                style={{
                  height: 'calc(100% - 60px)',
                  overflowY: 'scroll',
                }}
              >
                {groupName.length > 0 &&
                  groupName.map((item, index) => (
                    <div
                      className={classnames({
                        [styles.listItem]: true,
                        [styles.pickItem]: item === pickItem,
                        [styles.listHover]: item !== pickItem && item === hoverItemIndex,
                      })}
                      onClick={e => {
                        setPickItem(item);
                      }}
                      onMouseEnter={() => {
                        setHoverItemIndex(item);
                      }}
                      onMouseLeave={() => {
                        setHoverItemIndex('');
                      }}
                      key={index}
                    >
                      <div
                        style={{
                          width: '130px',
                          overflow: 'hidden',
                          whiteSpace: 'nowrap',
                          textOverflow: 'ellipsis',
                        }}
                      >
                        <Tooltip placement="top" title={item}>
                          {item}
                        </Tooltip>
                      </div>
{tableData[item] ? tableData[item].length : ''}
                    </div>
                  ))}
              </div>
            </div>
            <div className={styles.switcher}>
              {treeVisible && (
                <Tooltip title="隐藏业务划分列表">
                  <DoubleLeftOutlined onClick={() => setTreeVisible(false)} />
                </Tooltip>
              )}
              {!treeVisible && (
                <Tooltip title="显示业务划分列表">
                  <DoubleRightOutlined onClick={() => setTreeVisible(true)} />
                </Tooltip>
              )}
            </div>
          </Card>
        </Spin>
        {/* 右侧 */}
        <div
          className={classnames({
            [styles.userContainer]: true,
            [styles.userContainerHide]: !treeVisible,
皮倩雯's avatar
皮倩雯 committed
415
          })}
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
        >
          <div style={{ height: '50px', backgroundColor: 'white' }}>
            <span style={{ float: 'right', marginRight: '10px' }}>
              <Button
                icon={<PlusOutlined className={styles.icon} />}
                onClick={add}
                type="primary"
                style={{
                  verticalAlign: 'middle',
                  marginTop: '10px',
                }}
              >
                <span style={{ marginTop: '-2px' }}>新增</span>
              </Button>
              <Button
                icon={<OrderedListOutlined className={styles.icon} />}
                onClick={sort}
                style={{
                  verticalAlign: 'middle',
                  marginTop: '10px',
                }}
              >
                <span style={{ marginTop: '-2px' }}>调序</span>
              </Button>
              <Button
                icon={<DeleteOutlined className={styles.icon} />}
                style={{
                  verticalAlign: 'middle',
                  marginTop: '10px',
                }}
                onClick={de}
                disabled={!hasSelected}
              >
                <span style={{ marginTop: '-2px' }}>批量删除</span>
              </Button>
            </span>
          </div>
          <Table
            // rowClassName={setRowClassName}
            rowSelection={{
              type: 'checkbox',
              ...rowSelection,
            }}
            size="small"
            rowKey={record => record.id}
            bordered
            loading={treeLoading}
            onRow={record => ({
              onDoubleClick: event => {
                event.stopPropagation();
                editEventType(record);
              }, // 双击
            })}
            columns={columns}
            dataSource={tableData[pickItem]}
            scroll={{ y: 'calc(100% - 205px)', x: 'max-content' }}
            pagination={{
              showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`,
              pageSizeOptions: [10, 20, 50, 100],
              defaultPageSize: 20,
              showQuickJumper: true,
              showSizeChanger: true,
            }}
          />
        </div>
皮倩雯's avatar
皮倩雯 committed
481 482 483 484 485 486 487
        {/* 添加事件 */}
        <AddModal
          visible={addVisible}
          type={type}
          onClose={() => setAddVisible(false)}
          callBackSubmit={onSubmit}
          formObj={formObj}
皮倩雯's avatar
皮倩雯 committed
488
          keepTableData={keepTableData}
皮倩雯's avatar
皮倩雯 committed
489 490
          placement="right"
        />
491 492 493
        <SortModal
          title="调整顺序"
          visible={sortVisible}
494
          sortData={tableData[pickItem]}
495 496 497
          onCancel={() => setSortVisible(false)}
          callBackSubmit={onOK}
        />
皮倩雯's avatar
皮倩雯 committed
498 499 500
      </div>
    </div>
  );
501 502
};

皮倩雯's avatar
皮倩雯 committed
503
export default patrolFeedback;