<template>
|
<div>
|
<el-select :value="dictValue" @change="changeProjectMajor" @input="$emit('input', $event)" :placeholder="placeholder" clearable style="width: 100%;" v-if="showType === 'select'" :disabled="disabled">
|
<el-option :label="data.dictLabel" v-for="data in dicts" :key="data.dictValue" :value ="data.dictValue">{{data.dictLabel}}</el-option>
|
</el-select>
|
<el-radio-group :value="dictValue" @input="$emit('input', $event)" v-if="showType === 'radio'" :disabled="disabled">
|
<el-radio :label="data.dictValue" v-for="data in dicts" :key="data.dictValue">{{data.dictLabel}}</el-radio>
|
</el-radio-group>
|
<zt-combo-tree v-model="dictValue" :datas="dictTrees" :disabled-filter="disabledFilter" @input="$emit('input', $event)" v-if="showType === 'tree'" :placeholder="placeholder"/>
|
</div>
|
</template>
|
<script>
|
import cloneDeep from 'lodash/cloneDeep'
|
|
export default {
|
name: 'ZtDict',
|
props: {
|
value: [Number, String, Boolean],
|
dict: { // 字典类型
|
type: String,
|
required: true
|
},
|
excluded: {// 排除的
|
type: Array,
|
default: function () {
|
return []
|
}
|
},
|
radio: {
|
type: Boolean,
|
default: false
|
},
|
dataOnly: { // 对于字典树时,是否只能选择字典值
|
type: Boolean,
|
default: false
|
},
|
disabled: {
|
type: Boolean,
|
default: false
|
},
|
placeholder: String
|
},
|
data() {
|
return {
|
dictValue: typeof this.value === 'undefined' ? '' : (this.value + '')
|
}
|
},
|
computed: {
|
showType() {
|
if (this.radio) {
|
return 'radio'
|
} else {
|
return this.dicts.length > 0 && this.dicts[0].children ? 'tree' : 'select'
|
}
|
},
|
dictTrees() {
|
let datas = cloneDeep(this.dicts)
|
this.wrapTreeId(datas)
|
return datas
|
},
|
dicts: function () {
|
let dicts = this.$store.getters.getDict(this.dict)
|
if (this.excluded.length > 0) {
|
let excludedArray = []
|
this.excluded.forEach(value => excludedArray.push(value + ''))
|
return dicts.filter(option => excludedArray.indexOf(option.dictValue + '') < 0)
|
} else {
|
return dicts
|
}
|
}
|
},
|
watch: {
|
value(val, oldval) {
|
this.dictValue = typeof val === 'undefined' ? '' : (val + '')
|
}
|
},
|
methods: {
|
wrapTreeId(dictTypes) {
|
dictTypes.forEach(item => {
|
if ((item.dictType || '').length > 0) { // 字典类型
|
item.id = item.dictType
|
item.name = item.dictName
|
if (item.dataList && item.dataList.length > 0) {
|
item.children = item.dataList
|
}
|
if (item.children && item.children.length > 0) {
|
this.wrapTreeId(item.children)
|
}
|
} else { // 字典值
|
item.id = item.dictValue
|
item.name = item.dictLabel
|
}
|
})
|
},
|
changeProjectMajor(){
|
this.$emit('changeProjectMajor')
|
},
|
disabledFilter(dict) {
|
return this.dataOnly && (dict.dictType || '').length > 0
|
},
|
onSelected() {
|
|
}
|
}
|
}
|
</script>
|
<style>
|
.el-radio__input.is-disabled + .el-radio__label {
|
color: #808080 !important;
|
}
|
|
.el-radio__input.is-disabled.is-checked + .el-radio__label {
|
color: #00a06e !important;
|
}
|
|
.el-radio__input.is-disabled.is-checked .el-radio__inner {
|
background-color: #00a06e !important;
|
border-color: #1890ff !important;
|
}
|
</style>
|