<template>
<div>
<!-- 省 -->
<el-form-item label-width="60px">
<el-select v-model="province_id" placeholder="请选择省份" clearable>
<el-option :label="'全部'" :value="0"> </el-option>
<el-option
v-for="item in sele"
:key="item.id"
:label="item.name"
:value="item.id"
@change="sheng"
>
</el-option>
</el-select>
</el-form-item>
<!-- 市 -->
<el-form-item label-width="60px">
<el-select v-model="city_id" placeholder="请选择城市" clearable>
<el-option :label="'全部'" :value="0" @change="shi"> </el-option>
<el-option
v-for="s in si"
:key="s.id"
:label="s.name"
:value="s.id"
@change="shi"
>
</el-option>
</el-select>
</el-form-item>
<!-- 区 -->
<el-form-item label-width="60px">
<el-select v-model="district_id" placeholder="请选择区" clearable>
<el-option :label="'全部'" :value="0" @change="qua"> </el-option>
<el-option
v-for="q in qu"
:key="q.id"
:label="q.name"
:value="q.id"
@change="qua"
>
</el-option>
</el-select>
</el-form-item>
</div>
</template>
<script>
export default {
name: "zj",
computed: {
showuinof() {
return this.$store.state.info;
}
},
data() {
return {
dats: 0,
province_id: 0,
city_id: 0,
district_id: 0,
sele: [],
si: [],
qu: [],
optionProps: {
value: "id",
label: "name",
children: "sub"
},
allArea: []
};
},
watch: {
province_id(val) {
this.$emit("province_id", this.province_id);
this.selectProvince();
},
city_id(val) {
this.selectCity();
this.$emit("city_id", this.city_id);
},
district_id(a) {
this.$emit("district_id", this.district_id);
}
},
methods: {
selectProvince() {
this.si = this.allArea.filter(a => {
return a.level == 1 && a.pid == this.province_id;
});
this.city_id = 0;
},
selectCity() {
if (this.city_id == 0) {
this.qu = [];
this.district_id = 0;
} else {
this.qu = this.allArea.filter(a => {
if (a.level == 2 && a.name && a.pid == this.city_id) {
return a;
}
});
if (this.qu.length > 0) {
this.district_id = 0;
this.$emit("district_id", this.district_id);
}
}
},
queryinfo() {
if (this.showuinof.length > 0) {
this.allArea = this.showuinof;
this.gggg();
} else {
this.$http.post("?s=Manage.Index.Area", {}).then(res => {
console.log(res.data.data, "省市区数据");
if (res.data.code == 200) {
this.$store.commit("area", res.data.data);
this.allArea = res.data.data;
this.gggg();
}
});
}
},
gggg() {
this.sele = this.allArea.filter(a => {
return a.level == 0;
});
this.$emit("all", this.allArea);
},
},
mounted() {
this.$emit("dats", 0);
this.queryinfo();
}
};
</script>
<style scoped></style>
省市区组件优化
最新推荐文章于 2024-06-29 20:07:33 发布