statistics.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. state: '',
  23. listTitle: '无进出记录人员',
  24. list: []
  25. },
  26. getCurrentDate: function(e) {
  27. let date = new Date();
  28. let year = date.getFullYear();
  29. let month = date.getMonth() + 1;
  30. let day = date.getDate();
  31. month = month < 10 ? "0" + month : month;
  32. day = day < 10 ? "0" + day : day;
  33. date = year + '-' + month + '-' + day
  34. this.setData({
  35. startDate: date,
  36. endDate: date
  37. })
  38. },
  39. bindStartDateChange: function(e) {
  40. this.setData({
  41. startDate: e.detail.value
  42. })
  43. this.getStatisticsInfo();
  44. this.getUnInInfo();
  45. },
  46. bindendDateChange: function(e) {
  47. this.setData({
  48. endDate: e.detail.value
  49. })
  50. this.getStatisticsInfo();
  51. this.getUnInInfo();
  52. },
  53. getCollegeInfo: function(e) {
  54. const that = this;
  55. util.httpRequest(api.getDeptInfo, {
  56. companyId: that.data.userInfo.companyId,
  57. level: 1
  58. }, 'post').then(res => {
  59. let arrayCollege = [];
  60. if (res.data.length >= 1) {
  61. for (let i = 0; i < res.data.length; i++) {
  62. arrayCollege.push(res.data[i].deptName)
  63. if (i == res.data.length - 1) {
  64. let userArray = that.data.userArray;
  65. userArray[0] = arrayCollege;
  66. that.setData({
  67. userArray: userArray,
  68. listCollege: res.data
  69. })
  70. that.getDeptInfo();
  71. }
  72. }
  73. }
  74. })
  75. },
  76. getDeptInfo: function(e) {
  77. const that = this;
  78. util.httpRequest(api.getDeptInfo, {
  79. companyId: that.data.userInfo.companyId,
  80. parentId: that.data.listCollege[that.data.value[0]].deptId
  81. }, 'post').then(res => {
  82. let arrayDept = [];
  83. if (res.data.length >= 1) {
  84. for (let i = 0; i < res.data.length; i++) {
  85. arrayDept.push(res.data[i].deptName)
  86. if (i == res.data.length - 1) {
  87. let userArray = that.data.userArray
  88. userArray[1] = arrayDept
  89. that.setData({
  90. userArray: userArray,
  91. listDept: res.data
  92. })
  93. that.getStatisticsInfo();
  94. that.getUnOut();
  95. }
  96. }
  97. } else {
  98. let userArray = that.data.userArray;
  99. userArray[1] = arrayDept
  100. that.setData({
  101. userArray: userArray,
  102. listDept: '',
  103. list: ''
  104. })
  105. }
  106. })
  107. },
  108. bindUserChange: function(e) {
  109. },
  110. columnChange: function(e) {
  111. const that = this;
  112. let value = that.data.value
  113. value[e.detail.column] = e.detail.value
  114. that.setData({
  115. value: value
  116. })
  117. if (e.detail.column == 0) {
  118. that.getDeptInfo()
  119. } else if (e.detail.column == 1) {
  120. that.getStatisticsInfo();
  121. }
  122. },
  123. getChart: function(e) {
  124. const that = this;
  125. ringChart = new wxCharts({
  126. animation: true,
  127. canvasId: 'ringCanvas',
  128. type: 'ring',
  129. extra: {
  130. ringWidth: 10,
  131. pie: {
  132. offsetAngle: -40
  133. }
  134. },
  135. title: {
  136. name: '归勤率',
  137. color: '#333',
  138. fontSize: 15
  139. },
  140. subtitle: {
  141. name: that.data.totalInfo.attendance + '%',
  142. color: '#6282f4',
  143. fontSize: 18
  144. },
  145. series: [{
  146. name: '归勤',
  147. data: that.data.totalInfo.attendance * 100,
  148. stroke: false,
  149. color: '#6282f4'
  150. }, {
  151. name: '缺勤',
  152. data: 100 - that.data.totalInfo.attendance * 100,
  153. stroke: false,
  154. color: '#ed5c68'
  155. }],
  156. disablePieStroke: true,
  157. width: 160,
  158. height: 160,
  159. dataLabel: false,
  160. legend: false,
  161. background: '#fff',
  162. padding: 0
  163. });
  164. ringChart.addEventListener('renderComplete', () => {
  165. console.log('renderComplete');
  166. });
  167. setTimeout(() => {
  168. ringChart.stopAnimation();
  169. }, 500);
  170. },
  171. touchHandler: function(e) {
  172. console.log(ringChart.getCurrentDataIndex(e));
  173. },
  174. getStatisticsInfo: function(e) {
  175. const that = this;
  176. let deptId;
  177. if (that.data.listDept != '') {
  178. deptId = that.data.listDept[that.data.value[1]].deptId
  179. } else {
  180. deptId = that.data.listCollege[that.data.value[0]].deptId
  181. }
  182. util.httpRequest(api.getStatisticsInfo, {
  183. start: that.data.startDate,
  184. end: that.data.endDate,
  185. deptId: deptId
  186. }, 'post').then(res => {
  187. that.setData({
  188. totalInfo: res.data.data
  189. })
  190. that.getChart();
  191. })
  192. },
  193. getUnInInfo: function(e) {
  194. const that = this;
  195. util.httpRequest(api.getUnInInfo, {
  196. start: that.data.startDate,
  197. end: that.data.endDate,
  198. page: 1,
  199. rows: 20
  200. }, 'post').then(res => {
  201. that.setData({
  202. list: res.data.data.data
  203. })
  204. })
  205. },
  206. getOutAndInInfo: function(e) {
  207. const that = this;
  208. let deptId;
  209. if (that.data.listDept != '') {
  210. deptId = that.data.listDept[that.data.value[1]].deptId
  211. } else {
  212. deptId = that.data.listCollege[that.data.value[0]].deptId
  213. }
  214. util.httpRequest(api.getOutAndInInfo, {
  215. startDate: that.data.startDate,
  216. endDate: that.data.endDate,
  217. page: 1,
  218. rows: 20,
  219. deptId: deptId,
  220. state: that.data.state
  221. }, 'post').then(res => {
  222. that.setData({
  223. list: res.data.data.data
  224. })
  225. })
  226. },
  227. getUnOut: function(e) {
  228. const that = this;
  229. let deptId;
  230. if (that.data.listDept != '') {
  231. deptId = that.data.listDept[that.data.value[1]].deptId
  232. } else {
  233. deptId = that.data.listCollege[that.data.value[0]].deptId
  234. }
  235. util.httpRequest(api.getUnOut, {
  236. start: that.data.startDate,
  237. end: that.data.endDate,
  238. page: 1,
  239. rows: 20,
  240. deptId: deptId
  241. }, 'post').then(res => {
  242. that.setData({
  243. list: res.data.data.data
  244. })
  245. })
  246. },
  247. getLateIn: function(e) {
  248. const that = this;
  249. let deptId;
  250. if (that.data.listDept != '') {
  251. deptId = that.data.listDept[that.data.value[1]].deptId
  252. } else {
  253. deptId = that.data.listCollege[that.data.value[0]].deptId
  254. }
  255. util.httpRequest(api.getLateIn, {
  256. start: that.data.startDate,
  257. end: that.data.endDate,
  258. page: 1,
  259. rows: 20,
  260. deptId: deptId
  261. }, 'post').then(res => {
  262. that.setData({
  263. list: res.data.data.data
  264. })
  265. })
  266. },
  267. getInUnOut: function(e) {
  268. const that = this;
  269. let deptId;
  270. if (that.data.listDept != '') {
  271. deptId = that.data.listDept[that.data.value[1]].deptId
  272. } else {
  273. deptId = that.data.listCollege[that.data.value[0]].deptId
  274. }
  275. util.httpRequest(api.getInUnOunt, {
  276. start: that.data.startDate,
  277. end: that.data.endDate,
  278. page: 1,
  279. rows: 20,
  280. deptId: deptId
  281. }, 'post').then(res => {
  282. that.setData({
  283. list: res.data.data.data
  284. })
  285. })
  286. },
  287. qiehuan: function(e) {
  288. const that = this;
  289. let type = e.currentTarget.dataset.type;
  290. let state = e.currentTarget.dataset.state;
  291. if (type == 1) {
  292. that.setData({
  293. listTitle: '无进出记录人员'
  294. })
  295. that.getUnOut();
  296. } else if (type == 2) {
  297. that.setData({
  298. listTitle: '已出宿舍人员',
  299. state: state
  300. })
  301. that.getOutAndInInfo();
  302. } else if (type == 3) {
  303. that.setData({
  304. listTitle: '已归宿舍人员',
  305. state: state
  306. })
  307. that.getOutAndInInfo();
  308. } else if (type == 4) {
  309. that.setData({
  310. listTitle: '晚归宿舍人员'
  311. })
  312. that.getLateIn();
  313. } else if (type == 5) {
  314. that.setData({
  315. listTitle: '未归宿舍人员'
  316. })
  317. that.getUnInInfo();
  318. } else if (type == 6) {
  319. that.setData({
  320. listTitle: '未出宿舍人员'
  321. })
  322. that.getInUnOut();
  323. }
  324. },
  325. /**
  326. * 生命周期函数--监听页面加载
  327. */
  328. onLoad: function(options) {
  329. const that = this;
  330. that.getCurrentDate();
  331. that.data.userInfo = wx.getStorageSync('user');
  332. that.getCollegeInfo();
  333. },
  334. /**
  335. * 生命周期函数--监听页面初次渲染完成
  336. */
  337. onReady: function() {
  338. },
  339. /**
  340. * 生命周期函数--监听页面显示
  341. */
  342. onShow: function() {
  343. },
  344. /**
  345. * 生命周期函数--监听页面隐藏
  346. */
  347. onHide: function() {
  348. },
  349. /**
  350. * 生命周期函数--监听页面卸载
  351. */
  352. onUnload: function() {
  353. },
  354. /**
  355. * 页面相关事件处理函数--监听用户下拉动作
  356. */
  357. onPullDownRefresh: function() {
  358. },
  359. /**
  360. * 页面上拉触底事件的处理函数
  361. */
  362. onReachBottom: function() {
  363. }
  364. })