emis-frontend/src/views/emis/EmisBaseTools/DistrictPicker.vue

100 lines
2.3 KiB
Vue
Raw Normal View History

2024-04-22 05:35:19 +00:00
<template>
<el-select
style="width:100%"
filterable
clearable
v-model="svalue"
:placeholder="placeholder"
2024-05-25 09:36:22 +00:00
@change="onChange"
@click.native="onClick"
>
2024-04-22 05:35:19 +00:00
<el-option v-for="item in optionItems" :key="item.regionCode" :label="item.regionName" :value="item.regionCode" />
</el-select>
</template>
<script>
import { listSimpleEmisRegion } from "@/api/emis/emisRegion";
export default {
name: "DistrictPicker",
props: {
value: {
2024-05-25 09:36:22 +00:00
type: String,
2024-04-22 05:35:19 +00:00
required: false
},
parentCode: {
type: String,
required: false
},
placeholder: {
type: String,
required: false
}
},
data() {
return {
svalue: this.value,
2024-05-25 09:36:22 +00:00
optionItems: [],
// 缺省值
defaultItems: null,
2024-04-22 05:35:19 +00:00
};
},
watch: {
2024-05-25 09:36:22 +00:00
value(newVal,oldVal) {
2024-07-20 05:00:02 +00:00
// if(this.value!=null){
// // 判断默认值中是否存在,若存在则不继续查询
// if(this.optionItems){
// let selItem = this.optionItems.find(item => item.regionCode == this.svalue);
// if(selItem){
// return;
// }
// }
// }
this.svalue=this.value;
this.queryData(null,this.svalue);
2024-04-22 05:35:19 +00:00
},
2024-05-25 09:36:22 +00:00
parentCode(newVal,oldVal) {
if(newVal!=oldVal){
this.defaultItems=null;
}
2024-04-22 05:35:19 +00:00
}
},
created() {
2024-07-20 05:00:02 +00:00
// if(this.svalue!=null){
// }
this.queryData(null,this.svalue);
2024-04-22 05:35:19 +00:00
},
methods: {
2024-05-25 09:36:22 +00:00
onClick(){
// 第一次点击时需要初始化
if(!this.defaultItems){
this.queryData(null,null);
}else{
this.optionItems = [...this.defaultItems];
}
},
2024-04-22 05:35:19 +00:00
onChange() {
this.$emit("input", this.svalue);
this.$emit("onChange");
},
2024-05-25 09:36:22 +00:00
queryData(val,key) {
2024-04-22 05:35:19 +00:00
this.optionItems =[];
2024-05-25 09:36:22 +00:00
let queryParams = {
parentCode:this.parentCode,
regionCode:key,
regionType:3
};
2024-04-22 05:35:19 +00:00
listSimpleEmisRegion(queryParams).then(response => {
this.optionItems = response.rows;
2024-05-25 09:36:22 +00:00
// 初始值存储
if(key==null && val==null){
this.defaultItems=[...this.optionItems]
}
2024-04-22 05:35:19 +00:00
});
},
}
};
</script>