liuxiaolong
2019-05-06 19e47fa0e48ac76a951bbfaa0a3e95211567f5a1
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
<template>
  <b-modal
    ref="myModalRef"
    title="请选择人员关系"
    size="lg"
    ok-title="确定"
    cancel-title="取消"
    @ok="handleSave"
    @cancel="hideModal"
  >
    <div class="ml10">
      <span>姓名:</span>
      <b-input
        autocomplete="off"
        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-4"
          body-class="media align-items-center"
          @click.stop.prevent="toggleSelect($event, item)"
        >
        <!-- :checked="selected.includes(item)" -->
          <b-check
            class="file-item-checkbox"
            :checked="selected.some(i => i.id === item.id)"
            @change.stop.prevent="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>
import { isOrg } from '../../../components/common/util.js'
import { relationByOrg } from '../../../server/personnel.js'
 
export default {
  props: {
    item: {
      type: Object,
      default: () => (null)
    },
    orgId: {
      type: Number | String,
      default: ''
    },
    relationList: {
      type: Array,
      default: () => ([])
    }
  },
  data: () => ({
    modelList: [],
    total: 0,
    length: 9,
    currentPage: 1,
    searchValue: '',
    selected: [],
    focused: null,
    dropdownOpened: null
  }),
  methods: {
    showModal () {
      this.$refs.myModalRef.show()
      this.getRelation()
      this.selected = [...this.relationList]
    },
    hideModal () {
      this.$refs.myModalRef.hide()
    },
    // * 获取数据
    async getRelation() {
      const loginedInfo = JSON.parse(sessionStorage.getItem('loginedInfo'))
      const accessToken = loginedInfo.access_token.split(' ')[0]
      let orgId
      if (this.item) {
        const isOrgResult = isOrg(this.item.type)
        orgId = isOrgResult ? this.item.id : this.item.orgId
      }
      const res = await relationByOrg({
        orgId: this.orgId || orgId,
        id: this.orgId || orgId,
        length: this.length,
        start: this.length * (this.currentPage - 1),
        access_token: accessToken,
        searchName: 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.push(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;
}
.card-condenced {
  height: 135px;
  cursor: pointer;
  transition: all 0.3s;
}
.card-condenced:hover {
  border: 1px solid #26b4ff;
}
</style>