/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-01-13 10:47:32
 * @LastEditTime: 2022-03-31 17:37:04
 * @LastEditors: leizhe
 */
/* eslint-disable array-callback-return */
/* eslint-disable no-plusplus */
import React, { useState, useEffect } from 'react';
import { Modal } from 'antd';

import Sortable from 'sortablejs';
import styles from './incident.less';
import DragTable from '@/components/DragTable/DragTable';
const SortModal = props => {
  const { callBackSubmit = () => {}, title, visible, onCancel, sortData1 } = props;
  const [orderTable, setOrderTable] = useState([]);
  const [flowIDs, setFlowIDs] = useState([]);

  const onSumbit = () => {
    console.log(flowIDs);
    callBackSubmit({ str: flowIDs });
  };

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

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

  // 拖拽回调函数
  const dragCallBack = data => {
    console.log(data);
    if (data) {
      setOrderTable(data);
    }
  };
  const columns = [
    {
      title: '字段名',
      dataIndex: 'name',
      width: 150,
      key: 'name',
    },
  ];
  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}>
          {/* <table style={{ width: '104%', marginLeft: '-5px' }}>
            <thead>
              <tr>
                <td>事件名称</td>
              </tr>
            </thead>
            <tbody id="doctor-drag-items">
              {sortData1.map((item, index) => (
                <tr drag-id={item.ID} key={item.ID} style={{ cursor: 'move' }}>
                  <td>
                    <span title={item.name}>{item.name}</span>
                  </td>
                </tr>
              ))}
            </tbody>
          </table> */}
          <DragTable
            bordered
            style={{ marginBottom: '10px' }}
            rowKey={record => record.extendID}
            columns={columns}
            dataSource={orderTable}
            showHeader={false}
            pagination={false}
            size="small"
            dragCallBack={dragCallBack}
            ItemTypes="flowOrder"
          />
        </div>
      </div>
    </Modal>
  );
};
export default SortModal;
