张卓
2022-09-29 4ef1c909df36c48f7f040e9ec408fc15e6745e71
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
<template>
  <div class="contributionRate_body">
    <ContributionRate ref="contributionRate" :selected-device="selectedDevices" @sendData="getData">
      <template slot="industry">
        <el-card class="industry" style="height: 320px">
          <div class="industry_header">
            <p style="margin: 0;display: inline-block; line-height: 49px; font-weight: 500; font-size: 16px">行业类型: </p>
            <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选</el-checkbox>
          </div>
          <div class="checkboxs">
            <el-checkbox-group v-model="checkedindustries" @change="handlecheckedindustriesChange">
              <el-checkbox v-for="(item, key) in industries" :key="key" :label="item">{{ item }}</el-checkbox>
            </el-checkbox-group>
          </div>
        </el-card>
      </template>
      <template slot="industryMap">
        <span class="contributionRateAnalysis" @click="showContributionRateAnalysis()">行业贡献率分析</span>
        <el-dialog
          title="行业贡献率分析"
          :visible.sync="dialogVisible"
          width="60%"
          :close-on-click-modal="false"
        >
          <div>
            <div class="selectInput">
              <el-select
                v-model="contributionRateAnalysis.industryValue"
                multiple
                collapse-tags
                style="margin-left: 20px;"
                placeholder="请选择行业"
                @change="querySensorData"
              >
                <el-option
                  v-for="item in contributionRateAnalysis.profession"
                  :key="item.dataKey"
                  :label="item.dataValue"
                  :value="item.dataKey"
                />
              </el-select>
              <el-date-picker
                ref="picker"
                :key="contributionRateAnalysis.dateType"
                v-model="contributionRateAnalysis.dateTime"
                align="right"
                :type="contributionRateAnalysis.dateType"
                :class="{activeDateType: contributionRateAnalysis.dateType === 'date'}"
                placeholder="选择日期"
                :picker-options="contributionRateAnalysis.pickerOptions"
              />
 
              <el-select v-model="contributionRateAnalysis.selectSensor" filterable placeholder="请选择因子">
                <el-option
                  v-for="item in contributionRateAnalysis.sensors"
                  :key="item.sensorCode"
                  :label="item.sensorName"
                  :value="item.sensorCode"
                />
              </el-select>
              <el-button type="primary" icon="el-icon-search" @click="queryData">查询</el-button>
            </div>
          </div>
          <!--          <span slot="footer" class="dialog-footer">-->
          <!--            <el-button @click="dialogVisible = false">取 消</el-button>-->
          <!--            <el-button type="primary" @click="dialogVisible = false">确 定</el-button>-->
          <!--          </span>-->
          <contribution-rate-charts v-if="chartsFlag" :contributionRateData="contributionRateAnalysis.datas" />
          <el-empty v-else description="请选择并查询"></el-empty>
 
        </el-dialog>
      </template>
    </ContributionRate>
 
  </div>
</template>
 
<script>
import ContributionRate from '@/components/ContributionRate/index'
import ContributionRateCharts from '@/components/charts/ContributionRateCharts'
 
export default {
  components: { ContributionRate, ContributionRateCharts },
  data() {
    const self = this
    return {
      checkAll: true,
      checkedindustries: [],
      industries: {},
      isIndeterminate: false, // 负责控制样式
      devices: [],
      marks: [],
      map: null,
      infoWindow: null,
      selectedDevices: [],
      dialogVisible: false, // 显示隐藏弹窗,
      chartsFlag: false,
      contributionRateAnalysis: {
        profession: [],
        industryValue: [],
        dateTime: '',
        dateType: 'date',
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now()
          },
          shortcuts: [{
            text: '年',
            onClick(picker) {
              // self.changeType('year')
              self.changeType('year')
            }
          }, {
            text: '月',
            onClick(picker) {
              self.changeType('month')
            }
          }, {
            text: '日',
            onClick(picker) {
              self.changeType('date')
            }
          }]
        },
        selectSensor: '',
        sensors: [],
        datas: {}
      }
    }
  },
  watch: {
    dialogVisible(newFlag, oldFlag) {
      if (!newFlag) {
        const self = this
        this.contributionRateAnalysis = {
          profession: [],
          industryValue: [],
          dateTime: '',
          dateType: 'date',
          pickerOptions: {
            disabledDate(time) {
              return time.getTime() > Date.now()
            },
            shortcuts: [{
              text: '年',
              onClick(picker) {
                self.changeType('year')
              }
            }, {
              text: '月',
              onClick(picker) {
                self.changeType('month')
              }
            }, {
              text: '日',
              onClick(picker) {
                self.changeType('date')
              }
            }]
          },
          selectSensor: '',
          sensors: [],
          datas: []
        }
        this.chartsFlag = false
      }
    }
  },
  created() {
  },
  mounted() {
    this.$refs.contributionRate.govMt()
    this.getIndustryData()
    this.getDeviceData()
  },
  methods: {
    // 获取地图数据
    getData(param) {
      this.map = param.map
      this.marks = param.markers
      this.infoWindow = param.infoWindow
    },
    // 全选点击
    handleCheckAllChange(val) {
      if (val) {
        const values = Object.keys(this.industries).map(key => {
          return this.industries[key]
        })
        this.checkedindustries = values
        this.selectedDevices = this.devices
        if (this.$refs.contributionRate.markers.length !== 0) {
          this.map.remove(this.$refs.contributionRate.markers)
        }
        this.$refs.contributionRate.addMarker(this.selectedDevices)
      } else {
        this.checkedindustries = []
        this.selectedDevices = []
        if (this.$refs.contributionRate.markers.length !== 0) {
          this.map.remove(this.$refs.contributionRate.markers)
        }
        if (this.infoWindow !== null) {
          this.infoWindow.close()
        }
      }
      this.isIndeterminate = false
    },
    handlecheckedindustriesChange(value) {
      const checkedCount = value.length
      this.checkAll = checkedCount === Object.keys(this.industries).length
      this.isIndeterminate = checkedCount > 0 && checkedCount < Object.keys(this.industries).length
      // 使用过滤器获取设备中包含点击的value框中的设备信息
      this.selectedDevices = this.devices.filter(device => {
        const p = Object.keys(device.professions).map(profession => {
          return device.professions[profession].dataValue
        })
        for (let i = 0; i < value.length; i++) {
          if (p.indexOf(value[i]) === -1) {
            continue
          } else {
            return device
          }
        }
      })
      if (this.marks.length !== 0) {
        this.map.remove(this.marks)
        this.$refs.contributionRate.addMarker(this.selectedDevices)
      } else {
        this.$refs.contributionRate.addMarker(this.selectedDevices)
      }
      if (this.infoWindow !== null) {
        this.infoWindow.close()
      }
    },
    // 获取行业字典表数据
    getIndustryData() {
      this.$request({
        url: '/sysDict/getSysDictDataByDictType',
        method: 'get',
        params: {
          type: 'profession'
        }
      }).then(res => {
        if (res.code === 0) {
          this.industries = res.data
          const values = Object.keys(this.industries).map(key => {
            return this.industries[key]
          })
          this.checkedindustries = values
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    // 获取设备信息
    getDeviceData() {
      this.$request({
        url: '/organization/getDevicesByOrganizationId',
        method: 'get',
        params: {
          organizationId: this.$store.state.orgId
        }
      }).then(res => {
        if (res.code === 0) {
          this.devices = res.data
          this.selectedDevices = this.devices
          if (this.$refs.contributionRate.markers.length !== 0) {
            this.map.remove(this.$refs.contributionRate.markers)
          }
          this.$refs.contributionRate.addMarker(this.selectedDevices)
        } else {
          this.$message.warning(res.message)
        }
      })
    },
 
    // 显示行业贡献率弹窗
    showContributionRateAnalysis() {
      this.dialogVisible = true
      this.$request({
        url: 'profession/getProfessionsByOrganizationId',
        method: 'get',
        params: {
          organizationId: this.$store.state.orgId
        }
      }).then(res => {
        if (res.code === 0) {
          this.contributionRateAnalysis.profession = res.data
        }
      })
    },
    // 查询统计图数据
    queryData() {
      if (this.contributionRateAnalysis.industryValue.length === 0) {
        this.$message.warning('请选择行业')
        return
      }
      if (this.contributionRateAnalysis.dateTime === '') {
        this.$message.warning('请选择日期')
        return
      }
      if (this.contributionRateAnalysis.selectSensor === '') {
        this.$message.warning('请选择因子')
        return
      }
      const professions = this.contributionRateAnalysis.industryValue.join(',')
      const date = new Date(this.contributionRateAnalysis.dateTime)
      let time = ''
      if (this.contributionRateAnalysis.dateType === 'year') {
        time = date.getFullYear()
      } else if (this.contributionRateAnalysis.dateType === 'month') {
        time = date.getFullYear() + '-' + ((date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1))
      } else {
        time = date.getFullYear() + '-' + ((date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) + '-' +
            (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())
      }
      this.$request({
        url: 'profession/professionContribution',
        method: 'get',
        params: {
          organizationId: this.$store.state.orgId,
          professions: professions,
          type: this.contributionRateAnalysis.dateType === 'date' ? 'day' : this.contributionRateAnalysis.dateType,
          time: time,
          sensorCode: this.contributionRateAnalysis.selectSensor
        }
      }).then(res => {
        if (res.code === 0) {
          this.contributionRateAnalysis.datas = res.data
          this.chartsFlag = true
        } else {
          this.chartsFlag = false
        }
      })
    },
    // 切换日历类型
    changeType(type) {
      this.contributionRateAnalysis.dateType = type
      this.contributionRateAnalysis.dateTime = ''
      this.$nextTick(() => {
        this.$refs.picker.focus()
        setTimeout(() => {
          const dom = document.getElementsByClassName('el-picker-panel__shortcut')
          if (this.contributionRateAnalysis.dateType === 'year') {
            dom[0].style.color = '#409EFF'
          } else if (this.contributionRateAnalysis.dateType === 'month') {
            dom[1].style.color = '#409EFF'
          } else {
            dom[2].style.color = '#409EFF'
          }
        })
      })
    },
    // 获取因子接口
    querySensorData() {
      this.$request({
        url: 'profession/getSensorByProfessions',
        method: 'get',
        params: {
          organizationId: this.$store.state.orgId,
          professions: this.contributionRateAnalysis.industryValue.join(',')
        }
      }).then(res => {
        if (res.code === 0) {
          this.contributionRateAnalysis.sensors = res.data
        }
      })
    }
  }
}
</script>
 
<style lang="less">
.contributionRate_body {
  box-sizing: border-box;
  border: 0;
  margin: 0;
  width: 100%;
  height: 100%;
}
 
.activeDateType {
  color: #409EFF!important;
}
 
</style>