新增用电查询echarts和导出功能
This commit is contained in:
		| @@ -1,10 +1,10 @@ | ||||
| // pages/electricQuery/index.js | ||||
| import { getAccountingList, getElectricityList, getMeterReadingList } from "../../service/accounting"; | ||||
| import { exportElectricityList, getAccountingList, getElectricityList, getMeterReadingList } from "../../service/accounting"; | ||||
| import { getTenementMeterList } from "../../service/meter"; | ||||
| import dayjs from "../../utils/dayjs"; | ||||
| import request from '../../utils/request'; | ||||
| import * as echarts from '../../components/echarts/echarts'; | ||||
| import { alertInfo } from "../../utils/index"; | ||||
| import { alertInfo, getPixelRatio, loadingFunc } from "../../utils/index"; | ||||
| const { OK } = request; | ||||
| Page({ | ||||
|  | ||||
| @@ -99,6 +99,52 @@ Page({ | ||||
|       return; | ||||
|     } | ||||
|     this.setData({ list: data, electricNumber, meterNumber }) | ||||
|     if (!data?.length) { | ||||
|       return; | ||||
|     } | ||||
|     this.selectComponent('#echarts').init((canvas, width, height) => { | ||||
|       // 初始化图表 | ||||
|       const pieChart = echarts.init(canvas, null, { | ||||
|         width: width, | ||||
|         height: height, | ||||
|         devicePixelRatio: getPixelRatio(), | ||||
|       }); | ||||
|       const ids = [...new Set(data?.map(item => item?.meter?.id))] | ||||
|       const options  = { | ||||
|         tooltip: { | ||||
|           trigger: 'axis' | ||||
|         }, | ||||
|         legend: { | ||||
|           data: data?.map(item => item?.meter?.address), | ||||
|         }, | ||||
|         grid: { | ||||
|           left: '3%', | ||||
|           right: '4%', | ||||
|           bottom: '3%', | ||||
|           containLabel: true | ||||
|         }, | ||||
|         xAxis: { | ||||
|           type: 'category', | ||||
|           boundaryGap: false, | ||||
|           data: [...new Set(data?.map(item => item.time))] | ||||
|         }, | ||||
|         yAxis: { | ||||
|           type: 'value' | ||||
|         }, | ||||
|         series: ids?.map(item => { | ||||
|           const element = data?.find(i => i?.meter?.id === item) | ||||
|           return { | ||||
|             name: element?.meter?.address, | ||||
|             type: 'line', | ||||
|             stack: 'Total', | ||||
|             data: data?.filter(ele => ele?.meter?.id === item).map(item => item.number) | ||||
|           }})  | ||||
|           | ||||
|       }; | ||||
|       pieChart.setOption(options); | ||||
|       // 注意这里一定要返回 chart 实例,否则会影响事件处理等 | ||||
|       return pieChart; | ||||
|     }); | ||||
|   }, | ||||
|   async getReadingList() { | ||||
|     const { meterId } = this.data; | ||||
| @@ -109,6 +155,37 @@ Page({ | ||||
|     } | ||||
|     this.setData({ meterReadingList: data }) | ||||
|   }, | ||||
|   async export() { | ||||
|     loadingFunc(async () => { | ||||
|       const { queryType, timeType, meterId, year, yearMonth, yearMonthDay } = this.data; | ||||
|       let time; | ||||
|       switch(timeType) { | ||||
|         case 1: | ||||
|           time = yearMonth; | ||||
|           break; | ||||
|         case 2:  | ||||
|           time = year; | ||||
|           break; | ||||
|         default: | ||||
|           time = yearMonthDay; | ||||
|           break; | ||||
|       } | ||||
|       const data = await exportElectricityList({ type: timeType, meter: meterId, time: time }) | ||||
|       // if (code !== OK) { | ||||
|       //   alertInfo(message) | ||||
|       //   return; | ||||
|       // } | ||||
|           wx.openDocument({ | ||||
|             filePath: data.tempFilePath, | ||||
|             fileType: 'xlsx', | ||||
|             success() { | ||||
|             }, | ||||
|             fail(err) { | ||||
|             } | ||||
|           }) | ||||
|         | ||||
|     }) | ||||
|   }, | ||||
|   async getAccountingBalanceList() { | ||||
|     const { meterId } = this.data; | ||||
|     const { code, message, data } = await getAccountingList(meterId) | ||||
| @@ -147,11 +224,7 @@ Page({ | ||||
|     }) | ||||
|   }, | ||||
|   onOk(e) { | ||||
|     const { type, value = {} } = e.detail; | ||||
|     const { id, code } = e.detail.value; | ||||
|     console.log('e', e) | ||||
|     const { year } = this.data; | ||||
|     // const currentYear = years[Number(e)] | ||||
|     this.setData({ | ||||
|       // year: currentYear, | ||||
|       meterId: id, | ||||
|   | ||||
| @@ -9,7 +9,8 @@ | ||||
|     "table": "/components/table/table", | ||||
|     "empty": "/components/empty/index", | ||||
|     "timePicker": "/components/timePicker/index", | ||||
|     "accountingCard": "./components/accountingCard/index" | ||||
|     "accountingCard": "./components/accountingCard/index", | ||||
|     "echarts": "/components/echarts/ec-canvas" | ||||
|   }, | ||||
|   "navigationStyle": "custom" | ||||
| } | ||||
| @@ -53,7 +53,7 @@ | ||||
|         <view class="timeText" wx:else> {{year}} </view> | ||||
|         <van-icon name="arrow-down" /> | ||||
|       </view> | ||||
|       <van-button type="info" size="small"> 导出 </van-button> | ||||
|       <van-button type="info" size="small" bind:click="export"> 导出 </van-button> | ||||
|     </view> | ||||
|   </view> | ||||
|   <view wx:elif="{{queryType === 1}}"> | ||||
| @@ -94,14 +94,16 @@ | ||||
|     </view> | ||||
|     | ||||
|   </view> | ||||
|   <!-- <echarts  | ||||
|     style="width:200rpx;height:200rpx;position:relative"  | ||||
|   <echarts  | ||||
|     style="width:200rpx;height:180rpx;"  | ||||
|     id="echarts"  | ||||
|     class='mychart-bar'  | ||||
|     canvas-id="mychart-bar"  | ||||
|     ec="{{ ec }}"     | ||||
|     forceUseOldCanvas="{{false}}" | ||||
|     wx:if="{{list.length}}" | ||||
|   > | ||||
|   </echarts> --> | ||||
|   </echarts> | ||||
| <custom-picker  | ||||
|   title="{{title}}"  | ||||
|   show="{{show}}"  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user