liuxiaolong
2019-05-06 3e0536f508aad49f743e7bfabca34e3980a1b6e2
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
<template>
  <b-modal ref="myModalRef" :title="title" size="lg" ok-title="确定" cancel-title="取消" @ok="handleSave" @cancel="hideModal">
    <div class="ml10">
      <span>姓名:</span>
      <b-input v-model="searchValue" style="width: 200px; display: inline-block" placeholder="请输入姓名" @change.native="handleSearch" />
      <b-btn variant="primary" @click="handleSearch">
        搜索
      </b-btn>
    </div>
    <div class="row pt-3" style="margin-left: 0; margin-right: 0">
      <div :key="item.id" v-for="item in modelList" class="col-md-6 col-xl-4">
        <b-card class="card-condenced mb-3 person-card overflow-hidden" body-class="media align-items-center" @click="toggleSelect($event, item)">
          <b-check class="file-item-checkbox" :checked="selected.includes(item)" @change="toggleSelect($event, item)" />
          <httpImg :src="item.photos" height="100px" class="max-img" />
          <div class="media-body ml-3">
            <a href="javascript:void(0)" class="text-dark font-weight-semibold mb-2">
              {{item.name}}
            </a>
          </div>
        </b-card>
      </div>
    </div>
    <div class="fr">
      <b-pagination class="ml10" v-if="total" size="md" :total-rows="total" v-model="currentPage" :per-page="length" @change="changePage" />
    </div>
  </b-modal>
</template>
<style src="@/vendor/styles/pages/file-manager.scss" lang="scss"></style>
<script>
/**
 * 选择人员
 * @param { String } title 弹框名 默认 - 请选择人员关系
 * @param { String } orgId 机构id
 */
import { getUserList } from '../../server/personnel.js'
export default {
  props: {
    title: {
      type: String,
      default: '请选择人员关系'
    }
  },
  data: () => ({
    modelList: [],
    total: 0,
    length: 9,
    currentPage: 1,
    searchValue: '',
    selected: [],
    focused: null,
    dropdownOpened: null
  }),
  computed: {
    orgId() {
      return this.$store.getters.basicUserInfo.orgId
    }
  },
  methods: {
    showModal() {
      this.$refs.myModalRef.show()
      this.getRelation()
    },
    hideModal() {
      this.$refs.myModalRef.hide()
    },
    // * 获取数据
    async getRelation() {
      const res = await getUserList({
        orgId: this.orgId,
        id: 1,
        length: this.length,
        start: this.length * (this.currentPage - 1),
        type: '',
        isAll: 0,
        name: this.searchValue
      })
      if (res) {
        this.modelList = res.data
        this.total = res.total
      }
    },
    // * 分页器设置
    changePage(e) {
      this.currentPage = e
      this.getRelation()
    },
    // * 搜索
    handleSearch() {
      this.currentPage = 1
      this.getRelation()
    },
    // * 选择
    toggleSelect(checked, item) {
      if (checked) {
        this.selected = [item]
      } else {
        this.selected.splice(this.selected.indexOf(item), 1)
      }
    },
    // * 保存
    handleSave() {
      this.$emit('relationData', this.selected)
      this.selected = []
      this.hideModal()
    }
  }
}
</script>
<style>
.max-img {
  max-width: 120px;
}
.person-card {
  height: 135px;
  cursor: pointer;
  transition: all 0.3s;
}
.person-card:hover {
  border: 1px solid #26b4ff;
}
</style>