销售权限控制修改
This commit is contained in:
@@ -4,18 +4,20 @@
|
||||
:placeholder="placeholder"
|
||||
:clearable="clearable"
|
||||
:filterable="filterable"
|
||||
:filter-method="filterMethod"
|
||||
:disabled="disabled"
|
||||
:loading="loading"
|
||||
:size="size"
|
||||
:multiple="false"
|
||||
style="width: 100%;"
|
||||
@change="handleChange"
|
||||
@visible-change="handleVisibleChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.userId"
|
||||
:label="formatLabel(item)"
|
||||
:value="String(item.userId)"
|
||||
:value="String(item[valueField])"
|
||||
:disabled="item.status === '1'"
|
||||
>
|
||||
<span>{{ item.nickName || item.userName }}<template v-if="item.status === '1'">(停用)</template></span>
|
||||
@@ -61,23 +63,53 @@ const props = defineProps({
|
||||
showCode: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
/** 绑定值字段:userId=用户ID(默认);userName=登录账号/工号(老系统迁移数据按工号存储时使用) */
|
||||
valueField: {
|
||||
type: String,
|
||||
default: 'userId'
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'change'])
|
||||
|
||||
const { userList, ensureUsers, findUser } = useUsers()
|
||||
const { userList, ensureUsers } = useUsers()
|
||||
const loading = ref(false)
|
||||
/** 下拉搜索关键字(可同时匹配昵称/姓名与登录账号/工号) */
|
||||
const filterQuery = ref('')
|
||||
const innerValue = ref(props.modelValue === null || props.modelValue === undefined ? null : String(props.modelValue))
|
||||
|
||||
watch(() => props.modelValue, (val) => {
|
||||
innerValue.value = val === null || val === undefined || val === '' ? null : String(val)
|
||||
})
|
||||
|
||||
/** 按当前绑定值字段(userId 或 userName/工号)查找用户 */
|
||||
function findByValue(val) {
|
||||
if (val === null || val === undefined || val === '') return null
|
||||
return userList.value.find(u => String(u[props.valueField]) === String(val)) || null
|
||||
}
|
||||
|
||||
/** 自定义过滤:昵称/姓名、登录账号/工号 任一命中即可(忽略大小写) */
|
||||
function matchUser(item, q) {
|
||||
if (!q) return true
|
||||
const kw = q.trim().toLowerCase()
|
||||
if (!kw) return true
|
||||
return ['nickName', 'userName'].some(k => item[k] && String(item[k]).toLowerCase().includes(kw))
|
||||
}
|
||||
|
||||
function filterMethod(q) {
|
||||
filterQuery.value = q || ''
|
||||
}
|
||||
|
||||
/** 下拉收起后清空搜索词,恢复完整选项 */
|
||||
function handleVisibleChange(visible) {
|
||||
if (!visible) filterQuery.value = ''
|
||||
}
|
||||
|
||||
/** 兜底:当前值在用户列表中不存在(停用/未加载到)时补占位项,避免显示空白 */
|
||||
const options = computed(() => {
|
||||
const list = userList.value
|
||||
if (innerValue.value && !findUser(innerValue.value)) {
|
||||
const list = userList.value.filter(item => matchUser(item, filterQuery.value))
|
||||
if (innerValue.value && !findByValue(innerValue.value) && !filterQuery.value) {
|
||||
return [{ userId: innerValue.value, userName: '', nickName: String(innerValue.value) }, ...list]
|
||||
}
|
||||
return list
|
||||
@@ -92,7 +124,7 @@ function formatLabel(item) {
|
||||
function handleChange(val) {
|
||||
const value = val === '' ? null : val
|
||||
emit('update:modelValue', value)
|
||||
emit('change', value, value === null ? null : findUser(value))
|
||||
emit('change', value, value === null ? null : findByValue(value))
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user