formatOption.vue 10.2 KB
<template>
<div :class="storeLevel ? 'condition-item store-level-item' : 'condition-item'">
    <li class="condition-item">
        <span v-if="!storeLevel" class="condition-item-text">{{$t('asisTab.format')}} :</span>
        <div class="condition-item-option format-select">
            <el-select v-model="formatLevel" filterable placeholder="选择业态等级" class="mall-sel-box">
                <el-option :key="1" label="一级业态" :value="1"></el-option>
                <el-option :key="2" label="二级业态" :value="2"></el-option>
            </el-select>
        </div>
    </li> 
    <li class="condition-item format-item">
            <div class="condition-item-option">
                <el-select v-model="formatVal" filterable :placeholder="$t('pholder.format')" class="floor-sel-box format-sel-box" v-show="formatLevel === 1 && objectVal === 1" @change="formatChange(formatVal,'formatVal')">
                    <el-option v-for="item in formatOneOpts" :key="item.id" :label="item.label" :value="item.id">    
                    </el-option>
                </el-select>
                <el-select v-model="mutiFormatVal" filterable multiple collapse-tags :placeholder="$t('pholder.format')" class="floor-sel-box format-sel-box" @change="mutiFormatChange" v-show="formatLevel === 1 && objectVal === 2">
                    <div :class="isFormatSelAll ? 'sel-all-box selected' : 'sel-all-box'" @click="selAllHandle('Format',formatOneOpts)">
                        <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 formatOneOpts" :key="item.id" :label="item.label" :value="item.id">
                        <span class="custom-checkbox__input">
                            <span class="custom-checkbox__inner"></span>
                        </span>
                        <span style="padding-left: 5px;">{{ item.label }}</span>
                    </el-option>
                </el-select>
                <el-select v-model="formatTwoVal" filterable  :placeholder="$t('pholder.subFormat')" class="mall-sel-box" v-show="formatLevel === 2 && objectVal === 1" @change="formatChange(formatTwoVal,'formatTwoVal')">
                    <p
                    v-for="group in formatOptions"
                    :key="group.label"
                    :label="group.label">
                        <span class="group-label">{{group.label}}</span><i class="el-icon-caret-bottom"></i>
                        <el-option
                            v-for="item in group.children"
                            :key="item.id"
                            :label="item.label"
                            :value="item.id">
                        </el-option>
                    </p>
                </el-select>
                <el-select v-model="mutiFormatTwoVal"  multiple collapse-tags filterable  :placeholder="$t('pholder.subFormat')" class="mall-sel-box" @change="mutiSubFormatChange" v-show="formatLevel === 2 && objectVal === 2">
                    <div :class="isFormatTwoSelAll ? 'sel-all-box selected' : 'sel-all-box'" @click="selAllHandle('FormatTwo',formatOptions)">
                        <span class="custom-checkbox__input">
                            <span class="custom-checkbox__inner"></span>
                        </span>
                        <span style="padding-left: 5px;">{{$t('allPages.all')}}</span>
                    </div>
                    <div
                    v-for="group in formatOptions"
                    :key="group.label"
                    :label="group.label">
                        <span class="group-label">{{group.label}}</span>
                        <!-- <div :class="isFormatTwoSelAll ? 'sel-all-box selected' : 'sel-all-box'" @click="selGroupHandle(group.label)">
                            <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 group.children"
                            :key="item.id"
                            :label="item.label"
                            :value="item.id">
                            <span class="custom-checkbox__input">
                                <span class="custom-checkbox__inner"></span>
                            </span>
                            <span style="padding-left: 5px;">{{ item.label }}</span>
                        </el-option>
                    </div>
                </el-select>
            </div>
        </li>
    </div>
</template>

<script>
export default {
    props: {
        objectVal: {
            type: Number,
            required: true
        },
        storeLevel: {
            type: Boolean
        }
    },
    name: 'format-option-content',
    data() {
        return {
            formatOneOpts: [],
            formatOptions: [],
            formatVal: '',
            formatTwoVal: '',
            mutiFormatVal: [],
            mutiFormatTwoVal: [], 
            formatLevel: 1,
            subFormatIdObj: {},
            formatIdOfSub: [],
            isFormatSelAll: false,
            isFormatTwoSelAll: false,
            groupFormatId: {},
            subFormatLength: 0,
        }
    },
    watch: {
        formatVal(val) {
            let obj = {
                'formatVal': val
            }
            this.$emit('formatValWatch', obj);
        },
        formatTwoVal(val) {
            let obj = {
                'formatTwoVal': val
            }
            this.$emit('formatValWatch', obj);
        },
        mutiFormatVal(val) {
            let obj = {
                'mutiFormatVal': val
            }
            this.$emit('formatValWatch', obj);
        },
        mutiFormatTwoVal(val) {
            let obj = {
                'mutiFormatTwoVal': val
            }
            this.$emit('formatValWatch', obj);
        },
        formatLevel(val) {
            let obj = {
                'formatLevel': val
            }
            this.$emit('formatValWatch', obj);
        }

    },
    created() {
    },
    mounted() {
        this.getFormat();
    },
    methods: {
        getFormat() {
            this.sessionFormat('filterFormat').then(resovleData => {
                this.mutiFormatVal = [];
                this.mutiFormatTwoVal = [];
                this.formatVal = '';
                this.formatTwoVal = '';
                this.formatOneOpts = resovleData.format;
                this.formatOneOpts.forEach((item,index) => {
                    if(index === 0) {
                        this.formatVal = this.formatVal ? this.formatVal : item.id;
                    }
                    this.mutiFormatVal.push(item.id);
                })
                this.formatOptions = resovleData.subFormat;
                resovleData.subFormat.forEach((item,index) => {
                    this.groupFormatId[item.label] = [];
                    item.children.forEach((child,childIndex) => {
                        this.subFormatLength += 1;
                        if(index === 0 && childIndex === 0) {
                            this.formatTwoVal = this.formatTwoVal ? this.formatTwoVal : child.id;
                        }
                        this.subFormatIdObj[child.id] = child.formatId;
                        this.mutiFormatTwoVal.push(child.id);
                        this.groupFormatId[item.label].push(child.id);
                    })
                })
                let valKey = ['formatVal','formatTwoVal','mutiFormatVal','mutiFormatTwoVal'];
                valKey.forEach(item => {
                    this[item] = JSON.parse(window.sessionStorage.getItem(item)) ? JSON.parse(window.sessionStorage.getItem(item)) : this[item];
                })
                this.isFormatSelAll = this.mutiFormatVal.length < this.formatOneOpts.length ? false : true;
                this.isFormatTwoSelAll = this.mutiFormatTwoVal.length < this.subFormatLength ? false : true;
                // console.log('this.groupFormatId',this.groupFormatId)
            })
        },
        mutiFormatChange(val) {
            window.sessionStorage.setItem('mutiFormatVal',JSON.stringify(val));
            this.isFormatSelAll = this.mutiFormatVal.length < this.formatOneOpts.length ? false: true;
        },
        mutiSubFormatChange(val) {
            window.sessionStorage.setItem('mutiFormatTwoVal',JSON.stringify(val));
            this.isFormatTwoSelAll = this.mutiFormatTwoVal.length < this.subFormatLength.length ? false: true;
            // this.formatIdOfSub = [];
            // val.forEach(item => {
            //     let formatId = this.subFormatIdObj[item];
            //     if(formatId) {
            //         if(!this.formatIdOfSub.includes(formatId)) {
            //             this.formatIdOfSub.push(formatId)
            //         }
            //     }
            // })
            // console.log(this.formatIdOfSub)
        },
        formatChange(val,key) {
            window.sessionStorage.setItem(key,val);
        },
        selAllHandle(selType,option) {
            let selectAll = 'is' + selType + 'SelAll';
            let selectVal = 'muti' + selType + 'Val';
            if(this[selectAll]) {
                this[selectAll] = false;
                this[selectVal] = [];
            }else{
                this[selectAll] = true;
                this[selectVal] = [];
                if(selType === 'FormatTwo') {
                    option.forEach(item => {
                        item.children.forEach(child => {
                            this[selectVal].push(child.id);
                        })
                    })
                }else {
                    option.forEach(item => {
                        this[selectVal].push(item.id);
                    })
                }
            }
        },
        selGroupHandle(groupName) {
            console.log(this.groupFormatId[groupName])
        }
    }
}
</script>

<style scoped>
 /deep/.store-level-item {
     margin-left: 0px
 }
</style>