emis-frontend/src/views/emis/EmisBaseTools/TownPicker.vue
2024-05-07 12:53:25 +08:00

79 lines
1.7 KiB
Vue

<template>
<el-select
style="width:100%"
filterable
clearable
v-model="svalue"
:placeholder="placeholder"
@change="onChange">
<el-option v-for="item in optionItems" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</template>
<script>
import { listSimpleEmisRegion } from "@/api/emis/emisRegion";
export default {
name: "TownPicker",
props: {
value: {
type: [String, Number],
required: false
},
parentCode: {
type: String,
required: false
},
placeholder: {
type: String,
required: false
},
isInitiated:{
type: [Boolean,String],
required: false,
default:false
}
},
data() {
return {
optionItems: [],
svalue: this.value,
sParentId:null,
};
},
watch: {
value(newVal) {
this.svalue = newVal;
},
svalue(newVal, oldVal) {
this.$emit("input", this.svalue);
},
parentCode(newVal) {
this.queryData();
}
},
created() {
if(this.isInitiated || this.svalue!=null){
this.queryData();
}
},
methods: {
onChange() {
this.$emit("input", this.svalue);
this.$emit("onChange");
},
queryData() {
this.optionItems =[];
if(this.parentCode==null || this.svalue == null){
return;
}
let queryParams = {parentCode:this.parentCode,regionType:4};
listSimpleEmisRegion(queryParams).then(response => {
this.optionItems = this.handleOptions(response.rows,"regionCode", "regionName",false);
});
},
}
};
</script>