list.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. const app = getApp()
  2. import * as echarts from '../../../commpents/ec-canvas/echarts'
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '付费情况', leftArrow: true, useBar: false },
  6. },
  7. // 返回
  8. back(e) {
  9. wx.navigateBack({ delta: 1 })
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. },
  16. // 监听用户是否登录
  17. watchLogin: async function () {
  18. const that = this;
  19. wx.getStorage({
  20. key: 'user',
  21. success: async res => {
  22. that.setData({
  23. ec: {
  24. onInit: that.initChart
  25. }
  26. })
  27. // 模拟请求
  28. var times = setTimeout(async function () {
  29. // 数据
  30. that.data.xdata = [
  31. { value: 2, name: '1月(钱数)' },
  32. { value: 10, name: '2月(钱数)' },
  33. { value: 19, name: '3月(钱数)' },
  34. { value: 20, name: '4月(钱数)' },
  35. { value: 70, name: '5月(钱数)' },
  36. { value: 9, name: '6月(钱数)' },
  37. { value: 12, name: '7月(钱数)' },
  38. { value: 41, name: '8月(钱数)' },
  39. { value: 31, name: '9月(钱数)' },
  40. { value: 13, name: '10月(钱数)' },
  41. { value: 16, name: '11月(钱数)' },
  42. { value: 10, name: '12月(钱数)' }
  43. ];
  44. clearTimeout(times);
  45. }, 1000)
  46. },
  47. fail: async res => {
  48. wx.redirectTo({ url: '/pages/index/index' })
  49. }
  50. })
  51. },
  52. // 饼图
  53. initChart(canvas, width, height, dpr) {
  54. let that = this;
  55. // 由于请求数据有延迟所以写一个时间函数,当数据存在的时候再执行绘制
  56. var times = setInterval(function () {
  57. var xdata = that.data.xdata;
  58. if (xdata) {
  59. clearInterval(times)
  60. const chart = echarts.init(canvas, null, {
  61. width: width,
  62. height: height,
  63. devicePixelRatio: dpr // new
  64. });
  65. canvas.setChart(chart);
  66. var option = {
  67. tooltip: {
  68. trigger: 'item'
  69. },
  70. series: [
  71. {
  72. name: 'Access From',
  73. type: 'pie',
  74. radius: '50%',
  75. data: xdata,
  76. emphasis: {
  77. itemStyle: {
  78. shadowBlur: 10,
  79. shadowOffsetX: 0,
  80. shadowColor: 'rgba(0, 0, 0, 0.5)'
  81. }
  82. }
  83. }
  84. ]
  85. };
  86. chart.setOption(option, true);
  87. return chart;
  88. }
  89. }, 100)
  90. },
  91. /**
  92. * 生命周期函数--监听页面初次渲染完成
  93. */
  94. onReady: function () { },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow: function () {
  99. const that = this;
  100. // 监听用户是否登录
  101. that.watchLogin();
  102. },
  103. /**
  104. * 页面上拉触底事件的处理函数
  105. */
  106. /**
  107. * 生命周期函数--监听页面隐藏
  108. */
  109. onHide: function () {
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload: function () {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function () {
  120. },
  121. /**
  122. * 用户点击右上角分享
  123. */
  124. onShareAppMessage: function (res) {
  125. },
  126. })