109 lines
2.1 KiB
Vue
109 lines
2.1 KiB
Vue
<template>
|
|
<el-col :span="span">
|
|
<el-form-item
|
|
:label="config.attrName"
|
|
:prop="config.attrField"
|
|
label-width="150px"
|
|
class="add-form-item"
|
|
:class="{'form-item-disabled': disabled}"
|
|
>
|
|
<el-select
|
|
v-model="valueArr"
|
|
:placeholder="placeholder"
|
|
filterable
|
|
:disabled="disabled"
|
|
clearable
|
|
multiple
|
|
@change="handleChange"
|
|
>
|
|
<el-option
|
|
v-for="opt in options"
|
|
:key="opt.value"
|
|
:value="opt.value"
|
|
:label="opt.label"
|
|
>
|
|
{{ opt.label }}
|
|
</el-option>
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-col>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: 'CustomSelectArray',
|
|
props: {
|
|
config: {
|
|
type: Object,
|
|
required: true
|
|
},
|
|
value: {
|
|
required: true
|
|
},
|
|
disabled: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
// 栅格比例
|
|
span: {
|
|
type: Number,
|
|
default: 24
|
|
}
|
|
},
|
|
data () {
|
|
return {
|
|
valueArr: []
|
|
}
|
|
},
|
|
computed: {
|
|
placeholder () {
|
|
return `请输入${this.config.attrName}`
|
|
},
|
|
showMessage () {
|
|
return `${this.config.attrName}不能为空`
|
|
},
|
|
isRequired () {
|
|
return !!this.config.isMust
|
|
},
|
|
options () {
|
|
return this.config.options || []
|
|
}
|
|
},
|
|
methods: {
|
|
handleChange (event) {
|
|
// const value = event.target.value
|
|
this.$emit('input', event)
|
|
}
|
|
},
|
|
watch: {
|
|
value: {
|
|
deep: true,
|
|
handler (val) {
|
|
if (this.value !== '' && this.value !== null && typeof (this.value) !== 'undefined') {
|
|
if (this.value instanceof Array) {
|
|
this.valueArr = this.value
|
|
} else {
|
|
this.valueArr = this.value.split(',')
|
|
}
|
|
} else if (this.value === '') {
|
|
this.valueArr = []
|
|
}
|
|
}
|
|
}
|
|
},
|
|
mounted () {
|
|
if (this.value !== '' && this.value !== null && typeof (this.value) !== 'undefined') {
|
|
if (this.value instanceof Array) {
|
|
this.valueArr = this.value
|
|
} else {
|
|
this.valueArr = this.value.split(',')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
</style>
|