jinlin
2024-02-21 09e19d4defad238ecf28a5749a4ce64904fa76b0
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
<template>
  <zt-combo-tree v-model="selectValue" :url="'teamGroup/class/treeByCriteria'+'?dictType='+dictType+'&model='+model" :multiple="multiple" :placeholder="placeholder" @select="onSelected"/>
</template>
<script>
 
  export default {
    name: 'TeamMajorSelector',
    components: {},
    props: {
      value: String,
      dictType: String,
      model: String,
      multiple: {
        type: Boolean,
        default: false
      },
      placeholder: String
    },
    data() {
      return {
        selectValue: this.getValue(this.value)
      }
    },
    watch: {
      value(val, oldval) {
        this.selectValue = this.getValue(val)
      }
    },
    mounted() {
      this.onSelected()
    },
    methods: {
      getValue(value) {
        if (this.multiple) {
          return Array.isArray(value) ? value : (value || '').split(',')
        } else {
          return typeof value === 'undefined' ? '' : value
        }
      },
      onSelected(data) {
        if (this.multiple) {
          this.$emit('input', (this.selectValue || []).join(','))
        } else {
          this.$emit('input', this.selectValue)
        }
      }
    }
  }
</script>