|
@@ -1,137 +1,147 @@
|
|
|
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:[],
|
|
|
- },
|
|
|
- // 返回
|
|
|
- back(e) {
|
|
|
- wx.navigateBack({ delta: 1 })
|
|
|
- },
|
|
|
+ data: {
|
|
|
+ frameStyle: { useTop: true, name: '收入统计', leftArrow: true, useBar: false },
|
|
|
+ ec: {},
|
|
|
+ date: [],
|
|
|
+ money: [],
|
|
|
+ },
|
|
|
+ // 返回
|
|
|
+ back(e) {
|
|
|
+ wx.navigateBack({ delta: 1 })
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- onLoad: function (options) {
|
|
|
- },
|
|
|
- // 监听用户是否登录
|
|
|
- watchLogin: async function () {
|
|
|
- const that = this;
|
|
|
- wx.getStorage({
|
|
|
- key: 'user',
|
|
|
- success: async res => {
|
|
|
- let date = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '12', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'];
|
|
|
- let money = [900, 270, 340, 400, 600, 700, 310, 300, 270, 340, 344, 300, 320, 310, 300, 270, 340, 344, 300, 500, 310, 300, 270, 340, 344, 300, 320, 310, 300, 270, 340, 344, 300, 320, 310];
|
|
|
- that.setData({money:money})
|
|
|
- that.setData({date:date})
|
|
|
- that.setData({ ec: { onInit: that.initChart } })
|
|
|
- },
|
|
|
- fail: async res => {
|
|
|
- wx.redirectTo({ url: '/pages/index/index' })
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- // 柱状图
|
|
|
- initChart(canvas, width, height, dpr) {
|
|
|
- let that = this;
|
|
|
- var date = that.data.date;
|
|
|
- var money = that.data.money;
|
|
|
- const chart = echarts.init(canvas, null, {
|
|
|
- width: width,
|
|
|
- height: height,
|
|
|
- devicePixelRatio: dpr // new
|
|
|
- });
|
|
|
- canvas.setChart(chart);
|
|
|
- var option = {
|
|
|
- tooltip: {
|
|
|
- trigger: 'axis',
|
|
|
- axisPointer: { type: 'shadow' },
|
|
|
- confine: true
|
|
|
- },
|
|
|
- legend: { data: [] },
|
|
|
- grid: {
|
|
|
- left: 20,
|
|
|
- right: 60,
|
|
|
- bottom: 15,
|
|
|
- top: 40,
|
|
|
- containLabel: true
|
|
|
- },
|
|
|
- xAxis: [
|
|
|
- {
|
|
|
- type: 'value',
|
|
|
- name: '金额',
|
|
|
- axisLine: { lineStyle: { color: '#999' } },
|
|
|
- axisLabel: { color: '#666' }
|
|
|
- }
|
|
|
- ],
|
|
|
- yAxis: [
|
|
|
- {
|
|
|
- type: 'category',
|
|
|
- name: '日期',
|
|
|
- axisTick: { show: false },
|
|
|
- data: date,
|
|
|
- axisLine: { lineStyle: { color: '#999' } },
|
|
|
- axisLabel: { color: '#666' }
|
|
|
- }
|
|
|
- ],
|
|
|
- series: [
|
|
|
- {
|
|
|
- name: '收入',
|
|
|
- type: 'bar',
|
|
|
- label: { normal: { show: true, position: 'inside' } },
|
|
|
- data: money,
|
|
|
- itemStyle: {}
|
|
|
- },
|
|
|
- ],
|
|
|
-
|
|
|
- };
|
|
|
- chart.setOption(option, true);
|
|
|
- return chart;
|
|
|
- },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
- */
|
|
|
- onReady: function () { },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面显示
|
|
|
- */
|
|
|
- onShow: function () {
|
|
|
- const that = this;
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad: function (options) {
|
|
|
+ this.setData({ ec: { onInit: this.initChart } })
|
|
|
+ },
|
|
|
// 监听用户是否登录
|
|
|
- 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: 'm' });
|
|
|
+ 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 }]
|
|
|
+ }
|
|
|
+ chart.setOption(option)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: async res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 柱状图
|
|
|
+ initChart(canvas, width, height, dpr) {
|
|
|
+ let 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: 'axis',
|
|
|
+ axisPointer: { type: 'shadow' },
|
|
|
+ confine: true
|
|
|
+ },
|
|
|
+ legend: { data: [] },
|
|
|
+ grid: {
|
|
|
+ left: 20,
|
|
|
+ right: 60,
|
|
|
+ bottom: 15,
|
|
|
+ top: 40,
|
|
|
+ containLabel: true
|
|
|
+ },
|
|
|
+ xAxis: [
|
|
|
+ {
|
|
|
+ type: 'value',
|
|
|
+ name: '金额',
|
|
|
+ axisLine: { lineStyle: { color: '#999' } },
|
|
|
+ axisLabel: { color: '#666' }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ yAxis: [
|
|
|
+ {
|
|
|
+ type: 'category',
|
|
|
+ name: '日期',
|
|
|
+ axisTick: { show: false },
|
|
|
+ data: date,
|
|
|
+ axisLine: { lineStyle: { color: '#999' } },
|
|
|
+ axisLabel: {
|
|
|
+ color: '#666',
|
|
|
+ formatter: '{value} 日'
|
|
|
+ },
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ name: '收入',
|
|
|
+ type: 'bar',
|
|
|
+ label: { normal: { show: true, position: 'inside' } },
|
|
|
+ data: money,
|
|
|
+ itemStyle: {}
|
|
|
+ },
|
|
|
+ ],
|
|
|
+
|
|
|
+ };
|
|
|
+ chart.setOption(option, true);
|
|
|
+ return chart;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
- onHide: function () {
|
|
|
+ onReady: function () { },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
+ const that = this;
|
|
|
+ // 监听用户是否登录
|
|
|
+ that.watchLogin();
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面卸载
|
|
|
- */
|
|
|
- onUnload: function () {
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
- */
|
|
|
- onPullDownRefresh: function () {
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage: function (res) {
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage: function (res) {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
})
|