riku
2024-11-14 ae234efb788bca2fa77f700442427996fa7f4aca
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
<template>
  <div class="main">
    <!-- 选项 -->
    <!-- 设备类型  -->
    <el-row>
      <el-col>
        <span>设备类型:</span>
      </el-col>
      <el-col>
        <el-tabs class="child_select" placeholder="设备类型" v-model="currSelect.deviceTypeId">
          <el-tab-pane v-for="item in deviceTypes" :name="item.id" :label="item.label" />
        </el-tabs>
      </el-col>
    </el-row>
    <!-- 设备展示 -->
    <div class="devices">
      <el-card class="layout" shadow="hover" v-for="item of cardData">
        <div class="table-row">
          <span class="table-cell">站点: {{ item.diName || item.piName || item.wiName }}</span>
          <span class="table-cell"
            >供应商: {{ item.diSupplier || item.piSupplier || item.wiSupplier }}</span
          >
        </div>
        <div class="table-row">
          <span class="table-cell"
            >运维商: {{ item.diMaintainer || item.piMaintainer || item.wiMaintainer }}</span
          >
          <span class="table-cell"
            >运维频次:
            {{
              maintainFrequencysMap.get(
                item.diMaintainFrequency || item.piMaintainFrequency || item.wiMaintainFrequency
              )
            }}</span
          >
        </div>
        <div class="table-row">
          <span class="table-cell"
            >运维人员:
            {{ item.diMaintainStaff || item.piMaintainStaff || item.wiMaintainStaff }}</span
          >
          <span class="table-cell"
            >运维联系方式:
            {{ item.diMaintainTel || item.piMaintainTel || item.wiMaintainTel }}</span
          >
        </div>
        <div class="table-row">
          <span class="table-cell"
            >品牌型号: {{ item.diBrandModel || item.piBrandModel || item.wiBrandModel }}</span
          >
          <span class="table-cell"
            >运行状态:
            {{
              runStatusMap.get(item.diRunningStatus || item.piRunningStatus || item.wiRunningStatus)
            }}
          </span>
        </div>
        <div class="table-row">
          <span class="table-cell"
            >位置: {{ item.dlLocation || item.piLocation || item.wiLocation }}</span
          >
          <!-- The second cell is empty to maintain the two-field per row layout -->
          <span class="table-cell"></span>
        </div>
        <el-image
          class="pic-style"
          :src="item.picUrl"
          fit="cover"
          :preview-src-list="Array.of(item.picUrl)"
        />
      </el-card>
      <!-- 数据为空时 -->
      <div class="empty" v-if="isEmpty">
        <h3>暂无数据</h3>
      </div>
    </div>
  </div>
</template>
<script>
import deviceApi from '@/api/fysp/deviceApi';
import { $fysp } from '@/api/index';
export default {
  props: {},
  mounted() {},
  watch: {
    // 选择改变监听
    currSelect: {
      handler(newObj, oldObj) {
        this.getList();
      },
      deep: true
    }
  },
  data() {
    return {
      // 无数据
      isEmpty: false,
      // 双向绑定
      currSelect: {
        deviceTypeId: 0
      },
      // 场景类型
      sceneType: '',
      // 场景id
      sceneId: null,
      // 选项
      scenes: [],
      // 根据场景类型决定的设备类型
      iDevTypes: [
 
      ],
      deviceTypes: [
        { id: 0, label: '监控' },
        { id: 1, label: '治理' },
        { id: 2, label: '生产' }
      ],
      // 数据
      cardData: [],
      // 运行状态
      runStatusMap: new Map(
        [
          { key: 0, value: '未联网' },
          { key: 1, value: '上线中' },
          { key: 2, value: '下线' },
          { key: 3, value: '拆除' }
        ].map((item) => [item.key, item.value])
      ),
 
      // 维护频率状态
      maintainFrequencysMap: new Map(
        [
          { key: '1', value: '每月一次' },
          { key: '2', value: '每季度一次' },
          { key: '3', value: '每半年一次' },
          { key: '4', value: '每年一次' }
        ].map((item) => [item.key, item.value])
      )
    };
  },
  methods: {
    // 父组件主动传值
    init(scene) {
      this.sceneId = scene.guid;
      this.sceneType = scene.type;
      this.iDevTypes = dataMonitorDeviceTypeJs.monitorDevices(this.sceneType)
      this.getList();
    },
    isShowEmpty(data) {
      if (data.length == 0) {
        this.isEmpty = true;
        return true;
      } else {
        this.isEmpty = false;
        return false;
      }
    },
    // 重置展示的数据
    initList() {
      this.tableData = [];
    },
    // 字段名拦截器
    propNameConvert(obj, name) {
      name = String(name).substring(1)
      return obj['d'+name] || obj['p'+name] || obj['w'+name]
    },
    getList() {
      this.initList();
      var devicesInfoList = [];
      deviceApi.fetchDevices(this.sceneId, this.currSelect.deviceTypeId).then((result) => {
        devicesInfoList = result.data;
        this.cardData = [];
        if (this.isShowEmpty(devicesInfoList)) {
          return;
        }
        if (devicesInfoList) {
          devicesInfoList.forEach((e) => {
            let data = {
              deviceId: this.propNameConvert(e, 'diId'),
              sceneId: this.propNameConvert(e, 'diSceneGuid'),
              deviceTypeId: this.currSelect.deviceTypeId
            };
            deviceApi
              .fetchDeviceStatus(data)
              .then((status) => {
                var statusData = status.data;
                if (statusData && statusData instanceof Array) {
                  if (statusData.length == 0) {
                    this.cardData.push(e);
                    return;
                  }
                  statusData.forEach((imgItem) => {
                    e.picUrl = $fysp.imgUrl + imgItem.dlPicUrl;
                    e.dlLocation = imgItem.dlLocation;
                    this.cardData.push(e);
                  });
                }
              })
              .catch((err) => {});
          });
        }
      });
    }
  }
};
</script>
<style scoped>
.selects {
  display: flex;
}
.child_select {
  margin-right: 10px;
}
.table-row {
  display: flex;
  justify-content: space-between;
}
.table-cell {
  flex-basis: calc(50% - 10px); /* Adjust the width and margin as needed */
  border: 1px solid #ddd; /* Add border to mimic table cell */
  padding: 8px;
  text-align: center;
}
.pic-style {
  margin-top: 10px;
  width: 100%;
  height: 400px;
}
.empty {
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>