Files
quinn-accounts/pages/chart/index.js
2023-02-11 00:39:10 +08:00

282 lines
7.9 KiB
JavaScript

import * as echarts from '../../ec-canvas/echarts';
let pieData = [];
let line1Data = [];
let line2Data = [];
function initPieChart(canvas, width, height, dpr) {
if (pieData.length <= 0){
return;
}
const chart = echarts.init(canvas, null, {
width: 400,
height: 250,
devicePixelRatio: dpr // new
});
canvas.setChart(chart);
var option = {
backgroundColor: "#3C4043",
series: [{
label: {
normal: {
fontSize: 14
}
},
type: 'pie',
center: ['50%', '50%'],
radius: ['0%', '70%'],
data: pieData
}]
};
chart.setOption(option);
chart.on('click', 'series.pie', function(param) {
console.log(param);
wx.navigateTo({
url: "./group/index?expendId=" + param.data.sId + '&rangeDate=' + param.data.sDate
})
});
return chart;
}
function initLineChart1(canvas, width, height, dpr) {
const chart = echarts.init(canvas, null, {
width: 400,
height: 300,
devicePixelRatio: dpr // new
});
canvas.setChart(chart);
var option = {
legend: {
data: ['支出', '收入', '转账','还款'],
top: 20,
left: 'center',
backgroundColor: 'white',
z: 100
},
grid: {
containLabel: true
},
tooltip: {
show: true,
trigger: 'axis'
},
xAxis: {
type: 'category',
boundaryGap: false,
show: false
},
yAxis: {
x: 'center',
type: 'value',
splitLine: {
lineStyle: {
type: 'dashed'
}
}
},
series: line1Data
};
chart.setOption(option);
return chart;
}
function initLineChart2(canvas, width, height, dpr) {
const chart = echarts.init(canvas, null, {
width: 400,
height: 300,
devicePixelRatio: dpr // new
});
canvas.setChart(chart);
var option = {
legend: {
data: ['支出', '收入', '转账','还款'],
top: 20,
left: 'center',
backgroundColor: 'white',
z: 100
},
grid: {
containLabel: true
},
tooltip: {
show: true,
trigger: 'axis'
},
xAxis: {
type: 'category',
boundaryGap: false,
show: false
},
yAxis: {
x: 'center',
type: 'value',
splitLine: {
lineStyle: {
type: 'dashed'
}
}
// show: false
},
series: line2Data
};
chart.setOption(option);
return chart;
}
const app = getApp();
Page({
data: {
// 指定选择区间起始值
start: '2000-01-01 00:00:00',
end: '2030-09-09 12:12:12',
showDateVisible:false,
showDate:app.$utils.formatDateMonth(new Date()),
accountList: [],
sumExpend: 0,
sumIncome: 0,
sumTransfer: 0,
sumRepayment: 0,
payTypeList: [],
incomeList : [],
payList : [],
ecPie: {
onInit: initPieChart
},
ecLine1: {
onInit: initLineChart1
},
ecLine2: {
onInit: initLineChart2
}
},
onLoad: function (options) {
if (options.rangeDate){
let showDate = options.rangeDate
this.setData({showDate})
}
},
onShow: function () {
this.updateView();
if (wx.canIUse('hideHomeButton')) {
wx.hideHomeButton()
}
},
updateView(){
app.$api.listBillGroup({'rangeDate':this.data.showDate}).then(res => {
if (res){
let payTypeList = res.data
pieData = [];
if (payTypeList){
payTypeList.forEach(x => {
pieData = pieData.concat({
sId: x.expendId,
sDate: this.data.showDate,
value: x.progress,
name: x.moneyName
});
})
}
this.setData({payTypeList})
}
})
app.$api.listBillChart({'rangeDate':this.data.showDate}).then(res => {
if (res.data){
line1Data = [];
line2Data = [];
line1Data = line1Data.concat({
name: '支出',
type: 'line',
smooth: true,
data: res.data.lineDayExpend
})
line1Data = line1Data.concat({
name: '收入',
type: 'line',
smooth: true,
data: res.data.lineDayIncome
})
line1Data = line1Data.concat({
name: '转账',
type: 'line',
smooth: true,
data: res.data.lineDayTransfer
})
line1Data = line1Data.concat({
name: '还款',
type: 'line',
smooth: true,
data: res.data.lineDayRepayment
})
// 近六个月
line2Data = line2Data.concat({
name: '支出',
type: 'line',
smooth: true,
data: res.data.lineMonthExpend
})
line2Data = line2Data.concat({
name: '收入',
type: 'line',
smooth: true,
data: res.data.lineMonthIncome
})
line2Data = line2Data.concat({
name: '转账',
type: 'line',
smooth: true,
data: res.data.lineMonthTransfer
})
line2Data = line2Data.concat({
name: '还款',
type: 'line',
smooth: true,
data: res.data.lineMonthRepayment
})
}
})
app.$api.listBillByAMonth({'rangeDate':this.data.showDate}).then(res => {
if (res.data){
let accountList = res.data.accountList
let sumExpend = res.data.sumExpend
let sumIncome = res.data.sumIncome
let sumTransfer = res.data.sumTransfer
let sumRepayment = res.data.sumRepayment
this.setData({accountList,sumExpend,sumIncome,sumTransfer,sumRepayment})
}
})
app.$api.listExpendOrderBills({'rangeDate':this.data.showDate}).then(res => {
if (res){
let payList = res.data
this.setData({payList})
}
})
app.$api.listIncomeOrderBills({'rangeDate':this.data.showDate}).then(res => {
if (res){
let incomeList = res.data
this.setData({incomeList})
}
})
},
showPicker(e) {
const { mode } = e.currentTarget.dataset;
this.setData({
mode,
[`${mode}Visible`]: true,
});
},
hidePicker() {
const { mode } = this.data;
this.setData({
[`${mode}Visible`]: false,
});
},
onConfirm(e) {
const { value } = e.detail;
const { mode } = this.data;
this.setData({
[mode]: value
// [`${mode}Text`]: value,
});
// this.updateView()
this.hidePicker()
wx.redirectTo({url:"./index?rangeDate=" + this.data.showDate})
}
});