<!-- 多选枚举类型数据维护 -->
<template>
    <el-dialog :title="`编辑 <${infoName}>`" :visible.sync="dialog.menum" width="670px">
        <el-row style="margin-top: 20px">
            <el-select v-model="value" multiple placeholder="请选择" style="width: 100%">
                <el-option v-for="item in options" :key="item.Code" :label="item.Name" :value="item.Code"> </el-option>
            </el-select>
        </el-row>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialog.menum = false">取 消</el-button>
            <el-button type="primary" @click="handleClickUpdate">确 认</el-button>
        </span>
    </el-dialog>
</template>
<script>
import tools from "@/utils/old-adm/scan/tools";

export default {
    props: {
        dialog: {
            type: Object,
            default: function () {
                return {
                    menum: true,
                };
            },
        },
        updateInput: {
            type: [Array, String],
            default: [],
        },
        updateInfoData: {
            type: [Object],
            default: {},
        },
    },
    data() {
        return {
            value: [],
        };
    },
    computed: {
        options() {
            return this.updateInfoData.dataSource ? tools.formatDataSource(this.updateInfoData.dataSource) : [];
        },
        // 信息点名称
        infoName() {
            return this.updateInfoData.name || "";
        },
    },
    methods: {
        formatValue(value) {
            if (value instanceof Array) {
                return JSON.parse(JSON.stringify(value));
            } else if (typeof value === "string" && value !== "") {
                return value.split(",");
            } else {
                return [];
            }
        },
        // 确认修改
        handleClickUpdate() {
            this.$emit("change", this.value);
        },
    },
    watch: {
        dialog: {
            deep: true,
            handler() {
                if (this.dialog.menum) {
                    this.value = this.formatValue(this.updateInput);
                }
            },
        },
    },
};
</script>

<style lang="less">
</style>
