import {
  message
} from 'antd'

import {
  WeaTableNew
} from 'comsMobx';

import {
  i18n
} from '../../public/i18n';

const WeaTable = WeaTableNew.WeaTable;

export default class AreaTable extends React.Component {
  constructor(props) {
    super(props);
  }

  onOperatesClick(record, index, operate) {
    const {
      getEditForm,
      deleteRows,
      seal,
      unseal,
      type,
    } = this.props;

    let i = operate.index;
    let id = record.id || record.randomFieldId;

    i == '0' && getEditForm(id);
    i == '1' && deleteRows(id);
    i == '2' && seal(id);
    i == '3' && unseal(id);
    i == '4' && window.setLogViewProps({
      logSmallType: (type == 'all') ? '3006' : (type == 'country') ? '3007' : (type == 'province') ? '3008' : '3009',
      targetId: id,
    });;
  }

  reRenderColumns(columns) {
    const {
      tdClick,
      type
    } = this.props;
    let _this = this;

    columns.forEach((c, index) => {
      if (c.dataIndex == 'countryname' && type == 'all') { //点击'国家简称'
        c.render = function(text, record) {
          let params = {
            indexTo: 'country',
            id: record.id
          }
          return <a onClick={() => tdClick(params)} >{record.countryname}<span style={{color: '#FF0000'}}>{record.countrynamespan.indexOf('已封存') > -1 ? '(已封存)' : ''}</span></a>
        }
      }
      if (c.dataIndex == 'result' && type == 'all') { //点击'省份数量'
        c.render = function(text, record) {
          let params = {
            indexTo: 'country',
            id: record.id,
            isTabSwitch: true
          }
          return <a onClick={() => tdClick(params)} >{record.result}</a>
        }
      }
      if (c.dataIndex == 'provincename' && type == 'country') { //点击'省份简称'
        c.render = function(text, record) {
          let params = {
            indexTo: 'province',
            id: record.id
          }
          return <a onClick={() => tdClick(params) }>{record.provincename}<span style={{color: '#FF0000'}}>{record.provincenamespan.indexOf('已封存') > -1 ? '(已封存)' : ''}</span></a>
        }
      }
      if (c.dataIndex == 'result' && type == 'country') { //点击'省份数量'
        c.render = function(text, record) {
          let params = {
            indexTo: 'province',
            id: record.id,
            isTabSwitch: true
          }
          return <a onClick={() => tdClick(params)} >{record.result}</a>
        }
      }
      if (c.dataIndex == 'cityname' && type == 'province') { //点击'城市简称'
        c.render = function(text, record) {
          let params = {
            indexTo: 'city',
            id: record.id
          }
          return <a onClick={() => tdClick(params)} >{record.cityname}<span style={{color: '#FF0000'}}>{record.citynamespan.indexOf('已封存') > -1 ? '(已封存)' : ''}</span></a>
        }
      }
      if (c.dataIndex == 'result1' && type == 'province') { //点击'城市数量'
        c.render = function(text, record) {
          let params = {
            indexTo: 'city',
            id: record.id,
            isTabSwitch: true
          }
          return <a onClick={() => tdClick(params)} >{record.result1}</a>
        }
      }
      if (c.dataIndex == 'citytwoname' && type == 'city') { //点击'区县简称'
        c.render = function(text, record) {
          let params = {
            indexTo: 'citytwo',
            id: record.id
          }
          return <a onClick={() => tdClick(params)} >{record.citytwoname}<span style={{color: '#FF0000'}}>{record.citytwonamespan.indexOf('已封存') > -1 ? '(已封存)' : ''}</span></a>
        }
      }
    })
  }

  render() {
    const {
      tableStore
    } = this.props;

    return (
      <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@yt4uyl`} 
          comsWeaTableStore={tableStore}
          hasOrder={true}
          needScroll={true}
          getColumns={c => this.reRenderColumns(c)}
          onOperatesClick={(record, index, operate) => this.onOperatesClick(record, index, operate)}
      />
    )
  }
}