import React, { Component } from 'react';
import { Table } from 'amos-antd';
import { getForwardList } from './../../../../services/pamsTableService';


class ForwardTable extends Component {
  constructor(props) {
    super(props);
    this.state = {
      totalPage: 0,
      total: 0,
      current: 1,
      pageSize: 5,
      fwordList: []
    };
  }

  componentDidMount() {
    this.querryData();
  }

  /**
   * 获取端口数据
   */
  querryData() {
    getForwardList('/src/_mock/pamsTable/index.json', fwordList => {
      this.setState({ fwordList });
    });
  }

  /**
   *
   *设置共多少页
   */
  showTotal = (total) => {
    return `共 ${( total % this.state.pageSize) ===0 ? Math.floor((total / this.state.pageSize)) : Math.floor((( total / this.state.pageSize) + 1))} 页`;
  }

  /**
   * 设置当前页事件
   */
  onPaginationChange = (current) => {
    this.setState({ current },this.reload);
  }

  rendColumns = () => {
    return [
      {
        title: '序号',
        dataIndex: 'rownum',
        key: 'rownum',
        width: '2%'
      },
      {
        title: '设备名称',
        dataIndex: 'equipName',
        key: 'equipName',
        width: '5%'
      },
      {
        title: '交换机IP',
        dataIndex: 'switchIP',
        key: 'switchIP',
        width: '5%'
      },
      {
        title: 'MAC',
        dataIndex: 'mac',
        key: 'mac',
        width: '5%'
      },
      {
        title: '端口',
        dataIndex: 'port',
        key: 'port',
        width: '5%'
      }
    ];
  };

  render() {
    const {fwordList } = this.state;
    let tepmPage = Object.assign({
      size: 'small',
      total: this.state.totals,
      current: this.state.current,
      pageSize: this.state.pageSize,
      //onShowSizeChange: this.onSizeChange,
      onChange: this.onPaginationChange,
      showSizeChanger: 'true',
      pageSizeOptions: [5],
      showTotal: this.showTotal
    },  false);
    return (
      <div style={{width: '45%',height: '100%',marginLeft: '28px'}}>
        <Table
          pagination={tepmPage}
          columns={this.rendColumns()}
          dataSource={fwordList} />
      </div>
    );
  }
}

export default ForwardTable;
