diff --git a/src/views/iot/project/profileV2/EnergyManage/EElectricity.vue b/src/views/iot/project/profileV2/EnergyManage/EElectricity.vue index b6970aae..f2eb3164 100644 --- a/src/views/iot/project/profileV2/EnergyManage/EElectricity.vue +++ b/src/views/iot/project/profileV2/EnergyManage/EElectricity.vue @@ -1,41 +1,51 @@ --> - + @@ -147,11 +160,11 @@ @@ -162,6 +175,7 @@ import Treeselect from "@riophae/vue-treeselect"; import "@riophae/vue-treeselect/dist/vue-treeselect.css"; import { projectElectricityTable } from "@/api/iot/project_new"; import { listSpace } from "@/api/iot/space"; +import { getProjectGroupList } from "@/api/tenant/project"; export default { name: "EElectricity", props: { @@ -186,12 +200,15 @@ export default { queryParams: { spaceId: null, deviceId: '', + groupId: null, }, queryTime: '', querySpaceOptions: [], tableList: [], tableLoading: false, - total: 2 + total: 2, + // 设备分组 + projectGroupList:[], }; }, watch: { @@ -204,14 +221,35 @@ export default { created() { this.init() }, + updated() { + this.$nextTick(() => { + this.$refs.deviceTableRef.doLayout(); + console.log("do layout"); + }); + }, methods: { + // 查询所属项目分组列表 + getProjectGroupList() { + getProjectGroupList({ + projectId: this.sourceId + }).then(response => { + this.projectGroupList = response.rows||[]; + }); + }, init() { this.queryTime = this.parseTime(new Date(), "{y}-{m}-01 00:00:00"); - this.getSpaceList(); + // this.getSpaceList(); this.handleQuery(); + this.getProjectGroupList(); }, handleQuery() { - this.queryParams.pageNum = 1; + // this.queryParams.pageNum = 1; + this.queryParams={ + spaceId: null, + deviceId: '', + groupId: null, + pageNum:1 + } this.getList(); }, handleLinkDevDetails(row) { @@ -250,6 +288,7 @@ export default { projectElectricityTable( Object.assign(queryParams, { projectId: this.sourceId, + groupId: this.groupId, time: this.parseTime( new Date(this.queryTime), "{y}-{m}-01 00:00:00" @@ -258,10 +297,66 @@ export default { timeType: 'month' }) ).then((res) => { + if(res.rows.length>0){ + res.rows[0].tmReadSum = '1.0'; + res.rows[1].tmReadSum = '1.0'; + res.rows[1].lmReadSum = '2.0'; + res.rows[1].tmReadSum = '2.0'; + res.rows[1].lmReadSum = '1.0'; + } this.tableList = res.rows; this.total = res.total; }); }, + getSummaries(param) { + const { columns, data } = param; + const sums = []; + columns.forEach((column, index) => { + if (index === 0) { + sums[index] = '总计'; + return; + } + // const values = data.map(item => Number(item[column.property])); + const values = data.map((item,i)=>{ + if(index===2){ + return NaN; + }else{ + return Number(item[column.property]); + } + }); + if (!values.every(value => isNaN(value))) { + sums[index] = values.reduce((prev, curr) => { + const value = Number(curr); + if (!isNaN(value)) { + return prev + curr; + } else { + return prev; + } + }, 0); + sums[index] += ''; + } else { + sums[index] = ''; + } + }); + // 获取上个月电量和本月电量 + const lastMonthEnergy = parseFloat(sums[4]) || 0; + const thisMonthEnergy = parseFloat(sums[3]) || 0; + // 计算对比百分比 + let percentage = 0; + if (lastMonthEnergy !== 0) { + percentage = ((thisMonthEnergy - lastMonthEnergy) / lastMonthEnergy) * 100; + } else { + if(thisMonthEnergy==0 && lastMonthEnergy==0){ + percentage = 0; + }else if(thisMonthEnergy==0){ + percentage = -100; + }else if(lastMonthEnergy==0){ + percentage = 100; + } + } + sums[5] = percentage.toFixed(2) + '%'; + return sums; + } }, };