Blame view

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

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

<style scoped>

</style>