import React, { Component } from 'react'
import {WeaTableNew} from 'comsMobx';
import {observer}  from 'mobx-react'
import {WeaLocaleProvider,WeaAlertPage} from 'ecCom'

const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class Table extends Component {
    reRenderColumns = (columns) => {
      const {newOutSide: store} = this.props;
        const {
          handleViewClick
        } = store;
    
        columns.map(c => {
          if (c.dataIndex === 'canViewSignImg') {
            c.render = function(text, record) {
              const {
                randomFieldId,
                canViewSignImgspan
              } = record;
              if (canViewSignImgspan === '1') {
                return <a onClick={() => handleViewClick(randomFieldId)}>{getLabel(33564,'查看')}</a>
              } else {
                return <span />
              }
            }
          }
        });
      }
    render() {
        const {newOutSide} = this.props;
        const {table,hasRight,hrmName} = newOutSide
        const errorMsg = getLabel('517102', "你无权查看该人员的外勤数据");

        return (
            <div>
                {
                    !hasRight ?  <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@qms402`}>
                    <div>{errorMsg}</div>
                    </WeaAlertPage>
                    :
                 <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@all7by`}
                    comsWeaTableStore={table}
                    hasOrder={true}
                    needScroll={true}
                    getColumns={this.reRenderColumns}
                />
              }
            </div>
        )
    }
}
