statistics.js 4.6 KB
Newer Older
D
devil 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
import * as echarts from '../../../../components/ec-canvas/echarts';
const app = getApp();

// 近15日收益走势
let profit_chart_obj = null;
function init_profit_chart(canvas, width, height) {
  profit_chart_obj = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(profit_chart_obj);
  return profit_chart_obj;
};

// 近15日推广用户数
let user_chart_obj = null;
function init_user_chart(canvas, width, height) {
  user_chart_obj = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(user_chart_obj);
  return user_chart_obj;
};

Page({
  data: {
    data_list_loding_status: 1,
    data_list_loding_msg: '加载中...',
    data_bottom_line_status: false,

    user_total: null,
    user_profit_already_price: 0.00,
    user_profit_stay_price: 0.00,
    user_profit_total_price: 0.00,
    user_data: null,
    profit_data: null,

    // 图表
    profit_chart: {
      onInit: init_profit_chart,
    },
    user_chart: {
      onInit: init_user_chart,
    },
  },
  
  onShow() {
    this.init();
  },

  init() {
    var self = this;
    wx.showLoading({ title: "加载中..." });
    this.setData({
      data_list_loding_status: 1
    });

    wx.request({
D
devil 已提交
60
      url: app.get_request_url("index", "statistics", "distribution"),
D
devil 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
      method: "POST",
      data: {},
      dataType: "json",
      success: res => {
        wx.hideLoading();
        wx.stopPullDownRefresh();
        if (res.data.code == 0) {
          var data = res.data.data;
          self.setData({
            user_total: data.user_total || null,
            user_profit_already_price: data.user_profit_already_price || 0.00,
            user_profit_stay_price: data.user_profit_stay_price || 0.00,
            user_profit_total_price: data.user_profit_total_price || 0.00,
            user_data: data.user_chart || null,
            profit_data: data.profit_chart || null,

            data_list_loding_status: 3,
            data_bottom_line_status: true,
            data_list_loding_msg: '',
          });

          // 图表
          setTimeout(function()
          {
            // 近15日收益走势
            self.set_profit_chart(data.profit_chart);

            // 近15日推广用户数
            self.set_profit_user(data.user_chart);
D
devil 已提交
90
          }, 200);
D
devil 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
        } else {
          self.setData({
            data_list_loding_status: 2,
            data_bottom_line_status: false,
            data_list_loding_msg: res.data.msg,
          });
          if (app.is_login_check(res.data, self, 'init')) {
            app.showToast(res.data.msg);
          }
        }
      },
      fail: () => {
        wx.hideLoading();
        wx.stopPullDownRefresh();
        self.setData({
          data_list_loding_status: 2,
          data_bottom_line_status: false,
          data_list_loding_msg: '服务器请求出错',
        });

        app.showToast("服务器请求出错");
      }
    });
  },

  // 近15日推广用户数
  set_profit_user(data) {
    if ((data || null) != null) {
      var option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        grid: {
D
devil 已提交
130
          top: '10%',
D
devil 已提交
131 132
          left: '5%',
          right: '5%',
D
devil 已提交
133
          bottom: '15%',
D
devil 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: data.name_arr
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          data: data.data,
          type: 'bar',
          areaStyle: {}
        }]
      };
      if (typeof (user_chart_obj) == 'object') {
        user_chart_obj.setOption(option);
      }
    }
  },

  // 近15日收益走势图表
  set_profit_chart(data) {
    if ((data || null) != null)
    {
      var option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        grid: {
D
devil 已提交
171
          top: '10%',
D
devil 已提交
172 173
          left: '5%',
          right: '5%',
D
devil 已提交
174
          bottom: '15%',
D
devil 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: data.name_arr
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          data: data.data,
          type: 'line'
        }]
      };
      if (typeof (profit_chart_obj) == 'object') {
        profit_chart_obj.setOption(option);
      }
    }
  },

  // 下拉刷新
  onPullDownRefresh() {
    this.init();
  },

D
devil 已提交
201
});