import {
	observer,
	inject
} from 'mobx-react';
import {
	WeaTableNew
} from 'comsMobx';
import { WeaPopoverHrm } from 'ecCom';
import {
	jumpToHrmSubCompany,
	jumpToHrmDept,
	jumpToHrmPost,
} from '../../util/pure-util.js';
const WeaTable = WeaTableNew.WeaTable;

@inject('commonStore')
@observer
class Table extends React.Component {
	constructor(props) {
		super(props);
	}

	componentDidMount() {
		this.props.commonStore.getSearchList();
	}

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

		return (
			<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@6y5p5k`} 
				comsWeaTableStore={tableStore}
				bordered
				hasOrder
				needScroll
				pagination={tableStore.datas.length > 0}
				getColumns={columns => columns.map(c => {
					const dataIndex = c.dataIndex;
					if (["userId", "workcode"].includes(dataIndex)) {
						c.render = (text, record, index) => {
							const name = record[`${c.dataIndex}span`];
							
							return (
								<div>
		    						<WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@nxg0sh@${c.dataIndex}`} />
		    						<a href={`javaScript:openhrm(${record.userId})`} onClick={e => window.pointerXY(e)} title={name} >
		    							{name}
		    						</a>
		  						</div>
							)

						}
					}else if(dataIndex === "subcompanyId1"){
						c.render = (text, record, index) => {
							return <a onClick={() => jumpToHrmSubCompany(record.subcompanyId1)} target='_blank'>{record.subcompanyId1span}</a>
						}
					}else if(dataIndex === "departmentId"){
						c.render = (text, record, index) => {
							return <a onClick={() => jumpToHrmDept(record.departmentId)} target='_blank'>{record.departmentIdspan}</a>
						}
					}else if(dataIndex === "jobtitle"){
						c.render = (text, record, index) => {
							return<a onClick={() => jumpToHrmPost(record.jobtitle)} target='_blank'>{record.jobtitlespan}</a>
						}
					}
					return c;
				})}
			/>
		);
	}
}

export default Table