coach.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. // 选中
  8. tabs: {
  9. active: '0',
  10. menu: [
  11. { title: '教练出勤率', active: '0' },
  12. { title: '教练收入情况', active: '1' },
  13. ]
  14. },
  15. // 教练
  16. zhcoach: '',
  17. coach_id: '',
  18. coachList: [],
  19. value: [],
  20. date: [],
  21. },
  22. // 返回
  23. back(e) {
  24. wx.navigateBack({ delta: 1 })
  25. },
  26. // 选项卡选择
  27. tabsChange: function (e) {
  28. const that = this;
  29. let data = e.detail;
  30. that.setData({ 'tabs.active': data.active })
  31. that.watchLogin();
  32. },
  33. // 选择教练
  34. coachChange: async function (e) {
  35. const that = this;
  36. let data = that.data.coachList[e.detail.value];
  37. if (data) {
  38. that.setData({ coach_id: data.coach_id });
  39. that.setData({ zhcoach: data.coach_id_name });
  40. }
  41. await that.watchLogin();
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: async function (options) {
  47. const that = this;
  48. that.setData({ ec: { onInit: that.initChart } })
  49. // 监听用户是否登录
  50. await that.watchLogin();
  51. },
  52. // 监听用户是否登录
  53. watchLogin: async function () {
  54. const that = this;
  55. wx.getStorage({
  56. key: 'user',
  57. success: async res => {
  58. // 教练
  59. const abb = await app.$get(`/rcs`, { school_id: res.data.info.id });
  60. if (abb.errcode == '0' && abb.total > 0) {
  61. that.setData({ coachList: abb.data })
  62. }
  63. if (that.data.coach_id) {
  64. if (that.data.tabs.active == '0') {
  65. const arr = await app.$get(`/statistics/schoolSignCoach`, { school_id: res.data.info.id, coach_id: that.data.coach_id });
  66. if (arr.errcode == '0') {
  67. var date = []
  68. var value = []
  69. arr.data.map(function (item) {
  70. var m = ''; m = item.m; date.push(m)
  71. var sevm = '';
  72. sevm = item.value.split('%').join('')
  73. value.push(sevm)
  74. })
  75. that.setData({ date: date })
  76. that.setData({ value: value })
  77. const option = {
  78. xAxis: [{ data: date, }],
  79. yAxis: [{
  80. axisLabel: {
  81. formatter: '{value}%',
  82. },
  83. }],
  84. series: [{
  85. data: value,
  86. itemStyle: {
  87. normal: {
  88. label: { show: true, formatter: '{c}%', }
  89. }
  90. },
  91. }],
  92. tooltip: [{ formatter: '{b}月:出勤率{c}%' }]
  93. }
  94. if (chart) chart.setOption(option)
  95. }
  96. } else {
  97. const arr = await app.$get(`/statistics/schoolCoachIn`, { school_id: res.data.info.id, coach_id: that.data.coach_id });
  98. if (arr.errcode == '0') {
  99. var date = []
  100. var value = []
  101. arr.data.map(function (item) {
  102. var m = ''; m = item.m; date.push(m)
  103. var sevm = ''; sevm = item.total; value.push(sevm)
  104. })
  105. that.setData({ date: date })
  106. that.setData({ value: value })
  107. const option = {
  108. xAxis: [{ data: date, }],
  109. yAxis: [{
  110. axisLabel: {
  111. formatter: '{value}元',
  112. },
  113. }],
  114. series: [{
  115. data: value,
  116. itemStyle: {
  117. normal: {
  118. label: { show: true, formatter: '{c}元', }
  119. }
  120. },
  121. }],
  122. tooltip: [{ formatter: '{b}月:收入{c}元' }]
  123. }
  124. if (chart) chart.setOption(option)
  125. }
  126. }
  127. }
  128. },
  129. fail: async res => {
  130. wx.redirectTo({ url: '/pages/index/index' })
  131. }
  132. })
  133. },
  134. // 折线图
  135. initChart(canvas, width, height, dpr) {
  136. const that = this;
  137. var date = that.data.date;
  138. var value = that.data.value;
  139. chart = echarts.init(canvas, null, {
  140. width: width,
  141. height: height,
  142. devicePixelRatio: dpr
  143. });
  144. canvas.setChart(chart);
  145. var option = {
  146. grid: {
  147. left: 20,
  148. right: 20,
  149. bottom: 145,
  150. top: 60,
  151. containLabel: true
  152. },
  153. tooltip: {
  154. show: true,
  155. trigger: 'axis',
  156. formatter: '{b}:{c}' // 格式化数值百分比输出
  157. },
  158. xAxis: {
  159. type: 'category',
  160. boundaryGap: false,
  161. data: date,
  162. // 设置x轴线的属性
  163. //使x轴文字显示全
  164. axisLabel: {
  165. formatter: '{value}月',
  166. show: true, interval: 0,
  167. },
  168. },
  169. yAxis: {
  170. x: 'center',
  171. type: 'value',
  172. splitLine: {
  173. lineStyle: { type: 'dashed' }
  174. },
  175. },
  176. series: [
  177. {
  178. type: 'line',
  179. smooth: true,
  180. data: value,
  181. itemStyle: {
  182. normal: {
  183. color: '#ff7f50',
  184. lineStyle: { color: '#5470C6' },
  185. label: { show: true }
  186. }
  187. },
  188. }
  189. ]
  190. };
  191. chart.setOption(option, true);
  192. return chart;
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onReady: function () { },
  198. /**
  199. * 生命周期函数--监听页面显示
  200. */
  201. onShow: function () {
  202. },
  203. /**
  204. * 页面上拉触底事件的处理函数
  205. */
  206. /**
  207. * 生命周期函数--监听页面隐藏
  208. */
  209. onHide: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面卸载
  213. */
  214. onUnload: function () {
  215. },
  216. /**
  217. * 页面相关事件处理函数--监听用户下拉动作
  218. */
  219. onPullDownRefresh: function () {
  220. },
  221. /**
  222. * 用户点击右上角分享
  223. */
  224. onShareAppMessage: function (res) {
  225. },
  226. })