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,
      type,
    } = this.props;

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

    i == '0' && getEditForm(id);
    i == '1' && deleteRows(id);
    i == '2' && window.setLogViewProps({
      logSmallType: (type == 'all') ? '3012' : (type == 'JobGroup') ? '3013' : '3014',
      targetId: id,
    });
  }

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

    const linkStyle = {
      cursor: 'pointer',
      color: '#4D7AD8'
    };

    columns.forEach((c, index) => {
      if (c.dataIndex == 'jobgroupremark' && type == 'all') { //点击'类别简称'
        c.render = function(text, record) {
          let params = {
            indexTo: 'JobGroup',
            id: record.randomFieldId
          }
          return <a onClick={() => tdClick(params)} >{record.jobgroupremark}</a>
        }
      }
      if (c.dataIndex == 'result' && type == 'all') { //点击'职务数量'
        c.render = function(text, record) {
          let params = {
            indexTo: 'JobGroup',
            id: record.randomFieldId,
            isTabSwitch: true
          }
          return <a onClick={() => tdClick(params)} >{record.result}</a>
        }
      }
      if (c.dataIndex == 'jobactivitymark' && type == 'JobGroup') { //点击'职务简称'
        c.render = function(text, record) {
          let params = {
            indexTo: 'JobActivity',
            id: record.randomFieldId
          }
          return <a onClick={() => tdClick(params)} >{record.jobactivitymark}</a>
        }
      }
      if (c.dataIndex == 'jobtitlemark' && type == 'JobActivity') { //点击'岗位简称'
        c.render = function(text, record) {
          let params = {
            indexTo: 'JobTitle',
            id: record.randomFieldId
          }
          return <a onClick={() => tdClick(params)} >{record.jobtitlemark}</a>
        }
      }
    })
  }

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

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