select.vue 1.95 KB
<template>
    <el-select v-model="selectVal" class="floor-sel-box format-sel-box" multiple collapse-tags @change="selectChange">
        <div :class="isAll ? 'sel-all-box selected' : 'sel-all-box'" @click="selAllHandle()">
                <span class="custom-checkbox__input">
                        <span class="custom-checkbox__inner"></span>
                </span>
                <span style="padding-left: 5px;">{{$t('allPages.all')}}</span>
        </div>
        <el-option v-for="item in list" :key="item.value" :label="item.label" :value="item.value">
                <span class="custom-checkbox__input">
                        <span class="custom-checkbox__inner"></span>
                </span>
                <span style="padding-left: 5px;">{{ item.label }}</span>
        </el-option>
    </el-select>
</template>

<script>
export default {
    props: {
        parentList:{
            type: Array,
        },
        typeSouce:{
            type: String,
        }
    },
    data() {
        return {
            list: this.parentList,
            selectVal: [],
            isAll: false,
        }
    },
    components: {
    },
    mounted() {
    },
    methods: {
        selAllHandle(){
            if(this.isAll){
                this.isAll = false
                this.selectVal = [];
            }else{
                this.isAll = true;
                this.selectVal = [];
                this.list.forEach(item => {
                    this.selectVal.push(item.value)
                })
            }
            let obj = {};
            obj[this.typeSouce] = this.selectVal;
            this.$emit("childVal",obj)
        },
        selectChange() {
            this.isAll = this.selectVal.length >= this.list.length ? true : false;
            let obj = {};
            obj[this.typeSouce] = this.selectVal;
            this.$emit("childVal",obj)
        }
    }
}
</script>

<style scoped>
.format-sel-box {
    margin-left: 5px;
    width: 135px;
}
</style>