123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- const app = getApp()
- import * as echarts from '../../../commpents/ec-canvas/echarts'
- let chart;
- Page({
- data: {
- frameStyle: { useTop: true, name: '收入统计', leftArrow: true, useBar: false },
- ec: {},
- date: [],
- money: [],
- time: 'm',
- },
- // 返回
- back(e) {
- wx.navigateBack({ delta: 1 })
- },
- toDate: function (e) {
- const that = this;
- let { time } = e.currentTarget.dataset
- that.setData({ time: time })
- that.watchLogin();
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- const that = this;
- that.setData({ ec: { onInit: that.initChart } })
- // 监听用户是否登录
- await that.watchLogin();
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- wx.getStorage({
- key: 'user',
- success: async res => {
- const arr = await app.$get(`/statistics/schoolTotalIn`, { school_id: res.data.info.id, time: that.data.time });
- if (arr.errcode == '0') {
- that.setData({ date: arr.data.x })
- that.setData({ money: arr.data.y })
- const option = {
- series: [{ data: arr.data.y }],
- yAxis: [{ data: arr.data.x }]
- }
- if (chart) chart.setOption(option)
- }
- },
- fail: async res => {
- wx.redirectTo({ url: '/pages/index/index' })
- }
- })
- },
- // 柱状图
- initChart(canvas, width, height, dpr) {
- const that = this;
- var date = that.data.date;
- var money = that.data.money;
- chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
- var option = {
- tooltip: {
- trigger: 'item',
- axisPointer: { type: 'shadow' },
- confine: true,
- formatter: '{b}:收入{c}元' // 格式化数值百分比输出
- },
- // legend: { data: [] },
- grid: {
- left: 20,
- right: 60,
- bottom: 15,
- top: 40,
- containLabel: true
- },
- xAxis: [{
- type: 'value',
- axisLine: { lineStyle: { color: '#999' } },
- axisLabel: { color: '#666', formatter: '{value} 元' }
- }],
- yAxis: [{
- type: 'category',
- axisTick: { show: false },
- data: date,
- axisLine: { lineStyle: { color: '#999' } },
- axisLabel: { color: '#666', },
- }],
- series: [{
- name: '收入',
- type: 'bar',
- label: { normal: { show: true, position: 'inside' } },
- data: money,
- },],
- };
- chart.setOption(option, true);
- return chart;
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () { },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (res) {
- },
- })
|