income.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const app = getApp()
  2. import * as echarts from '../../../commpents/ec-canvas/echarts'
  3. let chart;
  4. Page({
  5. data: {
  6. frameStyle: { useTop: true, name: '收入统计', leftArrow: true, useBar: false },
  7. ec: {},
  8. date: [],
  9. money: [],
  10. time: 'm',
  11. },
  12. // 返回
  13. back(e) {
  14. wx.navigateBack({ delta: 1 })
  15. },
  16. toDate: function (e) {
  17. const that = this;
  18. let { time } = e.currentTarget.dataset
  19. that.setData({ time: time })
  20. that.watchLogin();
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: async function (options) {
  26. const that = this;
  27. that.setData({ ec: { onInit: that.initChart } })
  28. // 监听用户是否登录
  29. await that.watchLogin();
  30. },
  31. // 监听用户是否登录
  32. watchLogin: async function () {
  33. const that = this;
  34. wx.getStorage({
  35. key: 'user',
  36. success: async res => {
  37. const arr = await app.$get(`/statistics/schoolTotalIn`, { school_id: res.data.info.id, time: that.data.time });
  38. if (arr.errcode == '0') {
  39. that.setData({ date: arr.data.x })
  40. that.setData({ money: arr.data.y })
  41. const option = {
  42. series: [{ data: arr.data.y }],
  43. yAxis: [{ data: arr.data.x }]
  44. }
  45. if (chart) chart.setOption(option)
  46. }
  47. },
  48. fail: async res => {
  49. wx.redirectTo({ url: '/pages/index/index' })
  50. }
  51. })
  52. },
  53. // 柱状图
  54. initChart(canvas, width, height, dpr) {
  55. const that = this;
  56. var date = that.data.date;
  57. var money = that.data.money;
  58. chart = echarts.init(canvas, null, {
  59. width: width,
  60. height: height,
  61. devicePixelRatio: dpr // new
  62. });
  63. canvas.setChart(chart);
  64. var option = {
  65. tooltip: {
  66. trigger: 'item',
  67. axisPointer: { type: 'shadow' },
  68. confine: true,
  69. formatter: '{b}:收入{c}元' // 格式化数值百分比输出
  70. },
  71. // legend: { data: [] },
  72. grid: {
  73. left: 20,
  74. right: 60,
  75. bottom: 15,
  76. top: 40,
  77. containLabel: true
  78. },
  79. xAxis: [{
  80. type: 'value',
  81. axisLine: { lineStyle: { color: '#999' } },
  82. axisLabel: { color: '#666', formatter: '{value} 元' }
  83. }],
  84. yAxis: [{
  85. type: 'category',
  86. axisTick: { show: false },
  87. data: date,
  88. axisLine: { lineStyle: { color: '#999' } },
  89. axisLabel: { color: '#666', },
  90. }],
  91. series: [{
  92. name: '收入',
  93. type: 'bar',
  94. label: { normal: { show: true, position: 'inside' } },
  95. data: money,
  96. },],
  97. };
  98. chart.setOption(option, true);
  99. return chart;
  100. },
  101. /**
  102. * 生命周期函数--监听页面初次渲染完成
  103. */
  104. onReady: function () { },
  105. /**
  106. * 生命周期函数--监听页面显示
  107. */
  108. onShow: function () {
  109. },
  110. /**
  111. * 页面上拉触底事件的处理函数
  112. */
  113. /**
  114. * 生命周期函数--监听页面隐藏
  115. */
  116. onHide: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面卸载
  120. */
  121. onUnload: function () {
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh: function () {
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage: function (res) {
  132. },
  133. })