ParameterSelect.vue 1.28 KB
Newer Older
陈浩玮's avatar
yonghu  
陈浩玮 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
<template>
    <a-select
        :value="value"
        style="width: 100%"
        :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
        placeholder="Please select"
        allow-clear
        :options="data"
        @change="onChange"
        v-bind="$attrs"
    />
</template>

<script>
import { formatObj, getReq } from '@/utils';

export default {
    model: {
        prop: 'value',
        event: 'change',
    },
    props: {
        value: [String, Number, Array],
        staticKey: String,
        formatData: { type: Object, default: undefined },
        getName: Function,
    },
    data() {
        return {
            data: [],
        };
    },
    async mounted() {
        const formatData = this.formatData || { value: 'paramValue', label: 'paramName', key: 'paramId' };
        const newArr = await getReq('/api/v1/parameters/business/multi/list', {
            queryList: this.staticKey,
        });

        const curData = newArr.find((i) => i.key === this.staticKey);
        this.data = await formatObj(curData.businessParameterList || [], formatData);
    },
    methods: {
        onChange(val, opt) {
            this.$emit('change', val);
            this.getName && this.getName(opt?.componentOptions?.children[0]?.text || '');
        },
    },
};
//
</script>