statistics.js 6.0 KB

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