lecture.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. xdata: [],
  8. // 学校
  9. zhSchool: '',
  10. school_id: '',
  11. schoolList: [],
  12. },
  13. // 返回
  14. back(e) {
  15. wx.navigateBack({ delta: 1 })
  16. },
  17. // 选择学校
  18. schoolChange: function (e) {
  19. const that = this;
  20. let data = that.data.schoolList[e.detail.value];
  21. if (data) {
  22. that.setData({ school_id: data.school_id });
  23. that.setData({ zhSchool: data.school_id_name });
  24. }
  25. that.watchLogin();
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: async function (options) {
  31. const that = this;
  32. that.setData({ ec: { onInit: that.initChart } })
  33. // 监听用户是否登录
  34. await that.watchLogin();
  35. },
  36. // 监听用户是否登录
  37. watchLogin: async function () {
  38. const that = this;
  39. wx.getStorage({
  40. key: 'user',
  41. success: async res => {
  42. // 学校
  43. const school = await app.$get(`/rcs`, { coach_id: res.data.info.id });
  44. if (school.errcode == '0' && school.total > 0) {
  45. that.setData({ schoolList: school.data })
  46. }
  47. if (that.data.school_id) {
  48. const arr = await app.$get(`/statistics/coachLesson`, { school_id: that.data.school_id, coach_id: res.data.info.id });
  49. if (arr.errcode == '0') {
  50. that.setData({ xdata: arr.data })
  51. const option = {
  52. series: [{ data: arr.data }],
  53. }
  54. if (chart) chart.setOption(option)
  55. }
  56. }
  57. },
  58. fail: async res => {
  59. wx.redirectTo({ url: '/pages/index/index' })
  60. }
  61. })
  62. },
  63. // 饼图
  64. initChart(canvas, width, height, dpr) {
  65. const that = this;
  66. var xdata = that.data.xdata;
  67. chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr });
  68. canvas.setChart(chart);
  69. var option = {
  70. tooltip: { trigger: 'item' },
  71. legend: {
  72. orient: 'vertical',
  73. height: 40,
  74. padding: 50
  75. },
  76. series: [
  77. {
  78. name: '授课情况',
  79. type: 'pie',
  80. radius: '50%',
  81. data: xdata,
  82. emphasis: {
  83. itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' }
  84. },
  85. label: {
  86. normal: {
  87. show: true,
  88. formatter: '{b}({c}节课)'
  89. }
  90. }
  91. }
  92. ]
  93. };
  94. chart.setOption(option, true);
  95. return chart;
  96. },
  97. /**
  98. * 生命周期函数--监听页面初次渲染完成
  99. */
  100. onReady: function () { },
  101. /**
  102. * 生命周期函数--监听页面显示
  103. */
  104. onShow: function () {
  105. },
  106. /**
  107. * 页面上拉触底事件的处理函数
  108. */
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面卸载
  116. */
  117. onUnload: function () {
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh: function () {
  123. },
  124. /**
  125. * 用户点击右上角分享
  126. */
  127. onShareAppMessage: function (res) {
  128. },
  129. })