wente
2023-11-08 28e196ded3b02c1efc977fb1c8cba9902aa26d69
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
  <div>
    <el-checkbox-group v-model="dictValue"
                       :class="{'checkbox-column-1': column === '1', 'checkbox-column-2': column === '2', 'checkbox-column-3': column === '3', 'checkbox-column-4': column === '4'}"
                       @input="$emit('input', $event)"
                       v-if="showType === 'checkbox'"
                       :disabled="disabled">
      <el-checkbox :label="data.dictValue" v-for="data in dicts" :key="data.dictValue">{{data.dictLabel}}</el-checkbox>
    </el-checkbox-group>
  </div>
</template>
<script>
import cloneDeep from 'lodash/cloneDeep'
 
export default {
  name: 'ZtDictCheckbox',
  props: {
    value: [Number, String, Boolean],
    dict: { // 字典类型
      type: String,
      required: true
    },
    excluded: {// 排除的
      type: Array,
      default: function () {
        return []
      }
    },
    column: { // 几列
      type: String,
      default: '2'
    },
    checkbox: {
      type: Boolean,
      default: true
    },
    disabled: {
      type: Boolean,
      default: false
    },
    placeholder: String
  },
  data() {
    return {
      dictValue: Array.isArray(this.value) ? [...this.value] : []
    }
  },
  computed: {
    showType() {
      if (this.checkbox) {
        return 'checkbox'
      } 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 = Array.isArray(val) ? [...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>
.checkbox-column-2>.el-checkbox{
  width: 40%;
}
</style>