新增用电查询echarts和导出功能

This commit is contained in:
qiaomu 2024-05-09 11:02:40 +08:00
parent 6d35c78da9
commit e730e66c7c
9 changed files with 122 additions and 28 deletions

View File

@ -1,9 +1,9 @@
{
"pages": [
"pages/electricQuery/index",
"pages/home/index",
"pages/billDetail/index",
"pages/billList/index",
"pages/electricQuery/index",
"pages/rechargeRecord/index",
"pages/invoiceList/index",
"pages/invoiceDetail/index",

View File

@ -1,20 +1,9 @@
import { getReportDetail } from "../../service/report";
import { alertInfo } from "../../utils/index";
import { alertInfo, getPixelRatio } from "../../utils/index";
import request from '../../utils/request'
import * as echarts from '../../components/echarts/echarts';
const { OK } = request
const getPixelRatio = () => {
let pixelRatio = 0
wx.getSystemInfo({
success: function (res) {
pixelRatio = res.pixelRatio
},
fail: function () {
pixelRatio = 0
}
})
return pixelRatio
}
// pages/billDetail/index.js
Page({

View File

@ -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,

View File

@ -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"
}

View File

@ -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}}"

View File

@ -160,7 +160,6 @@ Page({
paySign: data?.paySign,
signType: 'RSA',
success: (res) => {
console.log('success', res)
alertSuccess("充值成功")
that.setData({
money: null

View File

@ -65,9 +65,8 @@ Page({
},
onChangeYear(e) {
const { years, codeId } = this.data;
const { codeId } = this.data;
const currentYear = e
console.log('e', e, 'currentYear', currentYear, 'years', years)
this.setData({
year: currentYear,
type: "",

View File

@ -1,4 +1,5 @@
import apis from '../utils/request';
import { getConfigByEnv } from "../utils/index"
const { GET, POST, PUT, DELETE } = apis
// 获取电费账单列表
@ -22,4 +23,21 @@ export const getMeterReadingList = async function(meter) {
export const getAccountingList = async function(meter) {
const tenement = wx.getStorageSync('tenement')?.id || ""
return await GET(`/wx/getAccountingList?tenement=${tenement}&meter=${meter}`);
}
// 导出电量查询
export const exportElectricityList = async function({ meter, type, time }) {
const tenement = wx.getStorageSync('tenement')?.id || ""
const { api } = getConfigByEnv();
return new Promise(resolve => {
wx.downloadFile({
url: `${api}/wx/getElectricityList/export?tenement=${tenement}&meter=${meter}&type=${type}&time=${time}`,
success(res) {
resolve(res)
},
fail(err) {
console.log('err', err)
}
})
})
}

View File

@ -220,3 +220,16 @@ export const wxModal = (data) => {
})
}
export const getPixelRatio = () => {
let pixelRatio = 0
wx.getSystemInfo({
success: function (res) {
pixelRatio = res.pixelRatio
},
fail: function () {
pixelRatio = 0
}
})
return pixelRatio
}