| <template> | 
|   <div class="contributionRate_body"> | 
|     <ContributionRate ref="regionalContributionRate" :selected-device="devicesCopy" @sendData="getData"> | 
|       <template slot="regional"> | 
|         <el-card class="regional" style="height: 320px"> | 
|           <div class="regional_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="checkedTowns" @change="handleCheckedCitiesChange"> | 
|               <el-checkbox v-for="(item, key) in regionals" :key="key" :label="item.townCode">{{ item.townName }}</el-checkbox> | 
|             </el-checkbox-group> | 
|           </div> | 
|         </el-card> | 
|       </template> | 
|       <template slot="regionalMap"> | 
|         <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.townCode" | 
|                 multiple | 
|                 collapse-tags | 
|                 style="margin-left: 20px;" | 
|                 placeholder="请选择区域" | 
|                 @change="queryCodeData" | 
|               > | 
|                 <el-option | 
|                   v-for="item in contributionRateAnalysis.town" | 
|                   :key="item.townCode" | 
|                   :label="item.townName" | 
|                   :value="item.townCode" | 
|                 /> | 
|               </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 { | 
|       dialogVisible: false, | 
|       checkAll: true, | 
|       checkedTowns: [], // 选择的区域 | 
|       isIndeterminate: false, // 负责控制样式 | 
|       regionals: [], | 
|       devices: [], | 
|       devicesCopy: [], | 
|       marks: [], | 
|       chartsFlag: false, | 
|       map: null, | 
|       infoWindow: null, | 
|       contributionRateAnalysis: { | 
|         townCode: [], | 
|         town: {}, | 
|         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 = { | 
|           town: {}, | 
|           townCode: [], | 
|           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.$nextTick(() => { | 
|       this.$refs.regionalContributionRate.govMt() | 
|       this.areaData() | 
|       this.getDeviceData() | 
|     }) | 
|   }, | 
|   methods: { | 
|     // 获取地图数据 | 
|     getData(param) { | 
|       this.map = param.map | 
|       this.marks = param.markers | 
|       this.infoWindow = param.infoWindow | 
|     }, | 
|     handleCheckAllChange(val) { | 
|       const townCodes = this.regionals.map(item => { | 
|         return item.townCode | 
|       }) | 
|       this.checkedTowns = val ? townCodes : [] | 
|       if (!val) { | 
|         this.devicesCopy = [] | 
|         if (this.$refs.regionalContributionRate.markers.length !== 0) { | 
|           this.map.remove(this.$refs.regionalContributionRate.markers) | 
|         } | 
|         if (this.infoWindow !== null) { | 
|           this.infoWindow.close() | 
|         } | 
|       } else { | 
|         this.devicesCopy = this.devices | 
|         if (this.$refs.regionalContributionRate.markers.length !== 0) { | 
|           this.map.remove(this.$refs.regionalContributionRate.markers) | 
|         } | 
|         this.$refs.regionalContributionRate.addMarker(this.devicesCopy) | 
|       } | 
|       this.isIndeterminate = false | 
|     }, | 
|     handleCheckedCitiesChange(value) { | 
|       const checkedCount = value.length | 
|       this.checkAll = checkedCount === this.regionals.length | 
|       this.isIndeterminate = checkedCount > 0 && checkedCount < this.regionals.length | 
|       this.devicesCopy = this.devices.filter(device => { | 
|         for (let i = 0; i < checkedCount; i++) { | 
|           if (value[i] === device.town.townCode) { | 
|             return device | 
|           } else { | 
|             continue | 
|           } | 
|         } | 
|       }) | 
|       if (this.marks.length !== 0) { | 
|         this.map.remove(this.marks) | 
|         this.$refs.regionalContributionRate.addMarker(this.devicesCopy) | 
|       } else { | 
|         this.$refs.regionalContributionRate.addMarker(this.devicesCopy) | 
|       } | 
|       if (this.infoWindow !== null) { | 
|         this.infoWindow.close() | 
|       } | 
|     }, | 
|     // 获取所以区域数据 | 
|     areaData() { | 
|       this.$request({ | 
|         url: 'region/getRegionsByOrganizationId', | 
|         method: 'get', | 
|         params: { | 
|           organizationId: this.$store.state.orgId } | 
|       }).then(res => { | 
|         if (res.code === 0) { | 
|           this.checkedTowns = [] | 
|           this.regionals = res.data | 
|           const townCodes = this.regionals.map(item => { | 
|             return item.townCode | 
|           }) | 
|           this.checkedTowns = townCodes | 
|         } 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.devicesCopy = res.data | 
|           this.$refs.regionalContributionRate.addMarker(this.devicesCopy) | 
|         } | 
|       }) | 
|     }, | 
|     // 显示区域贡献率弹窗 | 
|     showContributionRateAnalysis() { | 
|       this.dialogVisible = true | 
|       this.$request({ | 
|         url: 'region/getRegionsByOrganizationId', | 
|         method: 'get', | 
|         params: { | 
|           organizationId: this.$store.state.orgId | 
|         } | 
|       }).then(res => { | 
|         if (res.code === 0) { | 
|           this.contributionRateAnalysis.town = res.data | 
|         } | 
|       }) | 
|     }, | 
|     // 区域更改 | 
|     queryCodeData() { | 
|       this.$request({ | 
|         url: 'region/getSensorByRegionCodes', | 
|         method: 'get', | 
|         params: { | 
|           organizationId: this.$store.state.orgId, | 
|           regionCodes: this.contributionRateAnalysis.townCode.join(',') | 
|         } | 
|       }).then(res => { | 
|         if (res.code === 0) { | 
|           this.contributionRateAnalysis.sensors = res.data | 
|         } | 
|       }) | 
|     }, | 
|     // 切换日历类型 | 
|     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' | 
|           } | 
|         }) | 
|       }) | 
|     }, | 
|     // 查询统计数据 | 
|     queryData() { | 
|       if (this.contributionRateAnalysis.townCode.length === 0) { | 
|         this.$message.warning('请选择区域') | 
|         return | 
|       } | 
|       if (this.contributionRateAnalysis.dateTime === '') { | 
|         this.$message.warning('请选择日期') | 
|         return | 
|       } | 
|       if (this.contributionRateAnalysis.selectSensor === '') { | 
|         this.$message.warning('请选择因子') | 
|         return | 
|       } | 
|       const regionCodes = this.contributionRateAnalysis.townCode.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: 'region/regionContribution', | 
|         method: 'get', | 
|         params: { | 
|           organizationId: this.$store.state.orgId, | 
|           regionCodes: regionCodes, | 
|           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 | 
|         } | 
|       }) | 
|     } | 
|   } | 
| } | 
| </script> | 
|   | 
| <style lang="less"> | 
| .regional { | 
|   color: #808080; | 
|   border: 1px solid rgba(214, 214, 214, 1); | 
|   width: 280px; | 
|   margin: 10px auto; | 
|   position: relative; | 
|   font-family: 微软雅黑; | 
|   .el-card__body { | 
|     padding: 0; | 
|   } | 
|   .regional_header { | 
|     margin: 0; | 
|     background-color: #F7F7F7; | 
|     width: 100%; | 
|     position: absolute; | 
|     padding-left: 10px; | 
|     height: 49px; | 
|     top: 0 | 
|   } | 
|   .checkboxs { | 
|     width: 100%; | 
|     height: calc(100% - 49px); | 
|     color: #808080; | 
|     padding-left: 10px; | 
|     position: absolute; | 
|     top: 52px; | 
|     .el-checkbox-group { | 
|       label { | 
|         float: left; | 
|         margin-right: 6px; | 
|         margin-bottom: 5px; | 
|       } | 
|     } | 
|   } | 
| } | 
| </style> |