index.vue 1.57 KB
Newer Older
dragondean@qq.com's avatar
dragondean@qq.com 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 51 52 53 54 55
<template>
    <div>
        <el-select v-model="formData.country">
            <el-option v-for="(item) in treeList" :value="item.id" :label="item.titleZh" :key="item.id" />
        </el-select>
        <el-select v-model="formData.province">
            <el-option v-for="(item) in provinceList" :value="item.id" :label="item.titleZh" :key="item.id" />
        </el-select>
        <el-select v-model="formData.city">
            <el-option v-for="(item) in cityList" :value="item.id" :label="item.titleZh" :key="item.id" />
        </el-select>
    </div>
</template>
<script>
import { getListTree } from "@/api/ecw/region";

export default {
    data(){
        return {
            formData:{

            },
            treeList: [],
            provinceList: [],
            cityList:[]
        }
    },
    watch:{
        'formData.city'(city){
            this.$emit('cityChange', city)
        },
        'formData.country'(country){
            this.$emit('countryChange', country)
            this.treeList.forEach(item => {
                if(item.id == country){
                    this.provinceList = item.children || []
                }
            })
        },
        'formData.province'(province){
            this.$emit('provinceChange', province)
            this.provinceList.forEach(item => {
                if(item.id == province){
                    this.cityList = item.children || []
                }
            })
        }
    },
    created(){
        getListTree({treeType: 1}).then(response => {
            this.treeList = response.data
        })
    }
}
</script>