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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<template>
  <div id="mdcLogLayout" style="width: 100%; height: 100%; overflow: hidden">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="4" :sm="4">
            <a-form-item label="设备编号">
              <a-input placeholder="请选择设备" readOnly v-model="queryParams.equipmentId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="6">
            <a-form-item label="设备名称">
              <a-input placeholder="请选择设备" readOnly v-model="queryParams.equipmentName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="4">
            <a-form-item label="日期">
              <a-date-picker v-model="queryParams.collectTimeStr" :disabledDate="disabledDate"
                             value-format='YYYY-MM-DD'/>
            </a-form-item>
          </a-col>
          <a-col :md="2" :sm="2" :xs="2">
            <a-space>
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload">重置</a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
    </div>
 
    <div>
      <div class="equipment-status-container">
        <a href="#" @click="openWorkChart">
          <img src="@/assets/image/linechart.png" alt="">
          <div>工作曲线</div>
        </a>
 
        <div>
          <div :style='{display: "inline-block",width:item.dateProportion,  height: "100%"}' v-for="item in normal">
            <span v-if="item.status == 0"
                  :style='{display: "inline-block",width:item.dateProportion,  height: "100%", background: "#A8A8A8",position:"absolute",top:"0"}'></span>
            <span v-if="item.status == 1"
                  :style='{display: "inline-block",width:item.dateProportion,  height: "100%", background: "#fffc5c",position:"absolute",top:"0"}'></span>
            <span v-if="item.status == 2"
                  :style='{display: "inline-block",width:item.dateProportion,  height: "100%", background: "#fffc5c",position:"absolute",top:"0"}'></span>
            <span v-if="item.status == 3"
                  :style='{display: "inline-block",width:item.dateProportion,  height: "100%", background: "#19FE01",position:"absolute",top:"0"}'></span>
            <span v-if="item.status == 23"
                  :style='{display: "inline-block",width:item.dateProportion,  height: "100%", background: "#19FE01",position:"absolute",bottom:"0"}'></span>
          </div>
          <div v-if="item.status == 22"
               :style='{display: "inline-block",left:item.left,width:item.dateProportion,  height: "100%",position:"absolute"}'
               v-for="item in warning">
                            <span
                              :style='{display: "inline-block",width:"100%", left:0, height: "68%", background: "#FD0008",position:"absolute",bottom:"0"}'></span>
          </div>
          <div v-if="item.status == 25"
               :style='{display: "inline-block",left:item.left,width:item.dateProportion,  height: "100%",position:"absolute"}'
               v-for="item in fault">
                            <span
                              :style='{display: "inline-block",width:"100%", left:0, height: "50%", background: "#C11900",position:"absolute",bottom:"0"}'></span>
          </div>
        </div>
 
        <a href="#" @click="openHistoryChart">
          <img src="@/assets/image/Histogram.png" alt="">
          <div>历史记录</div>
        </a>
      </div>
 
      <div class="time-container">
        <div>0</div>
        <div>
          <div v-for="item in 12">{{('0'+item*2).slice(-2)}}:00</div>
        </div>
        <div></div>
      </div>
 
      <a-space class="date-change-container">
        <img @click="dataBefore" src="@/assets/image/left.png" alt="">
        <span>关机</span>
        <div style="background-color: #A8A8A8"/>
        <span>待机</span>
        <div style="background-color: #ffea91"/>
        <span>运行</span>
        <div style="background-color: #00ee00"/>
        <span>报警</span>
        <div style="background-color: #f00"/>
        <span>故障</span>
        <div style="background-color: #C11900"/>
        <img @click="dataAfter" src="@/assets/image/right.png" alt="">
      </a-space>
    </div>
 
    <div id="mdcLogTabs" class="mdcLogTabs-title">
      <div>
        <a-tabs>
          <a-tab-pane key="1" tab="设备日志" force-render>
            <log-list :dataList='normalList' :loading='loading'/>
          </a-tab-pane>
          <a-tab-pane key="2" tab="运行日志">
            <work-log-list :dataList='runList' :loading="loading"/>
          </a-tab-pane>
          <a-tab-pane key="3" tab="报警日志">
            <alarm-log-list :dataList='warningList' :loading="loading"/>
          </a-tab-pane>
          <a-tab-pane key="4" tab="故障日志">
            <fault-log-list :dataList='faultList' :loading="loading"/>
          </a-tab-pane>
        </a-tabs>
      </div>
    </div>
 
    <work-chart-model ref="workChartModel" :collectTime="this.queryParams.collectTime"
                      :equipment="equipment"/>
 
    <work-history-model ref="workHistoryModel"/>
  </div>
</template>
 
 
<script>
  import moment from 'moment'
  import LogList from './LogList'
  import WorkLogList from './WorkLogList'
  import AlarmLogList from './AlarmLogList'
  import FaultLogList from './FaultLogList'
  import WorkChartModel from './WorkChartModel'
  import WorkHistoryModel from './WorkHistoryModel'
  import { getAction } from '@/api/manage'
 
  export default {
    components: {
      FaultLogList,
      LogList,
      WorkLogList,
      AlarmLogList,
      WorkChartModel,
      WorkHistoryModel
    },
    props: { equipment: {} },
    data() {
      return {
        queryParam: {},
        queryParams: {
          collectTimeStr: moment().format('YYYY-MM-DD')
        },
        loading: false,
        normal: [],
        warning: [],
        fault: [],
        normalList: [],
        warningList: [],
        faultList: [],
        runList: [],
        url: {
          getEquipmentByPid: '/mdc/mdcEquipment/getEquipmentByPid',
          list: '/mdc/mdcEquipmentRunningSection/logList'
        }
      }
    },
    methods: {
      disabledDate(current) {
        return current && current > moment().subtract('days', 0)
      },
      queryChart() {
        this.loading = true
        this.normalList = []
        this.warningList = []
        this.runList = []
        this.faultList = []
        this.normal = []
        this.warning = []
        this.fault = []
        getAction(this.url.list, this.queryParams)
          .then((res) => {
            if (res.success) {
              if (res.result != null) {
                for (let i = 0; i < res.result.length; i++) {
                  this.normalList.push(res.result[i])
                  res.result[i].dateProportion = res.result[i].duration / 86400 * 100 + '%'
                  if ('22' == res.result[i].status) {
                    let leftTmp = (moment(res.result[i].startTime, 'YYYY-MM-DD HH:mm:ss').valueOf() - 57600000) / 1000 % 86400
                    res.result[i].left = leftTmp / 86400 * 100 + '%'
                    this.warning.push(res.result[i])
                    this.warningList.push(res.result[i])
                  } else if ('25' == res.result[i].status) {
                    let leftTmp = (moment(res.result[i].startTime, 'YYYY-MM-DD HH:mm:ss').valueOf() - 57600000) / 1000 % 86400
                    res.result[i].left = leftTmp / 86400 * 100 + '%'
                    this.faultList.push(res.result[i])
                    this.fault.push(res.result[i])
                  } else if ('3' == res.result[i].status) {
                    this.runList.push(res.result[i])
                    this.normal.push(res.result[i])
                  } else {
                    this.normal.push(res.result[i])
                  }
                }
              }
            }
          })
          .finally(() => {
            this.loading = false
          })
      },
      searchQuery() {
        if (!this.queryParams.equipmentId || !this.queryParams.equipmentName) {
          this.$notification.warning({
            message: '消息',
            description: '请选择设备进行查询'
          })
          return
        }
        this.queryChart()
      },
      searchReset() {
        this.queryParams = {
          collectTimeStr: moment().format('YYYY-MM-DD')
        }
        this.equipment = {}
        this.queryChart()
      },
      openWorkChart() {
        if (!this.equipment.equipmentId) {
          this.$notification.warning({
            message: '消息',
            description: '请选择设备进行查询'
          })
          return
        }
 
        // 判断是否点击设备日志表格行的数据,此时为点击表格数据为false
        this.$refs.workChartModel.isClicklogListRow = false
        this.$refs.workChartModel.add(this.equipment)
        this.$refs.workChartModel.title = '工作曲线'
      },
      openHistoryChart() {
        if (!this.equipment.equipmentId) {
          this.$notification.warning({
            message: '消息',
            description: '请选择设备进行查询'
          })
          return
        }
 
        this.$refs.workHistoryModel.add(this.equipment)
        this.$refs.workHistoryModel.title = '历史日志'
      },
      dataBefore() {
        this.queryParams.collectTimeStr = moment(this.queryParams.collectTimeStr).add(-1, 'd').format('YYYY-MM-DD')
        this.searchQuery()
      },
      dataAfter() {
        if (moment(this.queryParams.collectTimeStr).isSame(moment(), 'd')) {
          this.$notification.warning({
            message: '消息',
            description: '请选择今天以及今天之前的日期!!'
          })
          return
        }
        this.queryParams.collectTimeStr = moment(this.queryParams.collectTimeStr).add(1, 'd').format('YYYY-MM-DD')
        this.searchQuery()
      },
      initEquipment(id) {
        let _this = this
        getAction(this.url.getEquipmentByPid, { pid: id }).then((res) => {
          if (res.success) {
            if (res.result != null) {
              _this.$set(this.queryParams, 'equipmentName', res.result.equipmentName)
              _this.$set(this.queryParams, 'equipmentId', res.result.equipmentId)
              _this.$emit('initEquipment', res.result)
            } else {
              _this.queryParams = {}
              _this.$emit('initEquipment', {})
              _this.$notification.warning({
                message: '消息',
                description: '请联系管理员,开放设备权限!'
              })
            }
          } else {
            _this.$notification.warning({
              message: '消息',
              description: res.message
            })
 
          }
        })
      }
    },
    created() {
      this.initEquipment()
    },
    watch: {
      equipment(val) {
        if (val && val.equipmentId) {
          this.$set(this.queryParams, 'equipmentName', val.equipmentName)
          this.$set(this.queryParams, 'equipmentId', val.equipmentId)
          this.searchQuery()
        } else {
          this.initEquipment(val.key)
        }
      }
    }
  }
</script>
 
<style scoped="scoped" lang="less">
  @image-container-width: 58px;
 
  .equipment-status-container {
    display: flex;
 
    > a {
      display: inline-block;
      text-align: center;
      width: @image-container-width
    }
 
    > div {
      height: 62px;
      border: 1px solid #9d9d9d;
      position: relative;
      overflow: hidden;
      flex: 1
    }
  }
 
  .time-container {
    display: flex;
    align-items: center;
 
    > div:not(:nth-child(2)) {
      width: @image-container-width;
      text-align: right;
    }
 
    > div:nth-child(2) {
      width: calc(100% - @image-container-width * 2);
      display: flex;
 
      div {
        width: calc(100% / 12);
        text-align: right;
      }
    }
  }
 
  .date-change-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
 
    /deep/ .ant-space-item {
      display: flex;
      align-items: center;
 
      > div {
        width: 15px;
        height: 15px;
      }
    }
 
    img {
      cursor: pointer;
    }
  }
</style>