statistics.js 12 KB

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