doum
2026-06-18 93de43267e1663031fe5dc2f5ae40d128a182a76
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
<template>
  <GlobalWindow title="编辑空调内机" :visible.sync="visible" width="720px" :confirm-working="isWorking" @confirm="confirm">
    <el-form ref="form" :model="form" label-width="120px" class="conditioner-edit-form">
      <el-form-item label="设备名称">
        <span>{{ form.name || '-' }}</span>
      </el-form-item>
      <el-form-item label="设备编号">
        <span>{{ form.code || '-' }}</span>
      </el-form-item>
      <el-form-item label="网关MAC">
        <span>{{ form.wgMac || '-' }}</span>
        <span :class="isOnline ? 'green' : 'red'" style="margin-left: 12px">{{ form.online || '离线' }}</span>
      </el-form-item>
      <el-form-item label="设备类型">
        <span>{{ form.devTypeName || form.pid || '-' }}</span>
      </el-form-item>
      <el-form-item label="请选择房源">
        <el-tree
          ref="roomTree"
          :data="houseList"
          show-checkbox
          node-key="idd"
          :props="{ children: 'projectDataVOList', label: 'name' }"
          :default-checked-keys="checkedKeys"
          @check="onRoomCheck"
          style="max-height: 320px; overflow: auto; width: 400px; border: 1px solid #dcdfe6; padding: 8px;"
        />
      </el-form-item>
      <el-form-item label="已选房源">
        <div class="selected-room-list">
          <template v-if="selectedRooms.length">
            <el-tag
              v-for="room in selectedRooms"
              :key="room.idd"
              closable
              class="selected-room-tag"
              @close="removeSelectedRoom(room)"
            >{{ room.roomPath }}</el-tag>
          </template>
          <span v-else class="selected-room-empty">-</span>
        </div>
      </el-form-item>
      <el-form-item label="备注">
        <el-input
          v-model="form.remark"
          type="textarea"
          :rows="4"
          maxlength="500"
          show-word-limit
          placeholder="请输入备注"
          style="width: 400px"
        />
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import GlobalWindow from '@/components/common/GlobalWindow'
import { tree } from '@/api/project/ywProject'
import { getManageDetail, saveManageDetail } from '@/api/business/ywconditionerdevice'
 
export default {
  name: 'YwConditionerDeviceEdit',
  components: { GlobalWindow },
  data () {
    return {
      visible: false,
      isWorking: false,
      form: {},
      houseList: [],
      checkedKeys: [],
      selectedRooms: []
    }
  },
  computed: {
    isOnline () {
      const o = this.form && this.form.online
      return o === '在线' || o === 1 || o === '1'
    }
  },
  methods: {
    open (row) {
      this.visible = true
      this.checkedKeys = []
      this.selectedRooms = []
      this.loadHouseTree()
      getManageDetail(row.id).then(data => {
        this.form = { ...data }
        if (data.roomIds && data.roomIds.length) {
          this.checkedKeys = data.roomIds.map(id => '3-' + id)
          this.$nextTick(() => {
            if (this.$refs.roomTree) {
              this.$refs.roomTree.setCheckedKeys(this.checkedKeys)
              this.syncSelectedRoomsFromTree()
            }
          })
        }
      }).catch(e => this.$tip.apiFailed(e))
    },
    loadHouseTree () {
      tree({}).then(res => {
        this.markTreeNodes(res || [])
        this.houseList = res || []
        this.$nextTick(() => {
          if (this.checkedKeys.length && this.$refs.roomTree) {
            this.$refs.roomTree.setCheckedKeys(this.checkedKeys)
            this.syncSelectedRoomsFromTree()
          }
        })
      })
    },
    markTreeNodes (arr, ancestors) {
      if (!arr) return
      arr.forEach(node => {
        node.idd = node.lv + '-' + node.id
        node.disabled = node.lv !== 3
        const names = (ancestors || []).concat(node.name)
        if (node.lv === 3) {
          node.roomPath = names.length >= 3 ? names.slice(-3).join('/') : names.join('/')
        }
        if (node.projectDataVOList && node.projectDataVOList.length) {
          this.markTreeNodes(node.projectDataVOList, names)
        }
      })
    },
    syncSelectedRoomsFromTree () {
      const treeRef = this.$refs.roomTree
      if (!treeRef) {
        this.selectedRooms = []
        return
      }
      const nodes = treeRef.getCheckedNodes(true).filter(n => n.lv === 3)
      this.selectedRooms = nodes.map(n => ({
        id: n.id,
        idd: n.idd,
        roomPath: n.roomPath || n.name
      }))
      this.form.roomIds = nodes.map(n => n.id)
      this.checkedKeys = nodes.map(n => n.idd)
    },
    removeSelectedRoom (room) {
      const treeRef = this.$refs.roomTree
      if (!treeRef || !room) return
      treeRef.setChecked(room.idd, false, true)
      this.syncSelectedRoomsFromTree()
    },
    onRoomCheck () {
      this.syncSelectedRoomsFromTree()
    },
    confirm () {
      this.isWorking = true
      saveManageDetail({
        id: this.form.id,
        roomIds: this.form.roomIds || [],
        remark: this.form.remark || ''
      })
        .then(() => {
          this.$tip.success('保存成功')
          this.visible = false
          this.$emit('success')
        })
        .catch(e => this.$tip.apiFailed(e))
        .finally(() => { this.isWorking = false })
    }
  }
}
</script>
 
<style scoped>
.green { color: #67c23a; }
.red { color: #f56c6c; }
.selected-room-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  max-width: 560px;
  min-height: 32px;
  gap: 8px;
}
.selected-room-tag {
  max-width: 100%;
  white-space: normal;
  height: auto;
  line-height: 1.5;
  padding-top: 4px;
  padding-bottom: 4px;
}
.selected-room-empty {
  color: #909399;
}
</style>