Blame view

ant-design-vue-jeecg/src/components/jeecgbiz/JSelectUserByDep.vue 3.02 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<template>
  <div>
    <a-input-search
      v-model="textVals"
      placeholder="请先选择用户"
      readOnly
      unselectable="on"
      @search="onSearchDepUser">
      <a-button slot="enterButton" :disabled="disabled">选择用户</a-button>
    </a-input-search>
    <j-select-user-by-dep-modal
      ref="selectModal"
      :modal-width="modalWidth"
      :multi="multi"
      @ok="selectOK"
      :user-ids="value"
      :store="storeField"
      :text="textField"
      @initComp="initComp"/>
  </div>
</template>

<script>
肖超群 authored
24
25
import JSelectUserByDepModal from './modal/JSelectUserByDepModal'
import {underLinetoHump} from '@/components/_util/StringUtil'
肖超群 authored
26
肖超群 authored
27
28
29
30
31
32
33
34
export default {
  name: 'JSelectUserByDep',
  components: {JSelectUserByDepModal},
  props: {
    modalWidth: {
      type: Number,
      default: 1250,
      required: false
肖超群 authored
35
    },
肖超群 authored
36
37
38
    value: {
      type: String,
      required: false
肖超群 authored
39
    },
肖超群 authored
40
41
42
43
    disabled: {
      type: Boolean,
      required: false,
      default: false
肖超群 authored
44
    },
肖超群 authored
45
46
47
48
    multi: {
      type: Boolean,
      default: true,
      required: false
肖超群 authored
49
    },
肖超群 authored
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
    backUser: {
      type: Boolean,
      default: false,
      required: false
    },
    // 存储字段 [key field]
    store: {
      type: String,
      default: 'username',
      required: false
    },
    // 显示字段 [label field]
    text: {
      type: String,
      default: 'realname',
      required: false
    }
  },
  data() {
    return {
      storeVals: '', //[key values]
      textVals: '' //[label values]
    }
  },
  computed: {
    storeField() {
      let field = this.customReturnField
      if (!field) {
        field = this.store;
肖超群 authored
79
      }
肖超群 authored
80
      return underLinetoHump(field)
肖超群 authored
81
    },
肖超群 authored
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
    textField() {
      return underLinetoHump(this.text)
    }
  },
  mounted() {
    this.storeVals = this.value
  },
  watch: {
    value(val) {
      this.storeVals = val
    }
  },
  model: {
    prop: 'value',
    event: 'change'
  },
  methods: {
    initComp(textVals) {
      this.textVals = textVals
肖超群 authored
101
    },
肖超群 authored
102
103
104
105
106
107
108
109
110
111
112
113
    //返回选中的用户信息
    backDeparInfo() {
      if (this.backUser === true) {
        if (this.storeVals && this.storeVals.length > 0) {
          let arr1 = this.storeVals.split(',')
          let arr2 = this.textVals.split(',')
          let info = []
          for (let i = 0; i < arr1.length; i++) {
            info.push({
              value: arr1[i],
              text: arr2[i]
            })
肖超群 authored
114
          }
肖超群 authored
115
          this.$emit('back', info)
肖超群 authored
116
        }
肖超群 authored
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
      }
    },
    onSearchDepUser() {
      this.$refs.selectModal.showModal()
    },
    selectOK(rows) {
      console.log("当前选中用户", rows)
      if (!rows) {
        this.storeVals = ''
        this.textVals = ''
      } else {
        let temp1 = []
        let temp2 = []
        for (let item of rows) {
          temp1.push(item[this.storeField])
          temp2.push(item[this.textField])
肖超群 authored
133
        }
肖超群 authored
134
135
        this.storeVals = temp1.join(',')
        this.textVals = temp2.join(',')
肖超群 authored
136
      }
肖超群 authored
137
      this.$emit("change", this.storeVals)
肖超群 authored
138
139
    }
  }
肖超群 authored
140
}
肖超群 authored
141
142
143
144
145
</script>

<style scoped>

</style>