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

92 lines
2.4 KiB
Vue
Raw Normal View History

2024-04-22 05:35:19 +00:00
<template>
<el-select
2024-05-10 03:42:02 +00:00
2024-04-22 05:35:19 +00:00
filterable
clearable
v-model="svalue"
:placeholder="placeholder"
:filter-method="dataFilter"
2024-05-07 04:53:25 +00:00
@blur="onBlur"
@change="onChange"
>
2024-04-22 05:35:19 +00:00
<el-option v-for="item in optionItems" :key="item.code" :label="item.name+'('+item.code+'-'+item.nameEn+')'" :value="item.code" ></el-option>
</el-select>
2024-05-10 03:42:02 +00:00
<!-- style="width:100%" -->
2024-04-22 05:35:19 +00:00
</template>
<script>
2024-05-07 04:53:25 +00:00
import emitter from 'element-ui/src/mixins/emitter';
2024-04-22 05:35:19 +00:00
import { listSimpleEmisCountry} from "@/api/emis/emisCountry";
export default {
name: "CountryPicker",
2024-05-07 04:53:25 +00:00
mixins: [emitter],
2024-04-22 05:35:19 +00:00
props: {
value: {
type: [String],
required: false
},
placeholder:{
type: [String],
required: false
}
},
data() {
return {
bakOptionItems:[],
optionItems: [],
svalue: this.value,
optionDefault:null,
countryMap:new Map(),
};
},
watch: {
value(newVal) {
this.svalue = newVal;
},
},
created() {
this.initData();
},
methods: {
2024-05-07 04:53:25 +00:00
onBlur(val){
this.$emit("input", this.svalue);
this.dispatch('ElFormItem', 'el.form.blur', [this.svalue]);
},
2024-04-22 05:35:19 +00:00
onChange() {
this.$emit("input", this.svalue);
let itemData ={};
this.optionItems.forEach(item=>{
if(item.code === this.svalue){
itemData = item;
}
});
2024-05-07 04:53:25 +00:00
this.$emit("change",itemData);
2024-05-11 03:13:13 +00:00
this.$emit("onChange",itemData);
2024-05-07 04:53:25 +00:00
this.dispatch('ElFormItem', 'el.form.change', [this.svalue]);
2024-04-22 05:35:19 +00:00
this.optionItems = this.bakOptionItems;
},
initData() {
let queryParams = {};
listSimpleEmisCountry(queryParams).then(response => {
this.bakOptionItems = response.rows;
this.optionItems =this.bakOptionItems;
});
},
dataFilter(val) {
this.optionDefault = val
if (val) {
let searchVal = val.toLowerCase();
this.optionItems = this.bakOptionItems.filter(item => {
if (item.code.indexOf(searchVal) != -1 || item.name.toLowerCase().indexOf(searchVal) != -1 || item.nameEn.toLowerCase().indexOf(searchVal) != -1) {
return true
}
})
} else {
this.optionItems = this.bakOptionItems;
}
},
}
};
</script>