Files
zhgh_zjvtit/target/classes/static/components/plugins/sysDict/DictSelect.vue
T
2026-08-26 14:25:17 +08:00

114 lines
2.4 KiB
Vue

<template>
<el-select
v-model="valueAsString"
:placeholder="placeholder"
@change="onChange"
:disabled="disabled"
:clearable="clearable"
:multiple="multiple"
:filterable="filterable"
:size="size"
style="width: 100%"
v-bind="$attrs"
>
<el-option
v-for="item in options"
v-if="!item.disabled"
:key="item[option_value]"
:label="item[option_label]"
:value="item[option_value]"
></el-option>
</el-select>
</template>
<script>
module.exports = {
props: {
value: { type: [String, Array] },
code: {
type: [String, Array],
default: ""
},
option_value: {
type: String,
default: "code"
},
option_label: {
type: String,
default: "name"
},
size: {
type: String,
default: ""
},
placeholder: {
type: String,
default: "请选择"
},
clearable: {
type: Boolean,
default: true
},
disabled: {
type: Boolean,
default: false
},
multiple: {
type: Boolean,
default: false
},
filterable: {
type: Boolean,
default: true
}
},
model: {
prop: "value",
event: "change"
},
data() {
return {
options: []
}
},
computed: {
valueAsString: {
get() {
if (Array.isArray(this.value)) {
return this.value
} else {
return this.value ? this.value.toString() : ""
}
},
set(val) {}
}
},
watch: {
code(val) {
this.flushOptions()
}
},
methods: {
onChange(val) {
this.$emit("change", val)
},
async flushOptions() {
if (!this.code) {
this.options = []
return
}
$.get("/open/common/dictOptions", { code: this.code }).then((res) => {
this.options = res.data
})
}
},
created() {
this.flushOptions()
}
}
</script>
<style></style>