/*
 * @Author: PoJun
 * @Date: 2023-09-12 10:55:35
 * @LastEditors: PoJun
 * @LastEditTime: 2023-12-26 10:15:01
 * @Message: 也许可能会用到的一些公用方法
 */
import { getDictList } from "@/config/http.js";
module.exports = {
    data() {
        return {};
    },
    methods: {
        // 页面初始化需要的字典数据, 获取后存入vuex页面调用
        async initDictList(ids) {
            const ar = ids.split(",");
            const nAr = ar.filter(item => !this.vuex_dict[item]);
            if (nAr.length != 0) {
                const data = await getDictList({ params: { codes: ids } });
                for (const key in data) {
                    if (Object.hasOwnProperty.call(data, key)) {
                        this.$uv.vuex(`vuex_dict.${key}`, data[key]);
                    }
                }
            }
        },
        // 字典数据做key=>name的转换
        dictKeyToName(dict, key) {
            const data = this.vuex_dict[dict];
            if (!key || !data) {
                return key;
            }

            const ele = data.find(item => item.key == key);
            return ele?.name;
        },
    },
    computed: {},
};
