statistics.js 5.9 KB

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