1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template>
<el-select @change="$emit('input',customer)" v-model="customer" filterable remote
:remote-method="getCustomerSelectFn" :placeholder="$t('请选择客户名称')">
<el-option v-for="item in getCustomerList" :label="item.name" :value="Number(item.id)" :key="item.id"></el-option>
</el-select>
</template>
<script>
import {getCustomerList, getCustomerSelect} from "@/api/ecw/customer";
export default {
props:{
value:{
type:Number,
default:undefined,
},
},
name: "customerSelect",
mounted() {
this.getCustomerSelectFn();
this.$nextTick(()=>{
this.customer = this.value;
if(!(this.customerList.some(i => i.id === this.value)) && this.value !== undefined){
getCustomerList({ids:this.value}).then(r => {
this.recommended = r.data;
})
}
})
},
computed:{
getCustomerList(){
let index = this.customerList.findIndex(item => item.id !== this.recommended[0])
if(index > -1) return this.customerList
else return [...this.customerList,...this.recommended]
}
},
data(){
return {
customer:'',
customerList:[],
recommended:[],
}
},
methods:{
getCustomerSelectFn(val){
getCustomerSelect({pageNo:1,pageSize:100,searchKey:val}).then(r => {
this.customerList = r.data.list;
})
}
},
watch:{
value(val){
console.log(val,'val')
this.customer = val;
if(!(this.customerList.some(i => i.id === val)) && val !== undefined){
getCustomerList({ids:val}).then(r => {
this.recommended = r.data;
})
}
}
}
}
</script>
<style scoped>
</style>