yangys
2024-01-13 b8d63989635bc9fb58357f76333796e21409985b
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
<template>
  <div ref="room" style="overflow: hidden;" id="toollist">
    <mdc-message v-if="msgOpt.show" :message="msgOpt.msg"></mdc-message>
    <div>
      <p class="statelist" id="theradio">
        <el-radio-group v-model="radiotype">
          <el-radio :label="2" @change="radiotypes()">全部</el-radio>
          <el-radio :label="1" @change="radiotypes()">关注</el-radio>
          <el-radio :label="3" @change="">我的关注</el-radio>
        </el-radio-group>
        <span><i class="icons backblack" @click="getMachinesByStatus('STOP')"></i><i class="textwenzi">停机({{ stopCount }})</i></span>
        <span><i class="icons backgreenyellowtitle" @click="getMachinesByStatus('RUN')"></i><i class="textwenzi">运行({{ runCount }})</i></span>
        <span><i class="icons backyellow" @click="getMachinesByStatus('IDLE')"></i><i class="textwenzi">待机({{ idleCount }})</i></span>
        <span><i class="icons backgreenredtitle" @click="getMachinesByStatus('ALARM')"></i><i class="textwenzi">报警({{ alarmCount }})</i></span>
        <span><i class="icons backwhiletitle" @click="getMachinesByStatus(null)"></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>
<!--        <span><i class="icons backblack" @click="getMachinesByStatus('STOP')"></i><i class="textwenzi">停机({{ stopCount }})</i></span>-->
<!--        <span><i class="icons backgreenyellowtitle" @click="getMachinesByStatus('RUN')"></i><i class="textwenzi">运行({{ runCount }})</i></span>-->
<!--        <span><i class="icons backyellow" @click="getMachinesByStatus('IDLE')"></i><i class="textwenzi">待机({{ idleCount }})</i></span>-->
<!--        <span><i class="icons backgreenredtitle" @click="getMachinesByStatus('ALARM')"></i><i class="textwenzi">报警({{ alarmCount }})</i></span>-->
<!--        <span><i class="icons backwhiletitle" @click="getMachinesByStatus(null)"></i><i class="textwenzi">全部({{ allCount }})</i></span>-->
      </p>
      <div class="device-layout workshop">
        <div class="device-item-card" v-for="(item, index) in list" :key="index">
          <div class="content-card">
            <div class="device-img-layout">
              <el-row>
<!--                <el-col :span="11" v-if="item.status == 'ALARM'">-->
<!--                  <img :src="item.pic" class="mdc-machine-image" @click="police(item)">-->
<!--                </el-col>-->
<!--                <el-col :span="11" v-else>-->
<!--                  <img :src="item.pic" class="mdc-machine-image" @click="showMachineDetail(item.id, item.pic)">-->
<!--                </el-col>-->
                <el-col :span="11">
                  <img :src="item.pic" class="mdc-machine-image" @click="showMachineDetail(item.id, item.pic)">
                </el-col>
                <el-col :span="13" class="screen">
                  <el-checkbox v-model="item.concern" @change="focuson(item)"></el-checkbox>
                  <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" @click="police(item)"></i></span>
                  </div>
                  <div class="mdc-machine-efficiency margint10"><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="mdc-machine-name text-center"><span class="xsName">{{ item.name }}</span></div>
          </div>
        </div>
      </div>
      <div class="parent-h-layout">
        <div class="chart chart-panel">
          <div class="chart-content">
          </div>
        </div>
      </div>
    </div>
    <machine-detail-dialog :is-visible="dialog.showDetail" ref="machineDetailDialog"></machine-detail-dialog>
 
    <!-- 报警-->
    <call-police v-if="visible" ref="CallPolice" @refreshDataList="getMachineStatusByWorkshopId"></call-police>
  </div>
</template>
 
<script>
import ECharts from 'vue-echarts/components/ECharts.vue'
import 'echarts/lib/chart/gauge'
import 'echarts/lib/component/tooltip'
import { default as Bus, SCROLL_TOP, ON_MESSAGE, ON_VISIBILITY_CHANGE } from '@/bus/EventBus'
// import { getMachineDetailById, getMachineStatusByWorkshopId, focuson, getMachineList } from '@/api/MdcApi'
import { getMachineStatusByWorkshopId, focuson } from '@/api/MdcApi'
import { mapGetters } from 'vuex'
import { cfgUtil } from 'cfgUtil'
import { Loading } from 'element-ui'
import machineDetailDialog from './dialog/MachinDetail'
import CallPolice from './dialog/callPolice'
 
export default {
  components: {
    ECharts,
    machineDetailDialog,
    CallPolice
  },
  data() {
    return {
      currentTabIndex: '0',
      imgPreFix: (process.env.NODE_ENV === 'development' ? '' : '/mdc') + '/static/data/img/device/',
      dialog: {
        showDetail: false // 详细信息
      },
      radiotype: 2,
      machineDetail: {
        machine: {},
        data: []
      }, // 机床详细信息
      webSocket: null,
      mdcLoading: null,
      timerInterval: 0,
      list: [],
      msgOpt: {
        show: false,
        duration: 4000,
        msg: ''
      },
      timer: null,
      visible: false,
      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,
      legendStatus: ''
    }
  },
  methods: {
    /* 报警*/
    police(row) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.CallPolice.init(row)
      })
    },
    showLoading(timeOutCallBack) {
      let delay = 25
      this.mdcLoading = Loading.service({
        lock: true,
        text: `需要较长时间,请耐心等待 ${delay}秒`,
        // spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
        customClass: 'mdc-loading'
      })
      clearInterval(this.timerInterval)
      this.$nextTick(() => {
        this.timerInterval = setInterval(() => {
          delay--
          this.mdcLoading.text = `需要较长时间,请耐心等待 ${delay}秒`
          if (delay === 0) {
            this.mdcLoading.close()
            clearInterval(this.timerInterval)
            // todo 超时状态回退
            if (timeOutCallBack) {
              timeOutCallBack()
            }
          }
        }, 1000)
      })
    },
    /**
     *
     **/
    closeLoading() {
      clearInterval(this.timerInterval)
      this.mdcLoading.close()
    },
    /**
     * 错误提示信息
     **/
    showErrorTip(msg) {
      this.$message({
        message: msg,
        type: 'error',
        duration: 4000
      })
    },
    /**
     * 提示信息
     **/
    showInfoTip(msg) {
      if (!this.msgOpt) {
        return
      }
      if (!this.msgOpt.show) {
        this.msgOpt.msg = `系统提示:<p>${msg}</p>`
        this.msgOpt.show = true
        if (this.msgOpt.duration > 0) {
          const timer = setTimeout(() => {
            this.msgOpt.show = false
            clearTimeout(timer)
            this.msgOpt.msg = ''
          }, this.msgOpt.duration)
        }
      } else {
        this.msgOpt.msg += `<p>${msg}</p>`
      }
    },
    /**
     * 获取设备图标
     */
    getImgUrl(type) {
      const relUrl = cfgUtil.deviceImgMap[type] || cfgUtil.deviceImgMap.unknown
      return relUrl ? this.imgPreFix + relUrl : ''
    },
    /* 改变全部和关注*/
    radiotypes() {
      this.getMachineStatusByWorkshopId()
    },
    /**
     * 获取车间内的设备状态
     */
    getDeviceInfoByWorkshopID(filterItem) {
      const ids = this.$route.params.pid.split('=')
      return new Promise(resolve => {
        getMachineStatusByWorkshopId(ids[0], ids[1], this.radiotype, this.legendStatus).then(res => {
          const tempList = []
          const result = {}
          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
                }
                item.type = prop
                tempList.push(item)
                if (filterItem && filterItem.index === item.index && filterItem.type === item.type) {
                  result.select = item
                }
              }
              this.allCount = this.stopCount + this.runCount + this.idleCount + this.alarmCount
            }
          }
          result.list = tempList || []
          resolve(result)
        })
      })
    },
    /**
     * 获取数据
     */
    getMachineStatusByWorkshopId() {
      this.getDeviceInfoByWorkshopID().then(res => {
        this.list = res.list || []
      })
    },
    getMachinesByStatus(status) {
      this.legendStatus = status
      this.getDeviceInfoByWorkshopID().then(res => {
        this.list = res.list || []
      })
    },
    /**
     * 数值转换
     * @param num      数值
     * @param dec      精度    默认是0
     * @return {string}
     */
    convertNumber(num, dec = 0) {
      let ret = '-'
      let rate = 1
      let counter = dec
      num = parseFloat(num)
      if (num.toString() !== 'NaN') {
        while (counter && counter !== 0) {
          rate *= 10
          counter--
        }
        num = Math.round(num * rate)
        if (num === 0) {
          ret = num.toFixed(dec)
        } else {
          ret = num / rate
        }
      }
      return ret
    },
    /**
     * 通知vuex store 更新状态数据
     * @param type
     * @param params
     */
    commitMutations(type, params) {
      this.$store.commit(type, params)
    },
    /**
     * 更新UI
     * @param data
     */
    updateUI(data) {
      if (this.$route.path.indexOf('/workshop') === -1 || this.$route.params.pid !== data.workshop) {
        return
      }
      // console.log('机床页面')
    },
    showMachineDetail(machineId, imgurl) {
      if (machineId !== '') {
        this.dialog.showDetail = true
        this.$nextTick(() => {
          const obj = { imgurl: imgurl, machineId: machineId, concernFlag: this.radiotype }
          this.$refs.machineDetailDialog.init(obj)
        })
      }
    },
    /* 关注 */
    focuson(row) {
      var num = row.concern
      if (num === false) { num = 0 } else { num = 1 }
      focuson(row.id, num).then(res => {
        if (num === 0) {
          this.$message({
            message: '取关成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '关注成功',
            type: 'success'
          })
        }
      })
    }
  },
  computed: {
    ...mapGetters({
      mainWidth: 'mainWidth'
    })
  },
  watch: {
    '$route'(to, from) {
      // 对路由变化作出响应...
      if (this.$route.path.indexOf('/workshop') > -1) {
        Bus.$emit(SCROLL_TOP)
        this.getMachineStatusByWorkshopId()
      }
    }
  },
  created() {
    // 初始化车间设备状态
    this.getMachineStatusByWorkshopId()
    Bus.$on(ON_MESSAGE, res => {
      const a = JSON.parse(res)
      this.list.map(item => {
        if (item.id === a.machineId) {
          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.updateUI(res)
    })
    Bus.$on(ON_VISIBILITY_CHANGE, () => {
      this.getMachineStatusByWorkshopId()
    })
  },
  mounted() {
    console.log('111')
    this.legendStatus = null
    this.stopCount = this.runCount = this.idleCount = this.alarmCount = this.allCount = 0
    this.timer = setInterval(() => {
      this.getMachineStatusByWorkshopId()
    }, 10000)
  },
  beforeDestroy() {
    clearInterval(this.timer)
    this.timer = null
    Bus.$off(ON_MESSAGE)
  }
}
</script>
 
<style scoped>
  .workshop .content-card{border: 1px outset #0e2f67;}
  .device-layout{background-color: #061537;padding-bottom: 20px;margin-top:40px}
</style>