statistics.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var wxCharts = require('../../../utils/wxcharts.js');
  2. var data = require('../../../utils/util.js');
  3. const api = require('../../../utils/api.js');
  4. var ringChart = null;
  5. Page({
  6. data: {
  7. },
  8. bindDateChange(e) {
  9. this.setData({
  10. startdata: e.detail.value
  11. })
  12. this.req(e.detail.value,this.data.enddata)
  13. },
  14. bindendDateChange(e){
  15. this.setData({
  16. enddata: e.detail.value
  17. })
  18. this.req(this.data.startdata, e.detail.value)
  19. },
  20. touchHandler: function (e) {
  21. console.log(ringChart.getCurrentDataIndex(e));
  22. },
  23. onLoad(options){
  24. },
  25. req: function (start,end){
  26. let that = this
  27. wx.showLoading({
  28. title: '正在加载',
  29. })
  30. wx.request({
  31. url: api.selfInfo,
  32. data: {
  33. loginId: wx.getStorageSync('loginId'),
  34. start: start,
  35. end: end
  36. },
  37. success(res) {
  38. // res.data.data.nomalInTimes=130
  39. // res.data.data.nomalOutTimes = 40
  40. // res.data.data.laterTimes = 50
  41. // res.data.data.UnreturnedTimes = 20
  42. wx.hideLoading()
  43. that.setData({
  44. data: res.data.data
  45. })
  46. ringChart.updateData({
  47. title: {
  48. name: '汇总'
  49. },
  50. subtitle: {
  51. color: '#333333'
  52. },
  53. series: [{
  54. name: '正常进入',
  55. data: res.data.data.nomalInTimes,
  56. stroke: false,
  57. color: '#6282f4'
  58. }, {
  59. name: '正常外出',
  60. data: res.data.data.nomalOutTimes,
  61. stroke: false,
  62. color: '#ed5c68'
  63. }, {
  64. name: '晚归',
  65. data: res.data.data.laterTimes,
  66. stroke: false,
  67. color: '#89c997'
  68. }, {
  69. name: '未归寝',
  70. data: res.data.data.UnreturnedTimes,
  71. stroke: false,
  72. color: '#f29b76'
  73. }],
  74. });
  75. }
  76. })
  77. },
  78. onReady: function (e) {
  79. let that=this
  80. this.setData({
  81. enddata:data.formatDate(),
  82. checkenddate: data.formatDate(),
  83. startdata: data.getDateStr(data.formatDate(),-30)
  84. })
  85. var windowWidth = 320;
  86. try {
  87. var res = wx.getSystemInfoSync();
  88. windowWidth = res.windowWidth;
  89. } catch (e) {
  90. console.error('getSystemInfoSync failed!');
  91. }
  92. ringChart = new wxCharts({
  93. animation: true,
  94. canvasId: 'ringCanvas',
  95. type: 'ring',
  96. extra: {
  97. ringWidth: 25,
  98. pie: {
  99. offsetAngle: -45
  100. }
  101. },
  102. title: {
  103. name: '汇总',
  104. color: '#333',
  105. fontSize: 18
  106. },
  107. subtitle: {
  108. name: '',
  109. color: '#6282f4',
  110. fontSize: 15
  111. },
  112. series: [{
  113. name: '正常进入',
  114. data: 0,
  115. stroke: false,
  116. color:'#6282f4'
  117. }, {
  118. name: '正常外出',
  119. data: 0,
  120. stroke: false,
  121. color:'#ed5c68'
  122. }, {
  123. name: '晚归',
  124. data: 0,
  125. stroke: false,
  126. color:'#89c997'
  127. }, {
  128. name: '未归寝',
  129. data: 0,
  130. stroke: false,
  131. color:'#f29b76'
  132. }],
  133. disablePieStroke: true,
  134. width: 200,
  135. height: 200,
  136. dataLabel: false,
  137. legend: false,
  138. background: '#fff',
  139. padding: 0
  140. });
  141. ringChart.addEventListener('renderComplete', () => {
  142. console.log('renderComplete');
  143. });
  144. setTimeout(() => {
  145. ringChart.stopAnimation();
  146. }, 500);
  147. this.data.startdata = data.getDateStr(data.formatDate(), -30)
  148. this.data.enddata = data.formatDate()
  149. this.req(this.data.startdata, this.data.enddata)
  150. this.setData({
  151. user: wx.getStorageSync('user')
  152. })
  153. }
  154. });