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

120 lines
2.7 KiB
Vue
Raw Normal View History

2024-04-22 05:35:19 +00:00
<template>
2024-05-07 04:53:25 +00:00
<el-select
2024-05-25 14:22:10 +00:00
style="width:100%"
filterable
clearable
v-model="svalue"
no-data-text=""
:placeholder="placeholder"
@change="onChange"
@click.native="onClick"
>
2024-05-07 04:53:25 +00:00
<el-option v-for="item in optionItems" :key="item.destCode" :label="item.destName" :value="item.destCode" ></el-option>
</el-select>
2024-04-22 05:35:19 +00:00
</template>
<script>
2024-05-07 04:53:25 +00:00
import { listSimpleEmisDestination } from "@/api/emis/emisDestination";
2024-04-22 05:35:19 +00:00
2024-05-07 04:53:25 +00:00
export default {
name: "DestinationPicker",
props: {
value: {
type: String,
required: false
},
placeholder: {
type: String,
required: false
},
countryCode: {
type: String,
required: false
},
lineCode:{
type: [String,Number],
required: false
},
isInitiated:{
type: [Boolean,String],
required: false,
default:false
},
disabled:{
type: [Boolean,String],
required: false
},
},
data() {
return {
loading:false,
svalue: this.value,
2024-05-25 14:22:10 +00:00
optionItems: [],
// 缺省值
defaultItems: null,
2024-05-07 04:53:25 +00:00
};
},
watch: {
2024-05-25 14:22:10 +00:00
value(newVal,oldVal) {
if(this.value!=null ){
this.svalue=this.value;
// 判断默认值中是否存在,若存在则不继续查询
if(this.optionItems){
let selItem = this.optionItems.find(item => item.destCode == this.svalue);
if(selItem){
return;
}
}
this.queryData(null,this.svalue);
}
},
2024-05-07 04:53:25 +00:00
countryCode(newVal, oldVal) {
2024-05-25 14:22:10 +00:00
if(newVal!=oldVal){
this.defaultItems=null;
}
2024-05-07 04:53:25 +00:00
},
},
created() {
2024-05-25 14:22:10 +00:00
if(this.svalue!=null){
this.queryData(null,this.svalue);
}
2024-05-07 04:53:25 +00:00
},
methods: {
2024-05-25 14:22:10 +00:00
onClick(){
// 第一次点击时需要初始化
if(!this.defaultItems){
this.queryData(null,null);
}else{
this.optionItems = [...this.defaultItems];
}
},
2024-05-07 04:53:25 +00:00
onChange() {
this.$emit("input", this.svalue);
2024-05-25 14:22:10 +00:00
let itemData=this.optionItems.find(item=> item.destCode === this.svalue);
2024-05-07 04:53:25 +00:00
this.$emit("onChange",itemData);
},
2024-05-25 14:22:10 +00:00
queryData(val,key) {
2024-05-07 04:53:25 +00:00
this.loading = true;
2024-05-25 14:22:10 +00:00
let queryParams = {
pageNum:1,
pageSize:150,
country:this.countryCode
};
this.optionItems=[];
2024-05-07 04:53:25 +00:00
listSimpleEmisDestination(queryParams).then(response => {
this.loading = false;
2024-05-25 14:22:10 +00:00
this.optionItems =response.rows;
// 初始值存储
if(key==null && val==null){
this.defaultItems=[...this.optionItems]
}
2024-05-07 04:53:25 +00:00
});
},
}
};
2024-04-22 05:35:19 +00:00
</script>