瀏覽代碼

教练收入统计

YY 2 年之前
父節點
當前提交
ffe3e8ae23
共有 1 個文件被更改,包括 144 次插入109 次删除
  1. 144 109
      pagesSchool/coaAdmin/stat/income.js

+ 144 - 109
pagesSchool/coaAdmin/stat/income.js

@@ -1,124 +1,159 @@
 const app = getApp()
 import * as echarts from '../../../commpents/ec-canvas/echarts'
+let chart;
+
 Page({
-  data: {
-    frameStyle: { useTop: true, name: '收入统计', leftArrow: true, useBar: false },
-  },
-  // 返回
-  back(e) {
-    wx.navigateBack({ delta: 1 })
-  },
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad: function (options) {
-  },
-  // 监听用户是否登录
-  watchLogin: async function () {
-    const that = this;
-    wx.getStorage({
-      key: 'user',
-      success: async res => {
+    data: {
+        frameStyle: { useTop: true, name: '收入统计', leftArrow: true, useBar: false },
+        value: [],
+        date: [],
+    },
+    // 返回
+    back(e) {
+        wx.navigateBack({ delta: 1 })
+    },
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: async function (options) {
+        const that = this;
         that.setData({ ec: { onInit: that.initChart } })
-        that.data.date = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
-        that.data.money = [11218, 5316, 6165, 8810, 3178, 5140, 2133, 6199, 4180, 6167, 7115, 1719];
-      },
-      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
-    });
-    canvas.setChart(chart);
-    var option = {
-      grid: {
-        left: 20,
-        right: 20,
-        bottom: 145,
-        top: 60,
-        containLabel: true
-      },
-      tooltip: {
-        show: true,
-        trigger: 'axis',
-        formatter: '{b}:{c}%' // 格式化数值百分比输出
-      },
-      xAxis: {
-        type: 'category',
-        boundaryGap: false,
-        data: date,
-        // 设置x轴线的属性
-        //使x轴文字显示全
-        axisLabel: { show: true, interval: 0, },
-      },
-      yAxis: {
-        x: 'center',
-        type: 'value',
-        splitLine: {
-          lineStyle: { type: 'dashed' }
-        }
-      },
-      series: [
-        {
-          type: 'line',
-          smooth: true,
-          data: money
-        }
-      ]
-    };
-    chart.setOption(option, true);
-    return chart;
-  },
-  /**
- * 生命周期函数--监听页面初次渲染完成
- */
-  onReady: function () { },
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow: function () {
-    const that = this;
+        // 监听用户是否登录
+        await that.watchLogin();
+    },
     // 监听用户是否登录
-    that.watchLogin();
-  },
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  /**
-   * 生命周期函数--监听页面隐藏
+    watchLogin: async function () {
+        const that = this;
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                const rcs = await app.$get(`/rcs`, { coach_id: res.data.info.id });
+                if (rcs.errcode == '0' && rcs.total > 0) {
+                    const arr = await app.$get(`/statistics/schoolCoachIn`, { school_id: rcs.data[0].school_id, coach_id: res.data.info.id });
+                    if (arr.errcode == '0') {
+                        var date = []
+                        var value = []
+                        arr.data.map(function (item) {
+                            var m = ''; m = item.m; date.push(m)
+                            var sevm = ''; sevm = item.total; value.push(sevm)
+                        })
+                        that.setData({ date: date })
+                        that.setData({ value: value })
+                        const option = {
+                            xAxis: [{ data: date, }],
+                            series: [{ data: value, }],
+
+                        }
+                        if (chart) 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 value = that.data.value;
+        chart = echarts.init(canvas, null, {
+            width: width,
+            height: height,
+            devicePixelRatio: dpr
+        });
+        canvas.setChart(chart);
+        var option = {
+            grid: {
+                left: 20,
+                right: 20,
+                bottom: 145,
+                top: 60,
+                containLabel: true
+            },
+            tooltip: {
+                show: true,
+                trigger: 'axis',
+                formatter: '{b}月:收入{c}元' // 格式化数值百分比输出
+            },
+            xAxis: {
+                type: 'category',
+                boundaryGap: false,
+                data: date,
+                // 设置x轴线的属性
+                //使x轴文字显示全
+                axisLabel: {
+                    formatter: '{value}月',
+                    show: true, interval: 0,
+                },
+            },
+            yAxis: {
+                x: 'center',
+                type: 'value',
+                splitLine: {
+                    lineStyle: { type: 'dashed' }
+                },
+                axisLabel: {
+                    formatter: '{value}元',
+                },
+            },
+            series: [
+                {
+                    type: 'line',
+                    smooth: true,
+                    data: value,
+                    itemStyle: {
+                        normal: {
+                            color: '#ff7f50',
+                            lineStyle: { color: '#5470C6' },
+                            label: { show: true, formatter: '{c}元', }
+                        }
+                    },
+                }
+            ]
+        };
+        chart.setOption(option, true);
+        return chart;
+    },
+    /**
+   * 生命周期函数--监听页面初次渲染完成
    */
-  onHide: function () {
+    onReady: function () { },
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow: function () {
+    },
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide: function () {
 
-  },
+    },
 
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload: function () {
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload: function () {
 
-  },
+    },
 
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh: function () {
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
 
-  },
+    },
 
 
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage: function (res) {
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage: function (res) {
 
-  },
+    },
 })