<template>
|
<a-modal centered width="40%" v-model="visibleShow" title="下发" @cancel="cancelClick" @ok="onsubmit">
|
<div class="treeBox">
|
<a-input-search style="margin-bottom: 8px" placeholder="搜索" @search="onSearchChange" />
|
<a-tree
|
v-model="checkedKeys"
|
@check="checkTree"
|
checkable
|
:auto-expand-parent="autoExpandParent"
|
:tree-data="treeData"
|
@expand="onExpand"
|
:replace-fields="replaceFields"
|
:expanded-keys="expandedKeys"
|
/>
|
</div>
|
</a-modal>
|
</template>
|
|
<script>
|
import { searchByKeywords } from '@tievd/cube-block/lib/api/api'
|
import { getAction, postAction } from '@tievd/cube-block/lib/api/manage'
|
|
export default {
|
created() {
|
this.init()
|
},
|
props: {
|
visible: {
|
type: Boolean,
|
default: false,
|
},
|
upgradeId: {
|
type: Number,
|
default: 0,
|
},
|
},
|
data() {
|
return {
|
expandedKeys: [],
|
autoExpandParent: true,
|
visibleShow: false,
|
treeData: [],
|
checkedKeys: [],
|
queryForm: {
|
upgradeId: 0,
|
deviceId: [],
|
},
|
replaceFields: {
|
children: 'children',
|
title: 'departName',
|
key: 'id',
|
},
|
}
|
},
|
watch: {
|
visible(val) {
|
this.visibleShow = val
|
},
|
/* checkedKeys(val) {
|
this.queryForm.deviceId = val
|
},*/
|
upgradeId(val) {
|
this.queryForm.upgradeId = val
|
},
|
},
|
methods: {
|
checkTree(e, n) {
|
this.queryForm.deviceId = []
|
for (let i = 0; i < n.checkedNodes.length; i++) {
|
let data = n.checkedNodes[i].data.props
|
if (data.orgCategory === '99999') {
|
this.queryForm.deviceId.push(data.id)
|
}
|
}
|
},
|
onExpand(expandedKeys) {
|
this.expandedKeys = expandedKeys
|
this.autoExpandParent = false
|
},
|
onsubmit() {
|
if (this.queryForm.deviceId.length == 0) {
|
this.$message.error('请选择下发的设备')
|
return
|
}
|
postAction('/jyz/upgrade/issue', this.queryForm).then((res) => {
|
if (res.code == 200) {
|
this.$message.success(res.message)
|
this.$emit('modalClose')
|
} else {
|
this.$message.error(res.message)
|
}
|
})
|
},
|
onCheck(checkedKeys) {
|
this.checkedKeys = checkedKeys
|
},
|
// 搜索框
|
onSearchChange(value) {
|
if (value) {
|
getAction('/jyz/device/searchBy', { keyWord: value }).then((res) => {
|
if (res.success) {
|
this.treeData = []
|
for (let i = 0; i < res.result.length; i++) {
|
let temp = res.result[i]
|
this.treeData.push(temp)
|
}
|
this.mapTreeData(this.treeData)
|
} else {
|
this.$message.error(res.message)
|
}
|
})
|
} else {
|
this.init()
|
}
|
},
|
// 递归实现a-tree默认展开所有节点
|
mapTreeData(treeData) {
|
let setExpandKeys = this.expandedKeys
|
treeData.forEach((child) => {
|
if (child.children && child.children.length > 0) {
|
this.mapTreeData(child.children)
|
}
|
if (child.id) {
|
setExpandKeys.push(child.id)
|
}
|
if (child.status === '2') {
|
child.disableCheckbox = true
|
}
|
})
|
this.expandedKeys = [...setExpandKeys]
|
},
|
// 初始化
|
init() {
|
getAction('/jyz/device/queryTreeList').then((res) => {
|
if (res.code == 200) {
|
this.treeData = res.result
|
this.mapTreeData(this.treeData)
|
}
|
})
|
},
|
// 点击关闭或者是遮罩发射关闭信号给父组件,控制关闭
|
cancelClick() {
|
this.$emit('modalClose')
|
},
|
},
|
}
|
</script>
|
<!-- @import '~@assets/less/dialog.less'; -->
|
<style scoped lang="less">
|
.treeBox {
|
height: 400px;
|
overflow-y: auto;
|
}
|
</style>
|