From e730e66c7c00f04bdbb2d1039dbea659a998b7b4 Mon Sep 17 00:00:00 2001
From: qiaomu <3520484422@qq.com>
Date: Thu, 9 May 2024 11:02:40 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E7=94=B5=E6=9F=A5?=
=?UTF-8?q?=E8=AF=A2echarts=E5=92=8C=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app.json | 2 +-
pages/billDetail/index.js | 15 +-----
pages/electricQuery/index.js | 85 +++++++++++++++++++++++++++++++---
pages/electricQuery/index.json | 3 +-
pages/electricQuery/index.wxml | 10 ++--
pages/home/index.js | 1 -
pages/rechargeRecord/index.js | 3 +-
service/accounting.js | 18 +++++++
utils/index.js | 13 ++++++
9 files changed, 122 insertions(+), 28 deletions(-)
diff --git a/app.json b/app.json
index c97a109..5e3241f 100644
--- a/app.json
+++ b/app.json
@@ -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",
diff --git a/pages/billDetail/index.js b/pages/billDetail/index.js
index d84e43f..de8b8f2 100644
--- a/pages/billDetail/index.js
+++ b/pages/billDetail/index.js
@@ -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({
diff --git a/pages/electricQuery/index.js b/pages/electricQuery/index.js
index 4898b70..8db63e1 100644
--- a/pages/electricQuery/index.js
+++ b/pages/electricQuery/index.js
@@ -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,
diff --git a/pages/electricQuery/index.json b/pages/electricQuery/index.json
index 7865dbb..4cb41b2 100644
--- a/pages/electricQuery/index.json
+++ b/pages/electricQuery/index.json
@@ -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"
}
\ No newline at end of file
diff --git a/pages/electricQuery/index.wxml b/pages/electricQuery/index.wxml
index 4aa9bf2..837a1a7 100644
--- a/pages/electricQuery/index.wxml
+++ b/pages/electricQuery/index.wxml
@@ -53,7 +53,7 @@
{{year}}
- 导出
+ 导出
@@ -94,14 +94,16 @@
-
+
{
- console.log('success', res)
alertSuccess("充值成功")
that.setData({
money: null
diff --git a/pages/rechargeRecord/index.js b/pages/rechargeRecord/index.js
index e59ea1d..1ec0f63 100644
--- a/pages/rechargeRecord/index.js
+++ b/pages/rechargeRecord/index.js
@@ -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: "",
diff --git a/service/accounting.js b/service/accounting.js
index 3a29ab0..02da240 100644
--- a/service/accounting.js
+++ b/service/accounting.js
@@ -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)
+ }
+ })
+ })
}
\ No newline at end of file
diff --git a/utils/index.js b/utils/index.js
index 1d32357..e54dce9 100644
--- a/utils/index.js
+++ b/utils/index.js
@@ -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
+}