statistics.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. if (that.data.totalInfo.total == 0) {
  137. ringChart = new wxCharts({
  138. animation: true,
  139. canvasId: 'ringCanvas',
  140. type: 'ring',
  141. extra: {
  142. ringWidth: 10,
  143. pie: {
  144. offsetAngle: -40
  145. }
  146. },
  147. title: {
  148. name: '归勤率',
  149. color: '#333',
  150. fontSize: 15
  151. },
  152. subtitle: {
  153. name: '100%',
  154. color: '#6282f4',
  155. fontSize: 18
  156. },
  157. series: [{
  158. name: '已归宿舍人员',
  159. data: 1,
  160. stroke: false,
  161. color: '#7792f5'
  162. }, ],
  163. disablePieStroke: true,
  164. width: 160,
  165. height: 160,
  166. dataLabel: false,
  167. legend: false,
  168. background: '#fff',
  169. padding: 0
  170. });
  171. ringChart.addEventListener('renderComplete', () => {
  172. console.log('renderComplete');
  173. });
  174. setTimeout(() => {
  175. ringChart.stopAnimation();
  176. }, 500);
  177. } else {
  178. ringChart = new wxCharts({
  179. animation: true,
  180. canvasId: 'ringCanvas',
  181. type: 'ring',
  182. extra: {
  183. ringWidth: 10,
  184. pie: {
  185. offsetAngle: -40
  186. }
  187. },
  188. title: {
  189. name: '归勤率',
  190. color: '#333',
  191. fontSize: 15
  192. },
  193. subtitle: {
  194. name: that.data.totalInfo.attendance * 100 + '%',
  195. color: '#6282f4',
  196. fontSize: 18
  197. },
  198. series: [{
  199. name: '无进出记录人员',
  200. data: that.data.totalInfo.unAccessCount / that.data.totalInfo.total,
  201. stroke: false,
  202. color: '#ed5c68'
  203. }, {
  204. name: '已出宿舍人员',
  205. data: that.data.totalInfo.out / that.data.totalInfo.total,
  206. stroke: false,
  207. color: '#f5a786'
  208. }, {
  209. name: '已归宿舍人员',
  210. data: that.data.totalInfo.in / that.data.totalInfo.total,
  211. stroke: false,
  212. color: '#7792f5'
  213. }, {
  214. name: '晚归宿舍人员',
  215. data: that.data.totalInfo.laterIn / that.data.totalInfo.total,
  216. stroke: false,
  217. color: '#79bef4'
  218. }, {
  219. name: '未归宿舍人员',
  220. data: that.data.totalInfo.unIn / that.data.totalInfo.total,
  221. stroke: false,
  222. color: '#5be0c1'
  223. }, {
  224. name: '未出宿舍人员',
  225. data: that.data.totalInfo.unOut / that.data.totalInfo.total,
  226. stroke: false,
  227. color: '#ac91f7'
  228. }],
  229. disablePieStroke: true,
  230. width: 160,
  231. height: 160,
  232. dataLabel: false,
  233. legend: false,
  234. background: '#fff',
  235. padding: 0
  236. });
  237. ringChart.addEventListener('renderComplete', () => {
  238. console.log('renderComplete');
  239. });
  240. setTimeout(() => {
  241. ringChart.stopAnimation();
  242. }, 500);
  243. }
  244. },
  245. touchHandler: function(e) {
  246. console.log(ringChart.getCurrentDataIndex(e));
  247. },
  248. getStatisticsInfo: function(e) {
  249. const that = this;
  250. let deptId;
  251. if (that.data.listDept != '') {
  252. deptId = that.data.listDept[that.data.value[1]].deptId
  253. } else {
  254. deptId = that.data.listCollege[that.data.value[0]].deptId
  255. }
  256. util.httpRequest(api.getStatisticsInfo, {
  257. start: that.data.startDate,
  258. end: that.data.endDate,
  259. deptId: deptId
  260. }, 'post').then(res => {
  261. that.setData({
  262. totalInfo: res.data.data
  263. })
  264. that.getChart();
  265. })
  266. },
  267. getUnInInfo: 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.getUnInInfo, {
  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. getOutAndInInfo: function(e) {
  288. const that = this;
  289. let deptId;
  290. if (that.data.listDept != '') {
  291. deptId = that.data.listDept[that.data.value[1]].deptId
  292. } else {
  293. deptId = that.data.listCollege[that.data.value[0]].deptId
  294. }
  295. util.httpRequest(api.getOutAndInInfo, {
  296. startDate: that.data.startDate,
  297. endDate: that.data.endDate,
  298. page: 1,
  299. rows: 20,
  300. deptId: deptId,
  301. state: that.data.state
  302. }, 'post').then(res => {
  303. that.setData({
  304. list: res.data.data.data
  305. })
  306. })
  307. },
  308. getUnOut: function(e) {
  309. const that = this;
  310. let deptId;
  311. if (that.data.listDept != '') {
  312. deptId = that.data.listDept[that.data.value[1]].deptId
  313. } else {
  314. deptId = that.data.listCollege[that.data.value[0]].deptId
  315. }
  316. util.httpRequest(api.getUnOut, {
  317. start: that.data.startDate,
  318. end: that.data.endDate,
  319. page: 1,
  320. rows: 20,
  321. deptId: deptId
  322. }, 'post').then(res => {
  323. that.setData({
  324. list: res.data.data.data
  325. })
  326. })
  327. },
  328. getLateIn: function(e) {
  329. const that = this;
  330. let deptId;
  331. if (that.data.listDept != '') {
  332. deptId = that.data.listDept[that.data.value[1]].deptId
  333. } else {
  334. deptId = that.data.listCollege[that.data.value[0]].deptId
  335. }
  336. util.httpRequest(api.getLateIn, {
  337. start: that.data.startDate,
  338. end: that.data.endDate,
  339. page: 1,
  340. rows: 20,
  341. deptId: deptId
  342. }, 'post').then(res => {
  343. that.setData({
  344. list: res.data.data.data
  345. })
  346. })
  347. },
  348. getInUnOut: function(e) {
  349. const that = this;
  350. let deptId;
  351. if (that.data.listDept != '') {
  352. deptId = that.data.listDept[that.data.value[1]].deptId
  353. } else {
  354. deptId = that.data.listCollege[that.data.value[0]].deptId
  355. }
  356. util.httpRequest(api.getInUnOunt, {
  357. start: that.data.startDate,
  358. end: that.data.endDate,
  359. page: 1,
  360. rows: 20,
  361. deptId: deptId
  362. }, 'post').then(res => {
  363. that.setData({
  364. list: res.data.data.data
  365. })
  366. })
  367. },
  368. qiehuan: function(e) {
  369. const that = this;
  370. let type = e.currentTarget ? e.currentTarget.dataset.type : e;
  371. let state = e.currentTarget ? e.currentTarget.dataset.state : that.data.state;
  372. if (type == 1) {
  373. that.setData({
  374. listTitle: '无进出记录人员',
  375. type: 1
  376. })
  377. that.getUnOut();
  378. } else if (type == 2) {
  379. that.setData({
  380. listTitle: '已出宿舍人员',
  381. type: 2,
  382. state: state
  383. })
  384. that.getOutAndInInfo();
  385. } else if (type == 3) {
  386. that.setData({
  387. listTitle: '已归宿舍人员',
  388. type: 3,
  389. state: state
  390. })
  391. that.getOutAndInInfo();
  392. } else if (type == 4) {
  393. that.setData({
  394. listTitle: '晚归宿舍人员',
  395. type: 4
  396. })
  397. that.getLateIn();
  398. } else if (type == 5) {
  399. that.setData({
  400. listTitle: '未归宿舍人员',
  401. type: 5
  402. })
  403. that.getUnInInfo();
  404. } else if (type == 6) {
  405. that.setData({
  406. listTitle: '未出宿舍人员',
  407. type: 6
  408. })
  409. that.getInUnOut();
  410. }
  411. },
  412. /**
  413. * 生命周期函数--监听页面加载
  414. */
  415. onLoad: function(options) {
  416. const that = this;
  417. that.getCurrentDate();
  418. that.data.userInfo = wx.getStorageSync('user');
  419. that.getCollegeInfo();
  420. },
  421. /**
  422. * 生命周期函数--监听页面初次渲染完成
  423. */
  424. onReady: function() {
  425. },
  426. /**
  427. * 生命周期函数--监听页面显示
  428. */
  429. onShow: function() {
  430. },
  431. /**
  432. * 生命周期函数--监听页面隐藏
  433. */
  434. onHide: function() {
  435. },
  436. /**
  437. * 生命周期函数--监听页面卸载
  438. */
  439. onUnload: function() {
  440. },
  441. /**
  442. * 页面相关事件处理函数--监听用户下拉动作
  443. */
  444. onPullDownRefresh: function() {
  445. },
  446. /**
  447. * 页面上拉触底事件的处理函数
  448. */
  449. onReachBottom: function() {
  450. }
  451. })