import {
	inject,
	observer,
} from 'mobx-react'
import {
	toJS
} from 'mobx';
import {
	WeaTableEditable,
	WeaLocaleProvider,
} from 'ecCom'
import {
	Spin
} from 'antd';
const getLabel = WeaLocaleProvider.getLabel

@inject('intelogin')
@observer
export default class SubTable extends React.Component {
	constructor(props) {
		super(props);
		this.columns = [{
			title: <span>{getLabel(21956,'对象类型')}</span>,
			dataIndex: 'type',
			width: '30%',
			com: [{
				type: 'INPUT',
				key: 'type',
				viewAttr: 1,
			}]
		}, {
			title: <span>{getLabel(106,'对象')}</span>,
			dataIndex: 'content',
			width: '30%',
			com: [{
				type: 'INPUT',
				key: 'content',
				viewAttr: 1,
			}]
		}, {
			title: <span>{getLabel(683,'安全级别')}</span>,
			dataIndex: 'seclevel',
			width: '40%',
			com: [{
				type: 'INPUT',
				key: 'seclevel',
				viewAttr: 1,
			}]
		}]
	}

	componentDidMount() {
		this.props.intelogin.getShareList();
	}

	componentWillUnmount() {
		this.props.intelogin.refreshShareList();
	}

	render() {
		const {
			intelogin,
		} = this.props, {
			subTable,
			setSelectedRowKeys,
		} = intelogin, {
			datas,
			loading,
		} = subTable;

		if (loading) {
			return (
				<div className='integration-loading-center-small'>
					<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@0pmr10`} spinning={loading}></Spin>
				</div>
			)
		} else {
			return (
				<WeaTableEditable ecId={`${this && this.props && this.props.ecId || ''}_WeaTableEditable@ff4ufy`} 
				 	columns={this.columns}
				 	datas={toJS(datas)}
				 	showTitle={false}
				 	onRowSelect={selectedRowKeys => setSelectedRowKeys(selectedRowKeys)}
				/>
			)
		}
	}
}