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

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

	get orgTreeProps() {
		return {
			needSearch: true,
			noCache: true,
			isLoadAllSub: true,
			inputLeftDom: `<b>${getLabel(25332, '组织结构')}</b>`,
			treeNodeClick: (event, ids, nodeids, nodes) => this.handleOrgTreeNodeClick(event, ids, nodeids, nodes)
		}
	}

	nodeInfo = {
		id,
		type,
		pid,
		name
	}

	@observable triggerRefresh = false;

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

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

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

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

}