zjf
2023-03-03 bafa9dff4d9880c562f4d3a7b83bd4c1129240c5
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<template>
  <div>
    <el-input
      v-model="searchInput"
      placeholder="搜索成员"
      size="small"
      suffix-icon="el-icon-search"
      @input="inputchange"/>
    <div
      v-loading="loading"
      class="search-list">
      <el-checkbox-group
        v-model="selectItems"
        @change="changeCheckout">
        <el-checkbox
          v-for="(item, i) in list"
          v-if="item.show"
          :key="i"
          :label="item"
          :disabled="item.disabled"
          class="colleagues-list">
          <div
            v-photo="item"
            v-lazy:background-image="$options.filters.filterUserLazyImg(item.img)"
            class="div-photo search-img"/>
          <span>{{ item.realname }}</span>
        </el-checkbox>
      </el-checkbox-group>
    </div>
  </div>
</template>
<script type="text/javascript">
// import { usersList } from '@/api/common'
 
export default {
  name: 'XhUser', // 新建 user
  components: {},
  props: {
    value: {
      type: String,
      default: ''
    },
    /** 多选框 只能选一个 */
    radio: {
      type: Boolean,
      default: false
    },
    /** 已选信息 */
    selectedData: {
      type: Array,
      default: () => {
        return []
      }
    },
    /** 获取不同的员工展示列表 */
    infoType: {
      type: String,
      default: 'default' // 返回全部  crm_contract crm_receivables oa_examine 合同审核人自选列表
    },
    infoRequest: Function,
    /** 请求辅助参数 */
    infoParams: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      list: [],
      selectItems: [], // 选择项
      loading: false, // 加载动画
      searchInput: ''
    }
  },
  computed: {},
  watch: {
    selectedData: function (value) {
      this.checkItems(value)
    }
  },
  mounted () {
    this.getUserList()
  },
  methods: {
    // 获取员工列表
    getUserList () {
      this.loading = true
      this.getRequest()(this.getParams())
        .then(res => {
          var self = this
          this.list = res.data.map(function (item, index, array) {
            item.disabled = false // 要求单选
            item.show = true
            if (self.selectedData.length > 0) {
              let disabled = true
              for (let index = 0; index < self.selectedData.length; index++) {
                const element = self.selectedData[index]
                if (element.userId === item.userId) {
                  disabled = false
                  self.selectItems.push(item)
                }
              }
              if (self.radio) {
                item.disabled = disabled
              }
            }
            return item
          })
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
    },
    getRequest () {
      if (this.infoRequest) {
        return this.infoRequest
      } else if (this.infoType === 'default') {
        // return usersList
      } else if (
        this.infoType === 'crm_contract' ||
        this.infoType === 'crm_receivables' ||
        this.infoType === 'oa_examine'
      ) {
        // return usersList
      }
    },
    getParams () {
      const params =
        this.infoParams && Object.keys(this.infoParams.length !== 0)
          ? this.infoParams
          : {}
      if (this.infoType === 'default') {
        params.pageType = 0
        return params
      } else if (
        this.infoType === 'crm_contract' ||
        this.infoType === 'crm_receivables' ||
        this.infoType === 'oa_examine'
      ) {
        params.pageType = 0
        return params
      }
    },
    changeCheckout (items) {
      if (this.radio) {
        if (items.length) {
          var element = items[0]
          this.list = this.list.map(function (item, index, array) {
            if (element.userId === item.userId) {
              item.disabled = false
            } else {
              item.disabled = true
            }
            return item
          })
        } else {
          this.list = this.list.map(function (item, index, array) {
            item.disabled = false
            return item
          })
        }
      }
 
      this.$emit('changeCheckout', { data: this.selectItems })
    },
    /** 取消勾选 */
    cancelCheckItem (item) {
      var removeIndex = -1
      for (let index = 0; index < this.selectItems.length; index++) {
        const element = this.selectItems[index]
        if (element.userId === item.userId) {
          removeIndex = index
        }
      }
      this.selectItems.splice(removeIndex, 1)
      if (this.radio && this.selectItems.length === 0) {
        this.list = this.list.map(function (item, index, array) {
          item.disabled = false
          return item
        })
      }
    },
    /** 标记勾选 */
    checkItems (items) {
      this.selectItems = []
      if (items.length > 0) {
        for (let bigIndex = 0; bigIndex < this.list.length; bigIndex++) {
          const item = this.list[bigIndex]
 
          let disabled = true
          for (let index = 0; index < items.length; index++) {
            const element = items[index]
            if (element.userId === item.userId) {
              disabled = false
              this.selectItems.push(item)
            }
          }
          if (this.radio) {
            item.disabled = disabled
          }
        }
      }
    },
    // 搜索
    inputchange (val) {
      this.list = this.list.map(function (item, index, array) {
        if (item.realname.indexOf(val) !== -1) {
          item.show = true
        } else {
          item.show = false
        }
        return item
      })
    }
  }
}
</script>
<style lang="less" scoped>
/* 选择员工 */
.search-img {
  width: 24px;
  height: 24px;
  border-radius: 12px;
  vertical-align: middle;
  margin-right: 8px;
}
.search-list {
  padding: 5px;
  height: 248px;
  overflow: auto;
}
.colleagues-list {
  padding: 5px;
  display: block;
  margin-left: 0;
}
</style>