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
<template>
  <TableLayout :permissions="['business:ywconditioner:query']">
    <template v-slot:table-wrap>
      <ul class="toolbar">
        <li>
          <el-button
            type="primary"
            :loading="isSyncing"
            v-permissions="['business:ywconditioner:sync']"
            @click="handleSync"
          >同步空调内机</el-button>
        </li>
      </ul>
      <el-table v-loading="isWorking.search" :data="tableData.list" stripe>
        <el-table-column label="设备类型" min-width="100" align="center" show-overflow-tooltip>
          <template slot-scope="{ row }">{{ formatDeviceType(row) }}</template>
        </el-table-column>
        <el-table-column label="设备ID" min-width="140" align="center" show-overflow-tooltip>
          <template slot-scope="{ row }">{{ row.code || '-' }}</template>
        </el-table-column>
        <el-table-column prop="name" label="设备名称" min-width="140" align="center" show-overflow-tooltip>
          <template slot-scope="{ row }">{{ row.name || row.code || '-' }}</template>
        </el-table-column>
        <el-table-column prop="wgMac" label="网关MAC" min-width="140" align="center" show-overflow-tooltip />
        <el-table-column prop="roomNames" label="绑定房间" min-width="160" align="center" show-overflow-tooltip>
          <template slot-scope="{ row }">{{ row.roomNames || '-' }}</template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" min-width="160" align="center" show-overflow-tooltip>
          <template slot-scope="{ row }">{{ row.remark || '-' }}</template>
        </el-table-column>
        <el-table-column label="设备状态" min-width="90" align="center">
          <template slot-scope="{ row }">
            <span :class="isOnline(row) ? 'green' : 'red'">{{ row.online || '离线' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="更新时间" min-width="150" align="center" show-overflow-tooltip>
          <template slot-scope="{ row }">{{ formatUpdateTime(row) }}</template>
        </el-table-column>
        <el-table-column label="操作" align="center" min-width="90" fixed="right">
          <template slot-scope="{ row }">
            <el-button type="text" @click="openEdit(row)" v-permissions="['business:ywconditioner:update']">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination @size-change="handleSizeChange" @current-change="handlePageChange" :pagination="tableData.pagination" />
    </template>
    <YwConditionerDeviceEdit ref="editWindow" @success="handlePageChange" />
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import * as deviceApi from '@/api/business/ywconditionerdevice'
import YwConditionerDeviceEdit from './components/YwConditionerDeviceEdit'
 
export default {
  name: 'YwConditionerDevice',
  extends: BaseTable,
  components: { TableLayout, Pagination, YwConditionerDeviceEdit },
  data () {
    return {
      isSyncing: false
    }
  },
  created () {
    this.module = '空调设备管理'
    this.configData['field.id'] = 'id'
    this.configData['field.main'] = 'name'
    this.tableData.pagination.pageSize = 10
    this.search()
  },
  methods: {
    handlePageChange (pageIndex) {
      this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
      this.isWorking.search = true
      deviceApi.fetchDeviceManagePage({
        page: this.tableData.pagination.pageIndex,
        capacity: this.tableData.pagination.pageSize,
        model: {},
        sorts: this.tableData.sorts
      })
        .then(data => {
          this.tableData.list = data.records || []
          this.tableData.pagination.total = data.total || 0
        })
        .catch(() => {})
        .finally(() => { this.isWorking.search = false })
    },
    formatDeviceType (row) {
      if (row.devTypeName) return row.devTypeName
      const pid = (row.pid || '').toLowerCase()
      if (pid === 'dlj') return '多联机'
      if (pid === 'sj') return '水机'
      return row.pid || '-'
    },
    isOnline (row) {
      const o = row && row.online
      return o === '在线' || o === 1 || o === '1'
    },
    formatUpdateTime (row) {
      const val = row.lastSyncDate || row.editDate
      if (!val) return '-'
      const text = String(val)
      return text.length >= 16 ? text.slice(0, 16) : text
    },
    handleSync () {
      this.$dialog.actionConfirm('确认从智精灵平台同步空调内机设备信息吗?', '同步空调内机')
        .then(() => {
          this.isSyncing = true
          deviceApi.syncDevicesAndStatus()
            .then(res => {
              this.$tip.apiSuccess(res || '同步成功')
              this.search()
            })
            .catch(e => this.$tip.apiFailed(e))
            .finally(() => { this.isSyncing = false })
        })
        .catch(() => {})
    },
    openEdit (row) {
      this.$refs.editWindow.open(row)
    }
  }
}
</script>
 
<style scoped>
.green { color: #67c23a; }
.red { color: #f56c6c; }
</style>