修改搜索功能
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
:placeholder="placeholder"
|
||||
:clearable="clearable"
|
||||
:filterable="filterable"
|
||||
:multiple="multiple"
|
||||
:collapse-tags="multiple"
|
||||
:collapse-tags-tooltip="multiple"
|
||||
:disabled="disabled"
|
||||
:loading="loading"
|
||||
:size="size"
|
||||
@@ -30,10 +33,16 @@ import { listCustomer } from '@/api/customersuppliermanagement/customerinfo/cust
|
||||
import { listSupplier } from '@/api/customersuppliermanagement/supplierinfo/supplier.js'
|
||||
|
||||
const props = defineProps({
|
||||
// 单选时为 String/Number;multiple 时为数组
|
||||
modelValue: {
|
||||
type: [String, Number],
|
||||
type: [String, Number, Array],
|
||||
default: ''
|
||||
},
|
||||
// 多选模式
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'customer',
|
||||
@@ -94,7 +103,8 @@ const realLabelKey = computed(() => props.labelKey || (isCustomer.value ? 'custo
|
||||
const realCodeKey = computed(() => props.codeKey || (isCustomer.value ? 'customerCode' : 'supplierCode'))
|
||||
|
||||
watch(() => props.modelValue, (val) => {
|
||||
innerValue.value = val
|
||||
// 多选模式下空值归一化为数组,避免 el-select 告警
|
||||
innerValue.value = props.multiple && (val === undefined || val === null) ? [] : val
|
||||
}, { immediate: true })
|
||||
|
||||
function getLabel(item) {
|
||||
@@ -118,8 +128,15 @@ function fetchList() {
|
||||
|
||||
function handleChange(val) {
|
||||
emit('update:modelValue', val)
|
||||
const selected = options.value.find(item => String(item[realValueKey.value]) === String(val))
|
||||
emit('change', val, selected)
|
||||
if (props.multiple) {
|
||||
const selected = options.value.filter(item =>
|
||||
Array.isArray(val) && val.some(v => String(v) === String(item[realValueKey.value]))
|
||||
)
|
||||
emit('change', val, selected)
|
||||
} else {
|
||||
const selected = options.value.find(item => String(item[realValueKey.value]) === String(val))
|
||||
emit('change', val, selected)
|
||||
}
|
||||
}
|
||||
|
||||
function handleVisibleChange(visible) {
|
||||
|
||||
Reference in New Issue
Block a user