Files
zhgh_ncu/src/main/resources/static/components/plugins/sysUserSelect/index.vue
T
2025-10-19 20:03:35 +08:00

124 lines
2.2 KiB
Vue

<template>
<el-select v-model="selectValue" :clearable="clearable" filterable remote :remote-method="selectUser"
placeholder="请输入姓名或工号查询" @change="onChange" v-bind="$attrs" style="width: 100%">
<el-option
v-for="item in options"
v-if="!item.disabled"
:key="item[option_value]"
:label="option_label_func ? option_label_func(item) : item[option_label]"
:value="item[option_value]"
></el-option>
</el-select>
</template>
<script>
module.exports = {
model: {
prop: "value",
event: "change"
},
props: {
value: {type: [String, Array]},
api: {
type: String,
required: false,
default: "/open/common/userOptions"
},
api_params: {
type: Object,
required: false,
default: () => {
return {}
}
},
clearable: {
type: Boolean,
default: true
},
api_input_key_name: {
type: String,
required: false,
default: "keyWord"
},
option_list: {
type: Array,
default: () => {
return []
}
},
option_value: {
type: String,
default: "id"
},
option_label: {
type: String,
default: "username"
},
option_label_func: {
type: Function,
required: false
}
},
data() {
return {
options: [],
selectValue: null
}
},
watch: {
value: {
handler: function (val) {
if (this.$attrs.multiple) {
this.selectValue = [...val]
} else {
this.selectValue = val ? val.toString() : ""
}
},
immediate: true,
deep: true
},
option_list: {
handler: function (val) {
if (val) {
this.options = val
}
},
immediate: true
}
},
methods: {
selectUser(query) {
if (query !== "") {
$.get(this.api, {[this.api_input_key_name]: query, ...this.api_params}).then((res) => {
this.options = res.data
})
}
},
onChange(val) {
this.$emit("change", val)
},
clearOptions() {
this.options = []
}
},
created() {
this.clearOptions()
console.log(this.placeholder)
}
}
</script>
<style></style>