SortModal.jsx 2.57 KB
Newer Older
1 2 3 4
/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-01-13 10:47:32
皮倩雯's avatar
皮倩雯 committed
5
 * @LastEditTime: 2022-07-22 10:46:13
6 7 8 9 10
 * @LastEditors: leizhe
 */
/* eslint-disable array-callback-return */
/* eslint-disable no-plusplus */
import React, { useState, useEffect } from 'react';
皮倩雯's avatar
皮倩雯 committed
11 12 13
import { Modal, notification } from 'antd';
import { CM_Feedback_ChangPatrolOrder } from '@/services/PatrolFeedback/api';
import styles from './patrolFeedback.less';
14
import DragTable from '@/components/DragTable/DragTable';
皮倩雯's avatar
皮倩雯 committed
15

16 17 18 19 20 21 22
const SortModal = props => {
  const { callBackSubmit = () => {}, title, visible, onCancel, sortData } = props;
  const [orderTable, setOrderTable] = useState([]);
  const [flowIDs, setFlowIDs] = useState([]);

  const onSumbit = () => {
    console.log(flowIDs);
皮倩雯's avatar
皮倩雯 committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    CM_Feedback_ChangPatrolOrder(flowIDs.toString()).then(res => {
      if (res.code === 0) {
        callBackSubmit();
        onCancel();
        notification.success({
          message: '提示',
          duration: 3,
          description: '调整成功',
        });
      } else {
        notification.error({
          message: '提示',
          duration: 3,
          description: res.msg,
        });
      }
    });
    // callBackSubmit({ str: flowIDs });
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  };

  // 根据orderTable值改变flowIDs
  useEffect(() => {
    let ids = [];
    orderTable.map(item => {
      ids.push(item.id);
    });
    console.log(ids);
    setFlowIDs(ids);
  }, [orderTable]);

  useEffect(() => {
    console.log(sortData);
    if (visible) {
      setOrderTable(sortData);
    }
  }, [visible]);

  // 拖拽回调函数
  const dragCallBack = data => {
    console.log(data);
    if (data) {
      setOrderTable(data);
    }
  };
  const columns = [
    {
皮倩雯's avatar
皮倩雯 committed
69 70
      title: '巡检对象',
      dataIndex: 'layerName',
71
      width: 150,
皮倩雯's avatar
皮倩雯 committed
72
      key: 'layerName',
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 106
    },
  ];
  return (
    <Modal
      title={title}
      visible={visible}
      onCancel={onCancel}
      onOk={onSumbit}
      okText="确认"
      cancelText="取消"
    >
      <div
        className={styles.cardContent}
        style={{ width: '26rem', marginLeft: '24px', maxHeight: '400px', overflow: 'auto' }}
      >
        <div className={styles.doctorTable}>
          <DragTable
            bordered
            style={{ marginBottom: '10px' }}
            rowKey={record => record.id}
            columns={columns}
            dataSource={orderTable}
            showHeader={false}
            pagination={false}
            size="small"
            dragCallBack={dragCallBack}
            ItemTypes="flowOrder"
          />
        </div>
      </div>
    </Modal>
  );
};
export default SortModal;