import {
	observable,
	action,
} from 'mobx';
import {
	WeaTableNew
} from 'comsMobx';
const {
	TableStore
} = WeaTableNew;

export default class TableListStore {
	constructor(api, rootStore) {
		this.api = api;
		this.rootStore = rootStore;
	}

	get tableProps() {
		return {
			hasOrder: true,
			needScroll: true,
			getColumns: columns => this.reRenderColumns(columns),
			onOperatesClick: (record, rowIndex, operate) => this.onOperatesClick(record, rowIndex, operate)
		}
	}

	@observable tableStore = new TableStore();

	@action fetchTableList = (params = {}) => {
		this.api.fetchTableList(params).then(datas => {
			const {
				sessionkey,
			} = datas;

			this.tableStore = new TableStore();
			this.tableStore.getDatas(sessionkey, 1);
		})
	}

	reRenderColumns = (columns) => {
		this.rootStore.reRenderColumns && this.rootStore.reRenderColumns(columns);
	}

	onOperatesClick = (record, rowIndex, operate) => {
		this.rootStore.onOperatesClick && this.rootStore.onOperatesClick(record, rowIndex, operate);
	}
}