import {
	observable,
	action,
} from 'mobx';
import {
	WeaTableNew
} from 'comsMobx';
import {
	WeaLocaleProvider,
} from 'ecCom';
import {
	Modal,
} from 'antd';
const {
	TableStore
} = WeaTableNew;
const getLabel = WeaLocaleProvider.getLabel;
const confirm = Modal.confirm;

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

	get tableProps() {
		return {
			hasOrder: true,
			needScroll: true,
		}
	}

	@observable tableStore = new TableStore();

	@action fetchTableList = (params = {}) => {
		this.api(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);
	}

	colSet = () => {
		this.tableStore.setColSetVisible(true);
		this.tableStore.tableColSet(true)
	}

	showConfirm = (msg) => {
		return new Promise((resolve, reject) => {
			confirm({
				title: getLabel('131329', '信息确认'),
				content: msg,
				okText: getLabel('33703', '确定'),
				cancelText: getLabel('32694', '取消'),
				onOk() {
					resolve();
				},
				onCancel() {
					return false;
				},
			});
		})
	}

	showLog = (type, id) => {
		const params = {
			logSmallType: type,
		};
		if (id) {
			Object.assign(params, {
				targetId: id,
			});
		}
		window.setLogViewProps(params);
	}

	exportExcel = () => {
		this.tableStore.exportAll();
	}
}