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

98 lines
2.3 KiB
Vue
Raw Normal View History

2024-04-22 05:35:19 +00:00
<template>
<el-select
:size="size"
filterable
clearable
v-model="svalue"
placeholder="选择大区"
:filter-method="dataFilter"
style="width: 100%;"
@change="onChange">
<el-option v-for="item in optionItems" :key="item.id" :label="item.name" :value="item.id" ></el-option>
</el-select>
<!-- <div >{{ item.name }}({{ item.nameEn }})</div> -->
</template>
<script>
import { listEmisCountryArea } from "@/api/emis/emisCountryArea";
export default {
name: "CountryAreaPicker",
props: {
value: {
type: [String,Number],
required: false
},
countryCode: {
type: String,
required: false
},
size: {
type: String,
required: false
},
},
data() {
return {
bakOptionItems:[],
optionItems: [],
svalue: this.value,
optionDefault:null,
countryMap:new Map(),
};
},
watch: {
value(newVal) {
this.svalue = newVal;
},
svalue(newVal, oldVal) {
if (newVal !== oldVal) {
this.$emit("input", this.svalue);
}
},
countryCode(newVal) {
this.initData();
}
},
created() {
this.initData();
},
methods: {
onChange() {
this.$emit("input", this.svalue);
let itemData ={};
this.optionItems.forEach(item=>{
if(item.id === this.svalue){
itemData = item;
}
});
this.$emit("onChange",itemData);
},
initData() {
this.optionItems =[];
if(this.countryCode==null ||this.countryCode==''){
return;
}
let queryParams = {countryCode:this.countryCode};
listEmisCountryArea(queryParams).then(response => {
this.bakOptionItems = response.rows;
this.optionItems = response.rows;
});
},
dataFilter(val) {
this.optionDefault = val
if (val) {
this.optionItems = this.bakOptionItems.filter(item => {
if (item.name.indexOf(val) != -1 || item.nameEn.indexOf(val) != -1) {
return true
}
})
} else {
this.optionItems = this.bakOptionItems;
}
},
}
};
</script>