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
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
<template>
  <div>
    <b-row class="row mb10">
      <b-col cols="6">
        <span>类型:</span>
        <b-select
          v-model="selectType"
          style="width: 160px; display: inline-block"
          :options="peoType"
          text-field="lable"
          value-field="lable"
          @change="handleSelectType"
        />
        <span class="ml10">姓名:</span>
        <b-form-input autocomplete="off" style="width: 200px; display: inline-block" id="search" v-model="searchValue" @keyup.enter. native="handleSearch" />
        <b-btn variant="primary" @click="handleSearch">
          <span class="fas fa-search"></span>
          搜 索
        </b-btn>
      </b-col>
      <b-col cols="6">
        <div class="fr">
          <b-dd variant="primary" text="下载模板" :right="isRTL">
            <b-dd-item @click="handleDownloadTem('stu')">学生模板</b-dd-item>
            <b-dd-item @click="handleDownloadTem('tea')">教师模板</b-dd-item>
          </b-dd>
          <b-dd variant="primary" text="批量导入" :right="isRTL">
            <b-dd-item @click="handleUpdateTem('stu')">学生模板</b-dd-item>
            <b-dd-item @click="handleUpdateTem('tea')">教师模板</b-dd-item>
          </b-dd>
          <b-btn
           variant="warning"
           @click="$router.push('/personnel/add')"
          >
            <span class="fas fa-plus"></span>
            添 加
          </b-btn>
        </div>
      </b-col>
    </b-row>
    <div class="row">
      <div class="col-md-12 col-lg-12 col-xl-3">
        <PersonnelTree
         :data="treeList"
         children="child"
         label="name"
        />
      </div>
      <div class="col-md-12 col-lg-12 col-xl-6">
        <b-card style="width: 700px; position: relative; padding-bottom: 32px;">
          <Card
            @click.native="handleDetail(item)"
            v-for="item of tableList"
            :key="item.id"
            class="fl"
            style="width: 200px; margin: 8px;"
            :body-style="{ padding: '0px' }"
          >
            <httpImg :src="item.photo" style="width: 100%" />
            <div style="padding: 14px; text-align: center">
              <span>{{item.name}}</span>
            </div>
          </Card>
          <div class="pagination">
            <b-pagination
              v-if="total"
              size="md"
              :total-rows="total"
              v-model="currentPage"
              :per-page="10"
              @change="changePage"
            />
          </div>
          <h5 v-if="!total" class="no-data">暂无数据</h5>
        </b-card>
      </div>
      <div class="col-md-12 col-lg-12 col-xl-3">
        <PersonnelDetail :item="item" @update="_initData" />
      </div>
    </div>
  </div>
</template>
 
<script>
import { Table, TableColumn, Card } from 'element-ui'
import PersonnelDetail from './component/PersonnelDetail'
import PersonnelTree from './component/PersonnelTree'
import { getUserList, getPeoType, excelDownload } from '../../server/personnel.js'
import { getOrgTree } from '../../server/project.js'
export default {
  data: () => ({
    searchValue: '',
    selectType: '',
    tableList: [],
    currentPage: 1,
    length: 6,
    total: 0,
    peoType: [],
    treeList: [],
    item: {} // 当前选择 type
  }),
  mounted() {
    this._getOrgTree()
    this._initData()
    this._initPeoType()
  },
  computed: {
    orgId() {
      return this.$store.getters.basicUserInfo.orgId
    }
  },
  methods: {
    index(index) {
      return this.currentPage > 1 ? this.length * (this.currentPage - 1) + index + 1 : index + 1
    },
    async _getOrgTree() {
      let res = await getOrgTree({
        orgById: this.orgId
      })
      if (res) {
        this.treeList = [...res]
      }
    },
    async _initPeoType() {
      let response = await getPeoType({
        orgId: this.orgId,
        type: 'PEO_TYPE'
      })
      if (response.code - 0 === 0 && response.data) {
        this.peoType = response.data
        if (this.peoType.length > 0) {
          this.selectType = this.peoType[0].lable
        }
      }
    },
    // 初始化
    async _initData(type = '') {
      let res = await getUserList({
        orgId: this.orgId,
        start: this.length * (this.currentPage - 1),
        length: this.length,
        type: type || this.selectType
      })
      if (res && res.data) {
        this.total = res.total
        this.tableList = [...res.data]
      }
    },
    // 搜索功能
    handleSearch() {
      this._initData()
    },
    // 变换类型
    handleSelectType(e) {
      // console.log(e)
      this._initData(e)
    },
    // 变换detail
    handleDetail(item) {
      this.item = item
    },
    // 分页器
    changePage(e) {
      this.currentPage = e
      this._initData()
    },
    // 下载模板
    async handleDownloadTem(type) {
      await excelDownload({ type })
    },
    // 导入
    async handleUpdateTem(type) {}
  },
  components: {
    Card,
    Table,
    TableColumn,
    PersonnelDetail,
    PersonnelTree
  }
}
</script>
 
<style lang="scss" scoped>
.pagination {
  position: absolute;
  right: 16px;
  bottom: 0px;
}
.no-data {
  text-align: center;
  margin: 60px auto 60px auto;
}
.max-img {
  max-width: 120px;
}
.person-card {
  height: 135px;
  cursor: pointer;
  transition: all 0.3s;
}
.person-card:hover {
  border: 1px solid #26b4ff;
}
</style>