list.js 3.6 KB

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