liuxiaolong
2019-05-06 2418a2d61feea858e9e63aa52fd64ddfe17e392a
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
<template>
  <div class="pb-4">
    <h5 class="pt-2 table-title">集群列表<small class="text-primary pl-2">( {{total}} )</small></h5>
    <hr/>
    <div class="py-2" v-for="(item,index) in treeList" :key="index">
      <div class="pb-2 flex-row-between">
        <h5 class="pt-2 table-title">集群名称:{{item.name}}</h5>
        <!-- <h5>集群ID:{{item.id}}</h5> -->
        <b-btn variant="primary" @click="handleDel(item.id)">
          退出集群
        </b-btn>
      </div>
      <treeTable class="mb-4" :width="100" v-if="item && item.child && item.child.length" :expandAll="false" border :data="item.child" :columns="columns">
        <TableColumn label="操作">
          <template slot-scope="scope">
            <fButton
              size="sm"
              type="link"
              @click.native="handleCheck(scope.row)"
              authority="device:colonyList:check"
              >
                查看
              </fButton>
            <span v-if="!scope.row.type||scope.row.type!=='摄像机'">
              <fButton
                size="sm"
                type="link"
                @click.native="handlEdeitVideoUrl(scope.row)"
                authority="device:colonyList:setting"
                >
                  配置地址
              </fButton>
            </span>
              <fButton v-if="scope.row.type && scope.row.type==='摄像机'"
                size="sm"
                type="link"
                @click.native="handlEdeitOrg(scope.row)"
                authority="device:colonyList:editOrg"
                >
                  编辑组织机构
              </fButton>
          </template>
        </TableColumn>
      </treeTable>
    </div>
    <iframe-model
      :item="null"
      ref="iframeModel"
      @submit="()=>{}"
      :isShowFooter="false"
    />
    <addVideoUrl
      :item="null"
      ref="addVideoUrl"
      title="配置地址"
      @submit="_initData"
      :isShowFooter="false"
    />
    <editOrg
      ref="editOrg"
      title="配置机构"
      :isShowFooter="false"
    />
  </div>
</template>
<script>
import { Table, TableColumn } from 'element-ui'
import { getColonyList, delColony } from '@/server/home.js'
import treeTable from '@/components/TreeTable'
import iframeModel from '../components/iframeModel'
import addVideoUrl from '../components/addVideoUrl'
import editOrg from '../components/editOrg'
export default {
  name: 'table-colony',
  metaInfo: {
    title: '集群设备'
  },
  components: {
    treeTable,
    Table,
    TableColumn,
    iframeModel,
    addVideoUrl,
    editOrg
  },
  props: {
    orgId: { default: '0', type: String },
    searchName: {
      default: '',
      type: String
    },
    currentColonyItem: {
      default: () => ({ id: '0', type: '1', name: '集群设备' }),
      type: Object
    },
    analysis: {
      default: '',
      type: String
    }
  },
  data() {
    return {
      total: 0,
      treeList: [],
      typeListAll: [],
      columns: [
        {
          text: '类型',
          value: 'type',
          width: '250'
        },
        // {
        //   text: 'ID',
        //   value: 'id',
        //   width: '300'
        // },
        {
          text: '名称',
          value: 'name',
          width: '300'
        },
        {
          text: 'IP地址',
          value: 'ip',
          width: '150'
        },
        {
          text: '位置',
          value: 'address',
          width: '300'
        },
        {
          text: '区域',
          value: 'orgName',
          width: '200'
        }
      ]
    }
  },
  computed: {
    userName() {
      return this.$store.getters.basicUserInfo.username
    }
  },
  methods: {
    // * 初始化
    async _initData() {
      const { type = '1', id = '0' } = this.currentColonyItem
      let res = await getColonyList({
        id: id,
        type: type,
        condition: this.searchName
      })
      if (res && res.success && res.code === 200 && res.data) {
        this.treeList = res.data
        this.total = res.data.length
      } else {
        this.$toast({
          type: 'error',
          message: res && res.msg ? res.msg : '列表查询失败!'
        })
      }
    },
    async delColony(json) {
      let res = await delColony(json)
      if (res.success && res.code === 200) {
        /* 成功操作 */
        this._initData()
        this.$emit('del-colony-success')
        this.$toast({
          type: 'success',
          message: res && res.msg ? res.msg : '退出集群成功'
        })
        // this.$swal(
        //   '删除成功!',
        //   res && res.msg ? res.msg : '退出集群成功',
        //   'success'
        // )
      } else {
        this.$toast({
          type: 'error',
          message: res && res.msg ? res.msg : '退出集群失败!'
        })
        // this.$swal(
        //   '删除失败!',
        //   res && res.msg ? res.msg : '退出集群成功',
        //   'error'
        // )
      }
    },
    handleDel(id) {
      this.$swal(
        {
          title: '确定退出集群?',
          text: '输入集群密码才能退出',
          showCancelButton: true,
          allowOutsideClick: true,
          // confirmButtonColor: '#d9534f',
          confirmButtonText: '确定退出!',
          cancelButtonText: '取消',
          // closeOnConfirm: true,
          content: 'input',
          type: 'input',
          inputType: 'password'
        },
        (inputValue, e) => {
          console.log(inputValue, '----', e)
          if (!inputValue && inputValue !== '') {
            return false
          }
          if (inputValue === '') {
            this.$toast({
              type: 'error',
              message: '必须输入密码才能删除'
            })
            // this.$swal('删除失败!', '必须输入密码才能删除', 'error')
          } else {
            this.delColony({ id, cookie: inputValue })
          }
        }
      )
    },
    handleCheck(data) {
      console.log(this.analysis, '这事后台要的', 'data', data)
      if (data.type === '分析设备') {
      }
      if (data.type === '摄像机') {
      }
      this.$refs.iframeModel.showModal({
        ...data,
        analysis: this.analysis,
        userName: this.userName
      })
      // `${ip}:${port}/ManCarAnaly/login?username=sysuser-${this.analysis}-${this.userName}&password=sysuser`
    },
    handlEdeitVideoUrl(data) {
      this.$refs.addVideoUrl.showModel(data)
    },
    handlEdeitOrg(data) {
      console.log(data, 'data')
      this.$refs.editOrg.showModel(data)
    }
  },
  created() {},
  /* async mounted() {
    await this._initData()
    treeListComputed = [...this.treeList]
  }, */
  watch: {
    currentColonyItem: {
      handler(newVal, oldVal) {
        if (newVal !== oldVal) {
          // 触发 org 查询平台设备列表
          this._initData()
        }
      },
      deep: true,
      immediate: true
    }
  }
}
</script>
<style lang="scss">
.table-title {
  font-size: 16px;
  font-weight: 600;
  // color: #868686;
}
</style>