Commit 21136b3d authored by “lixuyan”'s avatar “lixuyan”

站位长选择

parent 6bda104d
import { get } from '../utils/http'
// 通过用户名或账号模糊匹配查询存在账号的用户
export function getUsersByAccount(params) {
return get('/DxUserInfo/byAccount', params)
}
<template>
<div class="ext-position-user-link-com">
<el-select
v-model="bindValue"
size="small"
filterable
multiple
remote
value-key="targetId"
:remote-method="remoteMethod"
@change="UserChange"
@remove-tag="removeTag"
>
<el-option
v-for="citem in UserData"
:key="citem.target.id"
:label="`${citem.target.name}(${citem.target.userAccount})`"
:value="citem"
:disabled="citem.disabled"
/>
</el-select>
</div>
</template>
<script>
import { getUsersByAccount } from '@/api/user'
export default {
name: 'ExtPositionUserLink',
componentName: '站位长选择',
components: {},
props: {
item: {
type: Object,
default: () => {
return {}
}
},
value: {
type: Array,
default: () => {
return []
}
}
},
data() {
return {
bindValue: '',
UserData: [],
removeTags: []
}
},
computed: {},
watch: {
value: {
immediate: true,
deep: true,
handler: function(val) {
if (val) {
if (val !== this.bindValue) {
this.bindValue = val.filter(r => r.operator !== 'REMOVE')
this.removeTags = val.filter(r => r.operator === 'REMOVE')
val.forEach(element => {
element.disabled = true
})
this.UserData = this.bindValue
}
}
}
}
},
methods: {
remoteMethod(query) {
if (query) {
const params = { userAccount: query, containInnerUser: false }
if (this.item.secret) {
params.secretCode = this.$store.state.user.userInfo.secretCode
}
getUsersByAccount(params).then(res => {
const arr = []
this.bindValue.forEach(item => {
arr.push(item.targetId)
})
if (res.items) {
this.UserData = res.items.map(element => {
if (arr.includes(element.id)) {
element.disabled = true
} else {
element.disabled = false
}
return {
disabled: element.disabled,
target: element,
targetId: element.id
}
})
} else {
this.UserData = []
}
})
} else {
this.UserData = []
}
},
UserChange(val) {
const arr = this.removeTags.concat(val)
this.$emit('input', arr)
},
removeTag(val) {
if (val.sourceId || val.sourceId === 0) {
this.removeTags.push({ ...val, operator: 'REMOVE' })
const arr = this.bindValue.concat(this.removeTags)
this.$emit('input', arr)
}
}
}
}
</script>
<style lang='scss'>
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment