liuxiaolong
2019-05-06 8700cf1dc46c350371d865532c2914595187788e
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
<template>
  <b-card no-body class="p10">
      <div class="pl10 pr10 pt10 overflow-y">
        <h5 class="mb-0">
          食堂管理
        </h5>
        <div class="flex-center" style="height:10vh">
          <div class="col text-center">
            <h1 class="fw900">{{peopleCount}}</h1>
            <p class="mb-0">就餐人数</p>
          </div>
          <div class="col text-center">
            <h1 :class="`text-${densityJson.description} fw900`">{{densityJson.lable}}</h1>
            <p class="mb-0">密集等级</p>
          </div>
        </div>
        <!-- <div class="py-5 text-center" v-else>
          <small class="text-muted">暂无数据</small>
        </div> -->
      </div>
  </b-card>
</template>
<!-- Page -->
<script>
import CommonModel from '@/server/models/CommonModel'
import { getDensityDicts } from '@/server/common.js'
export default {
  name: 'HomeDataCanteen',
  data() {
    return {
      userInfo: this.$store.getters.basicUserInfo,
      densityDictsList: [],
      /* webSocket声明 */
      CanteenStateWS: new CommonModel(),
      infoDataCountWsClient: null,
      peopleCount: 0
    }
  },
  computed: {
    densityJson() {
      let titleJson = { lable: '正常', description: 'info' }
      if (this.densityDictsList.length === 0) {
        return titleJson
      }
      if (
        this.peopleCount >=
        this.densityDictsList[this.densityDictsList.length - 1].value
      ) {
        return { lable: '非常挤', description: 'danger' }
      }
      let minCount = 0
      for (let i = 0; i < this.densityDictsList.length + 1; i++) {
        const iteam = this.densityDictsList[i] ? this.densityDictsList[i] : null
        if (
          iteam &&
          iteam.value &&
          iteam.lable &&
          this.peopleCount >= minCount &&
          this.peopleCount < iteam.value
        ) {
          titleJson.lable = iteam.lable
          titleJson.description = iteam.description
            ? iteam.description
            : 'primary'
          return titleJson
        }
        minCount = iteam.value
      }
      return titleJson
    }
  },
  methods: {
    async getDensityDicts() {
      let res = await getDensityDicts({
        orgId: this.userInfo.orgId,
        type: 'SCHOOL_DENSITY',
        module: this.$store.state.menuName ? this.$store.state.menuName : ''
      })
      if (res && res.code === '0') {
        this.densityDictsList = res.data
      }
    },
    /* ws获取食堂人数 start */
    getCanteenPersonnelNum() {
      try {
        this.CanteenStateWS.getCanteenPersonnelNum(
          {
            orgId: this.userInfo.orgId
          },
          this.infoDataCountMsg,
          err => {
            console.log(err, '获取食堂人数--出错')
          },
          close => {
            console.log(close, '获取食堂人数--关闭')
          },
          e => {
            this.infoDataCountWsClient = e
          }
        )
      } catch (ex) {
        console.log('获取食堂人数--异常', ex)
      }
    },
    infoDataCountMsg(res) {
      if (res && res.result) {
        this.peopleCount = res.result
      }
      // console.log(res, '获取地图警报数量--接收数据')
    }
  },
  created() {
    /* 查询密集度字典 */
    this.getDensityDicts()
    /* 查询列表 */
    this.infoDataCountWsClient && this.infoDataCountWsClient.close()
    this.getCanteenPersonnelNum()
  }
}
</script>
<style>
.fw900 {
  font-weight: 900;
}
</style>