91 lines
2.3 KiB
Vue
91 lines
2.3 KiB
Vue
|
|
<template>
|
||
|
|
<el-select
|
||
|
|
filterable
|
||
|
|
clearable
|
||
|
|
v-model="svalue"
|
||
|
|
:placeholder="placeholder"
|
||
|
|
:filter-method="dataFilter"
|
||
|
|
style="width: 100%;"
|
||
|
|
@change="onChange">
|
||
|
|
<el-option v-for="item in optionItems" :key="item.code" :label="item.name+'('+item.code+'-'+item.nameEn+')'" :value="item.code" ></el-option>
|
||
|
|
</el-select>
|
||
|
|
<!-- <div >{{ item.name }}({{ item.nameEn }})</div> -->
|
||
|
|
</template>
|
||
|
|
<script>
|
||
|
|
import { listSimpleEmisCountry} from "@/api/emis/emisCountry";
|
||
|
|
|
||
|
|
export default {
|
||
|
|
name: "CountryPicker",
|
||
|
|
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;
|
||
|
|
},
|
||
|
|
svalue(newVal, oldVal) {
|
||
|
|
if (newVal !== oldVal) {
|
||
|
|
this.$emit("input", this.svalue);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
created() {
|
||
|
|
this.initData();
|
||
|
|
},
|
||
|
|
methods: {
|
||
|
|
onChange() {
|
||
|
|
this.$emit("input", this.svalue);
|
||
|
|
let itemData ={};
|
||
|
|
this.optionItems.forEach(item=>{
|
||
|
|
if(item.code === this.svalue){
|
||
|
|
itemData = item;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
this.$emit("onChange",itemData);
|
||
|
|
this.optionItems = this.bakOptionItems;
|
||
|
|
},
|
||
|
|
|
||
|
|
initData() {
|
||
|
|
let queryParams = {};
|
||
|
|
queryParams.orderByColumn = 'orderNum';
|
||
|
|
queryParams.isAsc = 'descending';
|
||
|
|
|
||
|
|
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>
|