import {
	observable,
	action,
} from 'mobx';
import {
	WeaLocaleProvider,
} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

export default class OrgTreeStore {
	constructor(rootStore) {
		this.rootStore = rootStore;
	}

	get orgTreeProps() {
		const basicProps = {
			needSearch: true,
			noCache: true,
			isLoadAllSub: true,
			inputLeftDom: `<b>${getLabel(25332, '组织结构')}</b>`,
		};

		return Object.assign({}, basicProps, this.orgTreeMoreProps);
	}

	@observable triggerRefresh = false;

	@action trigger = () => {
		this.triggerRefresh = !this.triggerRefresh;
	}

	handleOrgTreeNodeClick = (event, ids, nodeids, nodes) => {
		this.splitNodeInfo(nodes);

		this.rootStore.handleOrgTreeNodeClick && this.rootStore.handleOrgTreeNodeClick();
	}

	splitNodeInfo = (nodes) => {
		['id', 'type', 'pid', 'name'].forEach(v => {
			this[v] = nodes[0][v];
		});
	}

	//config包括：orgTreeMoreProps
	setOrgTreeConfig=(config)=>{
		Object.keys(config).forEach(key => {
			this[key] = config[key];
		})
	}
}