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

157 lines
4.0 KiB
Vue
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<el-select
ref="selectRef"
:disabled="disabled"
style="width:100%"
filterable
clearable
remote
:remote-method="queryData"
v-model="svalue"
:placeholder="placeholder"
@focus="onFocus"
@blur="onBlur"
@change="onChange"
@click.native="onClick"
@visible-change="reverseArrow"
>
<el-option v-for="item in optionItems" :key="item.lineCode" :label="item.lineName+((item.status==0)?'-已停用':'')" :value="item.lineCode" />
</el-select>
<!-- style="width:100%" -->
</template>
<script>
import emitter from 'element-ui/src/mixins/emitter';
import { listSimpleAllEmisTransLine } from "@/api/emis/emisTransLine";
export default {
name: "TransLinePicker",
mixins: [emitter],
props: {
value: {
type: String,
required: false
},
placeholder:{
type: String,
required: false
},
countryCode: {
type: String,
required: false
},
fromCountry: {
type: String,
required: false
},
isInitiated:{
type: [Boolean,String],
required: false,
default:false
},
disabled:{
type: [Boolean],
required: false
},
},
data() {
return {
optionItems: [],
defaultItems:null,
svalue: this.value,
filterMap:new Map(),
queryParams: {
pageNum: 1,
pageSize: 50,
lineCode:null,
lineName:null,
country:this.countryCode,
fromCountry:this.fromCountry
}
};
},
watch: {
value(newVal) {
this.svalue = newVal;
this.queryParams.lineCode=this.svalue ;
this.queryData(null,this.svalue);
},
countryCode(newVal) {
this.defaultItems=null;
this.queryParams.country=this.countryCode;
this.queryData();
},
fromCountry(newVal) {
this.defaultItems=null;
this.queryParams.fromCountry=this.fromCountry;
this.queryData();
},
},
created() {
if(this.isInitiated || this.svalue!=null){
this.queryData();
}
},
mounted(){
let rulesDom = this.$refs["selectRef"].$el.querySelector(".el-input .el-input__suffix .el-input__suffix-inner .el-input__icon"); // 找到dom
    rulesDom.classList.add("el-icon-arrow-up"); // 对dom新增class
},
methods: {
onClick(){
// 第一次点击时需要初始化
if(!this.defaultItems){
this.queryData(null,null);
}else{
this.optionItems = [...this.defaultItems];
}
},
onFocus(val){
this.optionItems=[];
this.queryData();
},
onBlur(val){
this.$emit("input", this.svalue);
this.dispatch('ElFormItem', 'el.form.blur', [this.svalue]);
},
onChange() {
this.$emit("input", this.svalue);
this.$emit("onChange",this.filterMap[this.svalue]);
this.dispatch('ElFormItem', 'el.form.change', [this.svalue]);
},
queryData(val,key) {
this.optionItems=[];
this.queryParams.lineCode=key;
this.queryParams.lineName=val;
listSimpleAllEmisTransLine( this.queryParams).then(response => {
this.optionItems = response.rows;
this.optionItems.forEach(item => {
this.filterMap[item.lineCode]=item;
});
//初始值存储
if(key==null && val==null){
this.defaultItems=[...this.optionItems];
}else{
this.onChange();
}
});
},
reverseArrow(flag) {
let rulesDom = this.$refs["selectRef"].$el.querySelector(
".el-input .el-input__suffix .el-input__suffix-inner .el-input__icon"
); // 找到dom
if (flag) {
rulesDom.classList.add("is-reverse"); // 对dom新增class
} else {
rulesDom.classList.remove("is-reverse"); // 对dom新增class
}
},
}
};
</script>