



/*
 * @Author: your name
 * @Date: 2021-04-27 11:19:40
 * @LastEditTime: 2021-04-28 17:03:31
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /react-antd-admin-template/src/views/groupManage/groupIdentity/table.js
 */

import React from 'react';
import { Table,Popconfirm, Form} from 'antd';

class EditableTable extends React.Component {
  


  constructor(props) {
    super(props);
    this.state = { data:[], editingKey: '',loading:false};

    this.columns = [

      ...props.columns,
      {
        title: '操作',
        dataIndex: 'operation',
        render: (text, record) => {
          const { editingKey} = this.state;
        //   console.log({editingKey,record});
          return (
            <span>
            
                 <Popconfirm title=" 是否确定删除?" onConfirm={()=>this.delItem(record)}>
                    <a disabled={editingKey !== ''} >
                            删除
                    </a>
                 </Popconfirm>
             </span>
 
          );
        },
      },
    ];
  }



  componentDidMount(){
    this.setState({
        data:this.props.data
    });
    
  }

  componentDidUpdate(prevProps, prevState){
    // console.log({prevProps, prevState});
    if(prevProps.ifUpdateList){
        console.log('update');
        this.setState({
            data:this.props.data
        });
    }
  }

  isEditing = record => {
    //   console.log(record.id,this.state.editingKey);
      return record.id === this.state.editingKey;
  }
  
  editItem=(record)=>{
      this.props.callbackFromChild(record);
  }

  delItem=record=>{
      this.props.deleteCallback(record);
  }

  changePage(current){
    this.setState({ loading: true });
    this.props.paginationCallback({'currPage':current})
  }


  render() {
    
    const columns = this.columns.map(col => {
      if (!col.editable) {
        return col;
      }
      return {
        ...col,
        onCell: record => ({
          record,
        }),
      };
    });

    const {
        currPage,
        totalCount,
    } = this.props.pages;

    const paginationProps = {
        showSizeChanger: false,
        showQuickJumper: false,
        showTotal: () => `共${totalCount}条`,
        pageSize: 10,
        current: currPage,
        total: totalCount,
        onChange: (current) => this.changePage(current),
    }

    return (
        <Table
          bordered
          loading={this.state.loading}
          pagination={paginationProps}
          dataSource={this.state.data}
          columns={columns}
          rowClassName="editable-row"
        />
    );
  }
}

const EditableFormTable = Form.create()(EditableTable);


export default EditableFormTable;