/** 业务域转换 */
import { getBusinessTagTree } from "@/api/data-auth";
export default {
    data() {
        return {
            tagTree: []
        };
    },
    methods: {
        // 构建新的一级标签树
        setNewTagTree() {
            let newTagTree = [];
            for (let j = 0; j < this.tagTree.length; j++) {
                const item = this.tagTree[j];
                if (item.child && item.parent) {
                    newTagTree = [...newTagTree, ...item.child];
                }
            }
            return newTagTree;
        },
        // 转换业务域
        transferBusinessTag(policeBusiness) {
            if (policeBusiness) {
                let labelAttr = [];
                const pbAttr = policeBusiness.split(",");
                const newTagTree = this.setNewTagTree();
                for (let i = 0; i < pbAttr.length; i++) {
                    const pbItem = pbAttr[i];
                    const element = newTagTree.find(item => item.code == pbItem);
                    if (element) {
                        labelAttr.push(element.name);
                    }
                }
                return labelAttr.join("，");
            }
        },
        // 获取业务域标签树
        getTagTree() {
            return new Promise(resolve => {
                getBusinessTagTree().then(res => {
                    this.tagTree = res.data.content;
                    resolve(res);
                });
            });
        }
    },
    async created() {
        await this.getTagTree();
    }
};
