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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<template>
  <div class="clients-wrapper" style="position: initial;" :class="{'clients-sidebox-open': sideboxOpened}">
    <div class="clients-content clients-scroll container-p-x container-p-y overflow-y">
      <!-- Header -->
      <h4 class="d-flex flex-wrap justify-content-between align-items-center font-weight-bold pt-2 mb-2">
        <div class="mb-2">设备地图管理</div>
        <div class="mb-2" style="max-width: 200px;">
          <fButton
              type="warning"
              @click.native="()=>{$router.push({path:'/mapdevice/mapadd'})}"
              authority="sys:mapdevice:mapadd"
            >
              <span class="fas fa-plus pr10"></span>
              添加地图
            </fButton>
        </div>
      </h4>
      <!-- / Header -->
 
      <!-- 设备列表 -->
      <b-card no-body>
          <!-- 检索 start -->
          <b-card-header header-tag="h4" class="media flex-wrap align-items-center py-4">
            <b-form-select style="max-width: 10rem;" v-model="modules" @change="(e)=>{modules = e;_initData()}" text-field="lable" :options="newSysDicts" class="mr10"/>
            <b-input
              placeholder="地图名称..."
              autocomplete="off"
              style="max-width: 20rem;"
              class="mr10"
              v-model="name"
              @keyup.enter.native="handleSearch"
            />
            <b-btn variant="primary" class="mr10" @click="handleSearch"><span class="fs fas-search"></span>搜索</b-btn>
          </b-card-header>
          <!-- 检索 end -->
          <div class="pl20 pr20 pt10 pb30">
            <Table
              :data="newTableList"
              highlight-current-row
              ref="leftTable"
            >
              <TableColumn
                type="index"
                prop="index"
                label="序号"
                :index="snMethod"
                width="50"
              />
              <TableColumn
                label="顺序编码"
                prop="no"
                width="80">
              </TableColumn>
              <TableColumn
                label="地图名称"
                prop="name"
              />
              <TableColumn
                label="地图应用系统"
                prop="modulesName"
              />
              <TableColumn
                label="更新时间"
                prop="updateTime"
                width="200"
              />
              <TableColumn
                label="操作"
                width="280"
              >
                <template slot-scope="scope">
                  <div @click.stop>
                  <b-btn
                    variant="link"
                    style="padding:2px;"
                    authority="sys:mapdevice:check"
                    @click.self="$router.push({path:'/mapdevice/add',query:{id:scope.row.id, type:'check'}})"
                  >
                    查看
                  </b-btn>
                  <fButton
                    type="link"
                    style="padding:2px;"
                    authority="sys:mapdevice:mapedit"
                    @click.native.self="$router.push({path:'/mapdevice/mapadd',query:{id:scope.row.id}})"
                  >
                    编辑地图
                  </fButton>
                  <fButton
                    type="link"
                    style="padding:2px;"
                    authority="sys:mapdevice:mapdeviceedit"
                    @click.native.self="$router.push({path:'/mapdevice/add',query:{id:scope.row.id, type:'edit'}})"
                  >
                    编辑设备
                  </fButton>
                  <fButton
                    type="link"
                    style="padding:2px;"
                    @click.native="handleDel(scope.row.id)"
                    authority="sys:device:delete"
                  >
                    删除
                  </fButton>
                  </div>
                </template>
              </TableColumn>
            </Table>
            <div class="pt20 pb20">
              <b-pagination class="justify-content-center justify-content-sm-end m-0"
                v-if="total"
                v-model="activePage"
                :total-rows="total"
                :per-page="pageSize"
              />
            </div>
          </div>
        </b-card>
      <!-- / 设备列表 -->
    </div>
  </div>
 
</template>
<!-- Page -->
<script>
import { Table, TableColumn, Collapse, CollapseItem } from 'element-ui'
import { getMapList, delMap } from '@/server/mapDeviceManagement.js'
import { getSysListWithHome } from '@/server/common.js'
 
export default {
  name: 'mapDeviceManagement',
  metaInfo: {
    title: '地图设备管理'
  },
  data() {
    return {
      noneImg: 'this.src="' + require('@/assets/img/noneImg.png') + '"',
      userInfo: this.$store.getters.basicUserInfo,
 
      deviceType: '',
      deviceTypeDicts: [],
      modules: '',
      sysDicts: [],
 
      name: '',
      tableList: [],
      total: 0,
      pageSize: 10,
      activePage: 1,
 
      /* 右侧侧边栏 */
      sideboxOpened: false,
      activeCollapse: 'basic',
      deviceInfo: null
    }
  },
  computed: {
    newSysDicts() {
      return [{ value: '', lable: '全部' }, ...this.sysDicts]
    },
    newTableList() {
      let sysDicts = this.sysDicts
      let list = this.tableList.map(iteam => {
        if (iteam.modules) {
          let arr = iteam.modules.replace(/^,+|,+$/g, '').split(',')
          let strName = ''
          for (let val of arr) {
            for (let sysIteam of sysDicts) {
              if (sysIteam.value === val) {
                strName +=
                  strName === '' ? sysIteam.lable : ',' + sysIteam.lable
              }
            }
          }
          iteam.modulesName = strName
          return iteam
        }
      })
      return list
    }
  },
  methods: {
    // 关闭侧边栏
    closeSidebox() {
      /* 取消选择 */
      this.$refs.leftTable.setCurrentRow(null)
    },
    snMethod(index) {
      return this.activePage > 1
        ? this.pageSize * (this.activePage - 1) + index + 1
        : index + 1
    },
    async getSysDicts() {
      let res = await getSysListWithHome({
        orgId: this.userInfo.orgId,
        userId: this.userInfo.id,
        tags: 'device'
      })
      if (res && !res.error) {
        this.sysDicts = res
      }
    },
    /* 设备列表初始化 */
    async _initData() {
      let res = await getMapList({
        orgId: this.userInfo.orgId,
        length: this.pageSize,
        start: this.pageSize * (this.activePage - 1),
        name: this.name,
        modules: this.modules
      })
      if (res) {
        this.tableList = res.data
        this.total = res.total
      }
    },
    // 搜索
    handleSearch() {
      this._initData()
    },
    // 删除
    handleDel(id) {
      this.$swal(
        {
          title: '确定删除吗?',
          type: 'warning',
          showCancelButton: true,
          allowOutsideClick: true,
          confirmButtonText: '确定删除!',
          cancelButtonText: '取消删除!',
          closeOnConfirm: true
        },
        async () => {
          let res = await delMap({
            orgId: this.userInfo.orgId,
            id
          })
          if (res.code === 200 || res - 1 === 0) {
            // this.$swal('删除成功', `${res.msg ? res.msg : ''}`, 'success')
            this.$toast({
              type: 'success',
              message: '删除成功'
            })
            this._initData()
          } else {
            // this.$swal('删除失败', `${res.message ? res.message : ''}`, 'error')
            this.$toast({
              type: 'error',
              message: '删除失败'
            })
          }
        }
      )
    }
  },
  watch: {
    activePage(val, oldVal) {
      if (val !== oldVal) {
        this.activePage = val
        this._initData()
      }
    }
  },
  created() {
    /* 查询字典 */
    this.getSysDicts()
    /* 查询列表 */
    this._initData()
  },
  components: {
    Table,
    TableColumn,
    elCollapse: Collapse,
    elCollapseItem: CollapseItem
  }
}
</script>