gaosp
2024-01-19 5b9a1d6cb3a7d59c8f2de83c495bba1a069b2723
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<template>
  <div>
    <p class="statelists" id="theradio">
      <span><i class="icons backblack"></i><i class="textwenzi">停机({{ stopCount }})</i></span>
      <span><i class="icons backgreenyellowtitle"></i><i class="textwenzi">运行({{ runCount }})</i></span>
      <span><i class="icons backyellow"></i><i class="textwenzi">待机({{ idleCount }})</i></span>
      <span><i class="icons backgreenredtitle"></i><i class="textwenzi">报警({{ alarmCount }})</i></span>
      <span><i class="icons backwhiletitle"></i><i class="textwenzi">全部({{ allCount }})</i></span>
    </p>
    <p class="statelist" id="theradio1" style="margin-top: 50px;border-bottom: 0px">
      <span><i class="textwenzi1">开机率({{ RUN }}%)</i></span>
      <span style="margin-left: 100px;"><i class="textwenzi1">故障率({{ ALRAM }}%)</i></span>
      <span style="margin-left: 100px;"><i class="textwenzi1">切削率({{ cutRate }}%)</i></span>
      <span style="margin-left: 100px;"><i class="textwenzi1">二班开工率({{ twoShiftRate }}%)</i></span>
      <span style="margin-left: 100px;"><i class="textwenzi1">三班开工率({{ threeShiftRate }}%)</i></span>
    </p>
    <div id='drags' class="content-card">
      <ul id="lists" ref="lists">
        <li class="machinelists" v-for="(item, index) in malists" :key="index" :class="item.lie?'margintop30':''">
          <!-- 第一个 -->
          <div class="content-card" :class="{'content-card-gary':item.collectFlag == 0}" v-if="item.highScale == '1'" >
            <div class="device-img-layout" v-if="item.status != ''">
              <el-row class="paddingt10">
                <el-col :span="12" v-if="item.status == 'ALARM'">
                  <img :src="item.pic" class="mdc-machine-image margint10" @click="police(item)">
                </el-col>
                <el-col :span="12" v-else>
                  <img :src="item.pic" class="mdc-machine-image margint10" @click="showMachineDetail(item.id,item.pic)">
                </el-col>
                <el-col :span="12" class="screen">
                  <div class="mdc-machine-efficiency roomstatelist">
                    <span class="xsName xxstate">机床状态: </span>
                    <span v-if="item.status == 'STOP' || item.status == '' || item.status == null"><i class="icons backblack opacity1"></i></span>
                    <span v-if="item.status == 'RUN' || item.status == 'FEEDHOLDON'"><i class="icons backgreenyellow opacity1"></i></span>
                    <span v-if="item.status == 'IDLE'"><i class="icons backyellow opacity1"></i></span>
                    <span v-if="item.status == 'ALARM'"><i class="icons backgreenred opacity1"></i></span>
                  </div>
                  <div class="mdc-machine-efficiency margintop5"><span class="xsName">能力利用率: </span>{{ item.efficiency }}%</div>
                  <div class="mdc-machine-efficiency"><span class="xsName">日利用率: </span>{{ item.utilizationDaily }}%</div>
                  <div class="mdc-machine-efficiency"><span class="xsName">完工件数: </span>{{ item.cycleCount }}</div>
                </el-col>
              </el-row>
            </div>
            <div class="device-img-layout" v-else></div>
            <!-- 机床名称 -->
            <div class="mdc-machine-name text-center"><span class="xsName">{{ item.name }}</span></div>
          </div>
          <!-- 第二个 -->
          <div class="content-card twotwo" :class="{'content-card-gary':item.collectFlag == 0}" v-if="item.highScale == '2'">
            <div class="device-img-layout" v-if="item.status != ''">
              <el-row class="paddingt10">
                <el-col :span="12">
                  <img :src="item.pic" class="mdc-machine-image">
                </el-col>
                <el-col :span="12" class="screen">
                  <div class="mdc-machine-efficiency roomstatelist">
                    <span class="xsName xxstate">机床状态: </span>
                    <span v-if="item.status == 'STOP' || item.status == '' || item.status == null"><i class="icons backblack opacity1"></i></span>
                    <span v-if="item.status == 'RUN' || item.status == 'FEEDHOLDON'"><i class="icons backgreenyellow opacity1"></i></span>
                    <span v-if="item.status == 'IDLE'"><i class="icons backyellow opacity1"></i></span>
                    <span v-if="item.status == 'ALARM'"><i class="icons backgreenred opacity1"></i></span>
                  </div>
                  <div class="mdc-machine-efficiency margintop5"><span class="xsName">能力利用率: </span>{{ item.efficiency }}%</div>
                  <div class="mdc-machine-efficiency"><span class="xsName">日利用率: </span>{{ item.utilizationDaily }}%</div>
                  <div class="mdc-machine-efficiency"><span class="xsName">完工件数: </span>{{ item.cycleCount }}</div>
                </el-col>
              </el-row>
            </div>
            <div class="device-img-layout" v-else></div>
            <!-- 机床名称 -->
            <div class="mdc-machine-name text-center"><span class="xsName">{{ item.name }}</span></div>
          </div>
          <!-- 第三个 -->
          <div class="content-card threethree" :class="{'content-card-gary':item.collectFlag == 0}" v-if="item.highScale == '3'">
            <div class="device-img-layout" v-if="item.status != ''">
              <el-row class="paddingt10">
                <el-col :span="12">
                  <img :src="item.pic" class="mdc-machine-image">
                </el-col>
                <el-col :span="12" class="screen">
                  <div class="mdc-machine-efficiency roomstatelist">
                    <span class="xsName xxstate">机床状态: </span>
                    <span v-if="item.status == 'STOP' || item.status == '' || item.status == null"><i class="icons backblack opacity1"></i></span>
                    <span v-if="item.status == 'RUN' || item.status == 'FEEDHOLDON'"><i class="icons backgreenyellow opacity1"></i></span>
                    <span v-if="item.status == 'IDLE'"><i class="icons backyellow opacity1"></i></span>
                    <span v-if="item.status == 'ALARM'"><i class="icons backgreenred opacity1"></i></span>
                  </div>
                  <div class="mdc-machine-efficiency margintop5"><span class="xsName">能力利用率: </span>{{ item.efficiency }}%</div>
                  <div class="mdc-machine-efficiency"><span class="xsName">日利用率: </span>{{ item.utilizationDaily }}%</div>
                  <div class="mdc-machine-efficiency"><span class="xsName">完工件数: </span>{{ item.cycleCount }}</div>
                </el-col>
              </el-row>
            </div>
            <div class="device-img-layout" v-else></div>
            <!-- 机床名称 -->
            <div class="mdc-machine-name text-center"><span class="xsName">{{ item.name }}</span></div>
          </div>
          <!-- 第四个 -->
          <div class="content-card fourfour" :class="{'content-card-gary':item.collectFlag == 0}" v-if="item.highScale == '4'">
            <div class="device-img-layout" v-if="item.status != ''">
              <el-row class="paddingt10">
                <el-col :span="12">
                  <img :src="item.pic" class="mdc-machine-image">
                </el-col>
                <el-col :span="12" class="screen">
                  <div class="mdc-machine-efficiency roomstatelist">
                    <span class="xsName xxstate">机床状态: </span>
                    <span v-if="item.status == 'STOP' || item.status == '' || item.status == null"><i class="icons backblack opacity1"></i></span>
                    <span v-if="item.status == 'RUN' || item.status == 'FEEDHOLDON'"><i class="icons backgreenyellow opacity1"></i></span>
                    <span v-if="item.status == 'IDLE'"><i class="icons backyellow opacity1"></i></span>
                    <span v-if="item.status == 'ALARM'"><i class="icons backgreenred opacity1"></i></span>
                  </div>
                  <div class="mdc-machine-efficiency margintop5"><span class="xsName">能力利用率: </span>{{ item.efficiency }}%</div>
                  <div class="mdc-machine-efficiency"><span class="xsName">日利用率: </span>{{ item.utilizationDaily }}%</div>
                  <div class="mdc-machine-efficiency"><span class="xsName">完工件数: </span>{{ item.cycleCount }}</div>
                </el-col>
              </el-row>
            </div>
            <div class="device-img-layout" v-else></div>
            <!-- 机床名称 -->
            <div class="mdc-machine-name text-center"><span class="xsName">{{ item.name }}</span></div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
 
<script>
  // import { default as Bus, SCROLL_TOP, ON_MESSAGE, ON_VISIBILITY_CHANGE } from '@/bus/EventBus'
  // import { default as Bus, ON_MESSAGE } from '@/bus/EventBus'
  // import { getMachineNum, getMachineList,focuson } from '@/api/MdcApi'
  import { getMachineNum, getMachineList, getMachineStatusByWorkshopId } from '@/api/MdcApi'
  export default {
    data() {
      return {
        malists: [],
        newlist: [],
        transverse: 0,
        vertical: 0,
        totalNum: 0,
        topnum: 0,
        top: 0,
        initialvalue: '',
        initialvaluenum: 0,
        appear: 0,
        stopCount: 0,
        runCount: 0,
        idleCount: 0,
        alarmCount: 0,
        allCount: 0,
        RUN: 0.00,
        ALRAM: 0.00,
        cutRate: 0.00,
        twoShiftRate: 0.00,
        threeShiftRate: 0.00,
        timer1: null,
        timer2: null
      }
    },
    mounted() {
      /* websocket*/
      // Bus.$on(ON_MESSAGE, res => {
      //   const a = JSON.parse(res)
      //   this.malists.map(item => {
      //     if (item.id === a.machineId) {
      //       if (item.name === '130H_2801019_Ss') {
      //         console.log(item.efficiency)
      //         console.log(item.utilizationDaily)
      //       }
      //       if (a.state != null) { item.status = a.state }
      //       if (a.cycleCount != null) { item.cycleCount = a.cycleCount }
      //       if (a.efficiency != null) { item.efficiency = a.efficiency }
      //       if (a.utilizationDaily != null) { item.utilizationDaily = a.utilizationDaily }
      //     }
      //   })
      // })
      this.getNum()
      this.timer2 = setInterval(() => {
        this.getMachineStatusByWorkshopId()
        getMachineList(this.currentPage, this.keyWord, 1, this.radiotype, this.workshopId).then(res => {
          this.malists.map(item => {
            res.list.map(resItem => {
              if (item.id === resItem.id) {
                item.status = resItem.status
                item.cycleCount = resItem.cycleCount
                item.efficiency = resItem.efficiency
                item.utilizationDaily = resItem.utilizationDaily
              }
            })
          })
        })
      }, 10000)
    },
    // 销毁组件前清除定时器
    beforeDestroy() {
      // Bus.$off(ON_MESSAGE)
      clearInterval(this.timer1)
      this.timer1 = null
      clearInterval(this.timer2)
      this.timer2 = null
    },
    created() {
      this.getMachineStatusByWorkshopId()
    },
    methods: {
      getNum() {
        getMachineNum().then(res => {
          this.transverse = res.length
          this.vertical = res.width
          this.totalNum = this.transverse * this.vertical
          this.getwidth()
        })
      },
      /* 获取机床*/
      // 获取机床lists
      getMachineList() {
        this.loading = true
        document.getElementById('drags').scrollTop = 0
        document.getElementById('drags').scrollLeft = 0
        getMachineList(this.currentPage, this.keyWord, 1, this.radiotype, this.workshopId).then(res => {
          res.list.map(item => {
            var name = item.name.split('_')[1]
            item.pic = '/static/data/img/machine/' + item.workshop + '/' + item.section + '/' + name + '.png'
          })
          this.newlist = []
          /* 占空位*/
          var addnum = 0
          res.list.map(item => {
            addnum++
            if (addnum === item.firstPosition) {
              this.newlist.push(item)
            } else {
              addnum = this.getnewlists(addnum, item, this.newlist)
            }
          })
          var newarr = this.newlist
          for (var i = this.newlist.length + 1; i <= this.totalNum; i++) {
            newarr.push({
              id: '',
              ip: '',
              name: '',
              port: null,
              firstPosition: 0,
              highScale: 1,
              section: '',
              type: '',
              workshop: '',
              status: '',
              lie: false
            })
          }
          newarr[newarr.length - 1].end = true
          this.malists = newarr
          this.malists.map(item => {
            item.lie = false
          })
          var numlenth = this.transverse * 12
          numlenth = numlenth + 1
          this.malists.map((item, index) => {
            var iione = index + 1
            var iitwo = numlenth + this.transverse
            if (iione >= numlenth && iione < iitwo) {
              item.lie = 'true'
            }
          })
          this.getvertical()
        })
      },
      getnewlists(addnum, item, newlist) {
        var totalNum = this.transverse * this.vertical
        for (var i = 0; i < totalNum; i++) {
          if (addnum === item.firstPosition) {
            newlist.push(item)
            break
          } else {
            newlist.push({
              id: '',
              ip: '',
              name: '',
              port: null,
              firstPosition: 0,
              highScale: 1,
              section: '',
              type: '',
              workshop: '',
              status: '',
              lie: false
            })
          }
          addnum++
        }
        return addnum
      },
      getwidth() {
        const total = this.transverse * 300 - 90
        document.getElementById('lists').style.width = total + 'px'
        this.getMachineList()
      },
      /* 竖滚 */
      gettransverse() {
        var parent = document.getElementById('drags')
        parent.scrollTop = this.top
        this.getvertical()
      },
      /* 横滚 */
      getvertical() {
        var bodyheight = document.documentElement.clientHeight
        this.initialvaluenum++
        if (this.initialvaluenum === 1) {
          this.initialvalue = bodyheight - 240
        }
        this.top = this.top + this.initialvalue
        bodyheight = bodyheight - 130
        document.getElementById('drags').style.height = bodyheight + 'px'
        var parent1 = document.getElementById('drags')
        var left = parent1.scrollLeft
        this.timer1 = setInterval(() => {
          if (left === 0) {
            parent1.scrollLeft = parent1.scrollLeft + 2
          } else {
            parent1.scrollLeft = parent1.scrollLeft - 2
          }
          var scrollLeft = document.getElementById('drags').scrollLeft// 滚动高度
          if (this.topnum1 !== scrollLeft) {
            this.topnum1 = scrollLeft
          } else {
            clearInterval(this.timer1)
            this.gettransverse()
            this.getappear()
          }
        }, 30)
      },
      /*  判断最后一个车床是否出现在屏幕中 */
      getappear() {
        // var element = document.querySelector('.end')
        var doc = document.getElementById('drags').scrollTop
        if (this.appear === doc) {
          document.getElementById('drags').scrollTop = 0
          document.getElementById('drags').scrollLeft = 0
          this.appear = 1
          this.topnum = 0
          this.top = 0
          this.initialvalue = ''
          this.initialvaluenum = 0
        } else {
          this.appear = doc
        }
      },
      /**
       * 获取车间内的设备状态
       */
      getDeviceInfoByWorkshopID() {
        return new Promise(resolve => {
          getMachineStatusByWorkshopId(0, null, 2, '').then(res => {
            this.RUN = res.RUN
            this.ALRAM = res.ALRAM
            this.cutRate = res.cutRate
            this.twoShiftRate = res.twoShiftRate
            this.threeShiftRate = res.threeShiftRate
            // console.log(res)
            for (const prop in res) {
              // 创建设备列表
              if (res.hasOwnProperty(prop) && Array.isArray(res[prop])) {
                this.stopCount = this.runCount = this.idleCount = this.alarmCount = this.allCount = 0
                for (let i = 0; i < res[prop].length; i++) {
                  const item = res[prop][i] || {}
                  switch (item.status) {
                    case 'STOP':
                      this.stopCount++
                      break
                    case 'RUN':
                      this.runCount++
                      break
                    case 'IDLE':
                      this.idleCount++
                      break
                    case 'ALARM':
                      this.alarmCount++
                      break
                    default:
                      this.stopCount++
                      break
                  }
                }
                this.allCount = this.stopCount + this.runCount + this.idleCount + this.alarmCount
              }
            }
          })
        })
      },
      /**
       * 获取数据
       */
      getMachineStatusByWorkshopId() {
        this.getDeviceInfoByWorkshopID().then(res => {
          this.list = res.list || []
        })
      }
    }
  }
</script>
<style scoped>
  .el-checkbox,.serialnum{float: right;}
  .serialnumnone{float: right;margin-top: 10px;}
  #drags{margin-top: 0;overflow-x: auto;overflow: hidden;color: white;background-color:green;}
  #drags>ul{list-style: none;padding: 30px;padding-right: 0;}
  #drags>ul>li{height:200px;float:left;width: 280px;box-sizing:border-box;}
  #drags>ul>li>div{padding: 5px;width: 100%;height: 100%;}
  #drags{width: 100%;position: relative;}
  #drags .divimg{width: 100%;text-align: center;}
  #drags .divimg>img{width: 90%;}
  #drags p{font-size: .5rem;}
 
  #drags .content-card{background: rgba(30,83,130);border: 1px solid #0e2f67;margin-top:35px}
  #drags .device-img-layout{padding-top: 18px;}
 
  .machinelists{position: relative;}
  .machinelists:nth-of-type(even){margin-right: 30px;}
  .twotwo{position: absolute;height: 400px !important;padding-top: 120px !important;z-index: 997;}
  .threethree{position: absolute;height: 600px !important;padding-top: 230px !important;z-index: 997;}
  .fourfour{position: absolute;height: 800px !important;padding-top: 340px !important;z-index: 997;}
</style>