statistics.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. userInfo: '',
  12. totalInfo: '',
  13. startDate: '2019-10-29',
  14. endDate: '2019-10-29',
  15. listCollege: '',
  16. listDept: '',
  17. userArray: [
  18. [],
  19. []
  20. ],
  21. value: [0, 0],
  22. weiguiList: []
  23. },
  24. bindStartDateChange: function(e) {
  25. this.setData({
  26. startDate: e.detail.value
  27. })
  28. },
  29. bindendDateChange: function(e) {
  30. this.setData({
  31. endDate: e.detail.value
  32. })
  33. },
  34. getCollegeInfo: function(e) {
  35. const that = this;
  36. util.httpRequest(api.getDeptInfo, {
  37. companyId: that.data.userInfo.companyId,
  38. level: 1
  39. }, 'post').then(res => {
  40. let arrayCollege = [];
  41. if (res.data.length >= 1) {
  42. for (let i = 0; i < res.data.length; i++) {
  43. arrayCollege.push(res.data[i].deptName)
  44. if (i == res.data.length - 1) {
  45. let userArray = that.data.userArray;
  46. userArray[0] = arrayCollege;
  47. that.setData({
  48. userArray: userArray,
  49. listCollege: res.data
  50. })
  51. that.getDeptInfo();
  52. }
  53. }
  54. }
  55. })
  56. },
  57. getDeptInfo: function(e) {
  58. const that = this;
  59. util.httpRequest(api.getDeptInfo, {
  60. companyId: that.data.userInfo.companyId,
  61. parentId: that.data.listCollege[that.data.value[0]].deptId
  62. }, 'post').then(res => {
  63. let arrayDept = [];
  64. if (res.data.length >= 1) {
  65. for (let i = 0; i < res.data.length; i++) {
  66. arrayDept.push(res.data[i].deptName)
  67. if (i == res.data.length - 1) {
  68. let userArray = that.data.userArray
  69. userArray[1] = arrayDept
  70. that.setData({
  71. userArray: userArray,
  72. listDept: res.data
  73. })
  74. that.getStatisticsInfo();
  75. }
  76. }
  77. } else {
  78. let userArray = that.data.userArray;
  79. userArray[1] = arrayDept
  80. that.setData({
  81. userArray: userArray,
  82. listDept: '',
  83. list: ''
  84. })
  85. }
  86. })
  87. },
  88. bindUserChange: function(e) {
  89. },
  90. columnChange: function(e) {
  91. const that = this;
  92. let value = that.data.value
  93. value[e.detail.column] = e.detail.value
  94. that.setData({
  95. value: value
  96. })
  97. if (e.detail.column == 0) {
  98. that.getDeptInfo()
  99. } else if (e.detail.column == 1) {
  100. that.getStatisticsInfo();
  101. }
  102. },
  103. getChart: function(e) {
  104. const that = this;
  105. ringChart = new wxCharts({
  106. animation: true,
  107. canvasId: 'ringCanvas',
  108. type: 'ring',
  109. extra: {
  110. ringWidth: 10,
  111. pie: {
  112. offsetAngle: -40
  113. }
  114. },
  115. title: {
  116. name: '归勤率',
  117. color: '#333',
  118. fontSize: 15
  119. },
  120. subtitle: {
  121. name: that.data.totalInfo.attendance * 100 + '%',
  122. color: '#6282f4',
  123. fontSize: 18
  124. },
  125. series: [{
  126. name: '归勤',
  127. data: that.data.totalInfo.attendance * 100,
  128. stroke: false,
  129. color: '#6282f4'
  130. }, {
  131. name: '缺勤',
  132. data: 100 - that.data.totalInfo.attendance * 100,
  133. stroke: false,
  134. color: '#ed5c68'
  135. }],
  136. disablePieStroke: true,
  137. width: 160,
  138. height: 160,
  139. dataLabel: false,
  140. legend: false,
  141. background: '#fff',
  142. padding: 0
  143. });
  144. ringChart.addEventListener('renderComplete', () => {
  145. console.log('renderComplete');
  146. });
  147. setTimeout(() => {
  148. ringChart.stopAnimation();
  149. }, 500);
  150. },
  151. touchHandler: function(e) {
  152. console.log(ringChart.getCurrentDataIndex(e));
  153. },
  154. getStatisticsInfo: function(e) {
  155. const that = this;
  156. let deptId;
  157. if (that.data.listDept != '') {
  158. deptId = that.data.listDept[that.data.value[1]].deptId
  159. } else {
  160. deptId = that.data.listCollege[that.data.value[0]].deptId
  161. }
  162. util.httpRequest(api.getStatisticsInfo, {
  163. start: that.data.startDate,
  164. end: that.data.endDate,
  165. deptId: deptId
  166. }, 'post').then(res => {
  167. that.setData({
  168. totalInfo: res.data.data
  169. })
  170. that.getChart();
  171. })
  172. },
  173. getUnInInfo: function(e) {
  174. const that = this;
  175. util.httpRequest(api.getUnInfo, {
  176. start: that.data.startDate,
  177. end: that.data.endDate,
  178. page: 1,
  179. rows: 20
  180. }, 'post').then(res => {
  181. })
  182. },
  183. getOutAndInInfo: function(e) {
  184. const that = this;
  185. util.httpRequest(api.getOutAndInInfo, {
  186. startDate: that.data.startDate,
  187. endDate: that.data.endDate,
  188. page: 1,
  189. rows: 20
  190. }, 'post').then(res => {
  191. that.setData({
  192. weiguiList: res.data.data.data
  193. })
  194. })
  195. },
  196. /**
  197. * 生命周期函数--监听页面加载
  198. */
  199. onLoad: function(options) {
  200. const that = this;
  201. that.data.userInfo = wx.getStorageSync('user');
  202. that.getCollegeInfo();
  203. that.getUnInInfo();
  204. that.getOutAndInInfo();
  205. },
  206. /**
  207. * 生命周期函数--监听页面初次渲染完成
  208. */
  209. onReady: function() {
  210. },
  211. /**
  212. * 生命周期函数--监听页面显示
  213. */
  214. onShow: function() {
  215. },
  216. /**
  217. * 生命周期函数--监听页面隐藏
  218. */
  219. onHide: function() {
  220. },
  221. /**
  222. * 生命周期函数--监听页面卸载
  223. */
  224. onUnload: function() {
  225. },
  226. /**
  227. * 页面相关事件处理函数--监听用户下拉动作
  228. */
  229. onPullDownRefresh: function() {
  230. },
  231. /**
  232. * 页面上拉触底事件的处理函数
  233. */
  234. onReachBottom: function() {
  235. }
  236. })