selectCarDialog.vue 3.44 KB
<template>
    <GLDialog title="选择车系"
        mode="mid"
        :visible.sync="dialogVisible"
        :before-close="handleClose"
        :close-on-click-modal="false"
        @onOk="handleConfirm"
        @onCancel="handleClose">
        <div class="car-container">
            <div class="wrap">
                <div class="item flex-center" v-for="item in carSeriesData" :key="item.id" @click="selectBrand(item)">
                    <span>{{ item.name }}</span>
                    <i class="el-icon-arrow-right"></i>
                </div>
            </div>
            <div class="wrap">
                <div class="item flex-center" v-for="(item, index) in sonBrandList" :key="item.id">
                    <el-checkbox :indeterminate="isIndeterminate(item)" v-model="item.checked" @change="selectCarSeries(index, item)">
                        <span class="flex-center">
                            {{ item.name }}
                            <i class="el-icon-arrow-right"></i>
                        </span>
                    </el-checkbox>
                </div>
            </div>
            <div class="wrap">
                <el-checkbox-group v-model="selectdData" @change="handleCheckedCitiesChange">
                    <el-checkbox class="item" v-for="item in carSeriesList" :label="item.name" :key="item.id">{{item.name}}</el-checkbox>
                </el-checkbox-group>
            </div>
        </div>
    </GLDialog>
</template>
  
<script>
  import url from '@/assets/empty.png'
  export default {
    name: 'selectStore',
    data() {
      return {
        carSeriesData: [],
        sonBrandList: [],
        curSonBrandIdx: -1,
        selectdData: [],
        isIndeterminate: true
      }
    },
    computed:{
        carSeriesList() {
            return this.curSonBrandIdx == -1 ? [] : this.sonBrandList[this.curSonBrandIdx]?.childs?.forEach(item => item.checked = false)
        }
    },
    props: {
        dialogVisible:{
            type: Boolean,
            default: false
        }
    },
  
    mounted() {
        this.getCarSeriesData()
    },
  
    methods:{
        getCarSeriesData() {
            this.$apis.store.getCarSeriesApi({needCarSeries:true}).then(res => {
                console.log(res)
                if(res?.length){
                    this.carSeriesData = res
                }
            })
        },
        selectBrand(item) {
            this.curSonBrandIdx = -1
            this.sonBrandList = item.childs
            console.log(item, this.sonBrandList)
        },
        selectCarSeries(idx, item){
            if(this.curSonBrandIdx != idx) this.curSonBrandIdx = idx
        }
    }
  }
</script>
  
<style lang="scss">
.car-container{
    border: 1px solid #E8E8EA;
    height: 476px;
    display: flex;
    .wrap{
        flex: 1;
        border-left:  1px solid #E8E8EA;
        overflow-y: auto;
        padding: 8px 0px 8px 12px;
        &:first-child{
            border: none;
        }
        .item{
            height: 28px;
            line-height: 28px;
            font-size: 14px;
            font-weight: 400;
            color: #333333;
            cursor: pointer;
        }
        .flex-center{
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .son-item{
            display: inline-flex;
            justify-content: space-between;
            align-items: center;
            width: calc(100% - 14px);
        }
    }
}
</style>