2025-08-12 15:25:10 +08:00
|
|
|
<template>
|
2026-04-06 13:16:45 +08:00
|
|
|
<el-select filterable v-model="_customerId" remote :remote-method="remoteSearchCustomer" :style="style" :loading="customerLoading" placeholder="请选择客户">
|
|
|
|
|
<el-option v-for="item in customerList" :key="item[bindField]" :label="item.companyName" :value="item[bindField]" />
|
2025-08-12 15:25:10 +08:00
|
|
|
</el-select>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-12-26 14:45:11 +08:00
|
|
|
import { listCustomer } from '@/api/crm/customer';
|
2025-08-12 15:25:10 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'CustomerSelect',
|
|
|
|
|
props: {
|
|
|
|
|
value: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: ''
|
2026-04-06 13:16:45 +08:00
|
|
|
},
|
|
|
|
|
bindField: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'customerId'
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => ({})
|
2025-08-12 15:25:10 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
_customerId: {
|
|
|
|
|
get() {
|
|
|
|
|
return this.value;
|
|
|
|
|
},
|
|
|
|
|
set(value) {
|
|
|
|
|
this.$emit('input', value);
|
2026-04-06 13:16:45 +08:00
|
|
|
// 找到对应的客户信息
|
|
|
|
|
const customer = this.customerList.find(item => item[this.bindField] === value);
|
|
|
|
|
// 触发 change 事件,传递客户信息
|
|
|
|
|
if (customer) {
|
|
|
|
|
this.$emit('change', customer);
|
|
|
|
|
}
|
2025-08-12 15:25:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
customerList: [],
|
|
|
|
|
customerLoading: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.remoteSearchCustomer('');
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
remoteSearchCustomer(query) {
|
|
|
|
|
this.customerLoading = true;
|
2026-04-06 13:16:45 +08:00
|
|
|
listCustomer({ companyName: query, pageNum: 1, pageSize: 10 }).then(response => {
|
2025-08-12 15:25:10 +08:00
|
|
|
this.customerList = response.rows;
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
this.customerLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|