peng
2026-03-18 b89df58e3b783f3d718bd85a3e4c6a3bd9ee353c
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
<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>