statistics.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. const wxCharts = require('../../../utils/wxcharts.js');
  2. const util = require('../../../utils/util.js');
  3. const api = require('../../../utils/api.js');
  4. const app = getApp()
  5. let ringChart = null;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. totalInfo: '',
  12. startDate: '2019-10-29',
  13. endDate: '2019-10-29',
  14. scopeIndex: 0,
  15. scopeArray: ['全部人员'],
  16. weiguiList: []
  17. },
  18. bindStartDateChange: function(e) {
  19. this.setData({
  20. startDate: e.detail.value
  21. })
  22. },
  23. bindendDateChange: function(e) {
  24. this.setData({
  25. endDate: e.detail.value
  26. })
  27. },
  28. bindScopeChange: function(e) {
  29. this.setData({
  30. scopeIndex: e.detail.value
  31. })
  32. },
  33. getChart: function(e) {
  34. const that = this;
  35. ringChart = new wxCharts({
  36. animation: true,
  37. canvasId: 'ringCanvas',
  38. type: 'ring',
  39. extra: {
  40. ringWidth: 10,
  41. pie: {
  42. offsetAngle: -40
  43. }
  44. },
  45. title: {
  46. name: '归勤率',
  47. color: '#333',
  48. fontSize: 15
  49. },
  50. subtitle: {
  51. name: that.data.totalInfo.attendance * 100 + '%',
  52. color: '#6282f4',
  53. fontSize: 18
  54. },
  55. series: [{
  56. name: '归勤',
  57. data: that.data.totalInfo.attendance * 100,
  58. stroke: false,
  59. color: '#6282f4'
  60. }, {
  61. name: '缺勤',
  62. data: 100 - that.data.totalInfo.attendance * 100,
  63. stroke: false,
  64. color: '#ed5c68'
  65. }],
  66. disablePieStroke: true,
  67. width: 160,
  68. height: 160,
  69. dataLabel: false,
  70. legend: false,
  71. background: '#fff',
  72. padding: 0
  73. });
  74. ringChart.addEventListener('renderComplete', () => {
  75. console.log('renderComplete');
  76. });
  77. setTimeout(() => {
  78. ringChart.stopAnimation();
  79. }, 500);
  80. },
  81. touchHandler: function(e) {
  82. console.log(ringChart.getCurrentDataIndex(e));
  83. },
  84. getStatisticsInfo: function(e) {
  85. const that = this;
  86. util.httpRequest(api.getStatisticsInfo, {
  87. start: that.data.startDate,
  88. end: that.data.endDate
  89. }, 'post').then(res => {
  90. that.setData({
  91. totalInfo: res.data.data
  92. })
  93. that.getChart();
  94. })
  95. },
  96. getUnInInfo: function(e) {
  97. const that = this;
  98. util.httpRequest(api.getUnInfo, {
  99. start: that.data.startDate,
  100. end: that.data.endDate,
  101. page: 1,
  102. rows: 20
  103. }, 'post').then(res => {
  104. })
  105. },
  106. getOutAndInInfo: function(e) {
  107. const that = this;
  108. util.httpRequest(api.getOutAndInInfo, {
  109. startDate: that.data.startDate,
  110. endDate: that.data.endDate,
  111. page: 1,
  112. rows: 20
  113. }, 'post').then(res => {
  114. that.setData({
  115. weiguiList: res.data.data.data
  116. })
  117. })
  118. },
  119. /**
  120. * 生命周期函数--监听页面加载
  121. */
  122. onLoad: function(options) {
  123. const that = this;
  124. that.getStatisticsInfo();
  125. that.getUnInInfo();
  126. that.getOutAndInInfo();
  127. },
  128. /**
  129. * 生命周期函数--监听页面初次渲染完成
  130. */
  131. onReady: function() {
  132. },
  133. /**
  134. * 生命周期函数--监听页面显示
  135. */
  136. onShow: function() {
  137. },
  138. /**
  139. * 生命周期函数--监听页面隐藏
  140. */
  141. onHide: function() {
  142. },
  143. /**
  144. * 生命周期函数--监听页面卸载
  145. */
  146. onUnload: function() {
  147. },
  148. /**
  149. * 页面相关事件处理函数--监听用户下拉动作
  150. */
  151. onPullDownRefresh: function() {
  152. },
  153. /**
  154. * 页面上拉触底事件的处理函数
  155. */
  156. onReachBottom: function() {
  157. }
  158. })