statistics.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. let userArray = that.data.userArray;
  100. userArray[1] = arrayDept
  101. that.setData({
  102. userArray: userArray,
  103. listDept: '',
  104. list: ''
  105. })
  106. }
  107. })
  108. },
  109. bindUserChange: function(e) {
  110. },
  111. columnChange: function(e) {
  112. const that = this;
  113. let value = that.data.value
  114. value[e.detail.column] = e.detail.value
  115. that.setData({
  116. value: value
  117. })
  118. if (e.detail.column == 0) {
  119. that.getDeptInfo()
  120. } else if (e.detail.column == 1) {
  121. that.getStatisticsInfo();
  122. that.qiehuan(that.data.type)
  123. }
  124. },
  125. getChart: function(e) {
  126. const that = this;
  127. ringChart = new wxCharts({
  128. animation: true,
  129. canvasId: 'ringCanvas',
  130. type: 'ring',
  131. extra: {
  132. ringWidth: 10,
  133. pie: {
  134. offsetAngle: -40
  135. }
  136. },
  137. title: {
  138. name: '归勤率',
  139. color: '#333',
  140. fontSize: 15
  141. },
  142. subtitle: {
  143. name: that.data.totalInfo.attendance * 100 + '%',
  144. color: '#6282f4',
  145. fontSize: 18
  146. },
  147. series: [{
  148. name: '无进出记录人员',
  149. data: that.data.totalInfo.unAccessCount / that.data.totalInfo.total,
  150. stroke: false,
  151. color: '#ed5c68'
  152. }, {
  153. name: '已出宿舍人员',
  154. data: that.data.totalInfo.out / that.data.totalInfo.total,
  155. stroke: false,
  156. color: '#f5a786'
  157. }, {
  158. name: '已归宿舍人员',
  159. data: that.data.totalInfo.in / that.data.totalInfo.total,
  160. stroke: false,
  161. color: '#7792f5'
  162. }, {
  163. name: '晚归宿舍人员',
  164. data: that.data.totalInfo.laterIn / that.data.totalInfo.total,
  165. stroke: false,
  166. color: '#79bef4'
  167. }, {
  168. name: '未归宿舍人员',
  169. data: that.data.totalInfo.unIn / that.data.totalInfo.total,
  170. stroke: false,
  171. color: '#5be0c1'
  172. }, {
  173. name: '未出宿舍人员',
  174. data: that.data.totalInfo.unOut / that.data.totalInfo.total,
  175. stroke: false,
  176. color: '#ac91f7'
  177. }],
  178. disablePieStroke: true,
  179. width: 160,
  180. height: 160,
  181. dataLabel: false,
  182. legend: false,
  183. background: '#fff',
  184. padding: 0
  185. });
  186. ringChart.addEventListener('renderComplete', () => {
  187. console.log('renderComplete');
  188. });
  189. setTimeout(() => {
  190. ringChart.stopAnimation();
  191. }, 500);
  192. },
  193. touchHandler: function(e) {
  194. console.log(ringChart.getCurrentDataIndex(e));
  195. },
  196. getStatisticsInfo: function(e) {
  197. const that = this;
  198. let deptId;
  199. if (that.data.listDept != '') {
  200. deptId = that.data.listDept[that.data.value[1]].deptId
  201. } else {
  202. deptId = that.data.listCollege[that.data.value[0]].deptId
  203. }
  204. util.httpRequest(api.getStatisticsInfo, {
  205. start: that.data.startDate,
  206. end: that.data.endDate,
  207. deptId: deptId
  208. }, 'post').then(res => {
  209. that.setData({
  210. totalInfo: res.data.data
  211. })
  212. that.getChart();
  213. })
  214. },
  215. getUnInInfo: function(e) {
  216. const that = this;
  217. let deptId;
  218. if (that.data.listDept != '') {
  219. deptId = that.data.listDept[that.data.value[1]].deptId
  220. } else {
  221. deptId = that.data.listCollege[that.data.value[0]].deptId
  222. }
  223. util.httpRequest(api.getUnInInfo, {
  224. start: that.data.startDate,
  225. end: that.data.endDate,
  226. page: 1,
  227. rows: 20,
  228. deptId: deptId
  229. }, 'post').then(res => {
  230. that.setData({
  231. list: res.data.data.data
  232. })
  233. })
  234. },
  235. getOutAndInInfo: function(e) {
  236. const that = this;
  237. let deptId;
  238. if (that.data.listDept != '') {
  239. deptId = that.data.listDept[that.data.value[1]].deptId
  240. } else {
  241. deptId = that.data.listCollege[that.data.value[0]].deptId
  242. }
  243. util.httpRequest(api.getOutAndInInfo, {
  244. startDate: that.data.startDate,
  245. endDate: that.data.endDate,
  246. page: 1,
  247. rows: 20,
  248. deptId: deptId,
  249. state: that.data.state
  250. }, 'post').then(res => {
  251. that.setData({
  252. list: res.data.data.data
  253. })
  254. })
  255. },
  256. getUnOut: function(e) {
  257. const that = this;
  258. let deptId;
  259. if (that.data.listDept != '') {
  260. deptId = that.data.listDept[that.data.value[1]].deptId
  261. } else {
  262. deptId = that.data.listCollege[that.data.value[0]].deptId
  263. }
  264. util.httpRequest(api.getUnOut, {
  265. start: that.data.startDate,
  266. end: that.data.endDate,
  267. page: 1,
  268. rows: 20,
  269. deptId: deptId
  270. }, 'post').then(res => {
  271. that.setData({
  272. list: res.data.data.data
  273. })
  274. })
  275. },
  276. getLateIn: 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.getLateIn, {
  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. getInUnOut: 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.getInUnOunt, {
  305. start: that.data.startDate,
  306. end: that.data.endDate,
  307. page: 1,
  308. rows: 20,
  309. deptId: deptId
  310. }, 'post').then(res => {
  311. that.setData({
  312. list: res.data.data.data
  313. })
  314. })
  315. },
  316. qiehuan: function(e) {
  317. const that = this;
  318. let type = e.currentTarget ? e.currentTarget.dataset.type : e;
  319. let state = e.currentTarget ? e.currentTarget.dataset.state : that.data.state;
  320. if (type == 1) {
  321. that.setData({
  322. listTitle: '无进出记录人员',
  323. type: 1
  324. })
  325. that.getUnOut();
  326. } else if (type == 2) {
  327. that.setData({
  328. listTitle: '已出宿舍人员',
  329. type: 2,
  330. state: state
  331. })
  332. that.getOutAndInInfo();
  333. } else if (type == 3) {
  334. that.setData({
  335. listTitle: '已归宿舍人员',
  336. type: 3,
  337. state: state
  338. })
  339. that.getOutAndInInfo();
  340. } else if (type == 4) {
  341. that.setData({
  342. listTitle: '晚归宿舍人员',
  343. type: 4
  344. })
  345. that.getLateIn();
  346. } else if (type == 5) {
  347. that.setData({
  348. listTitle: '未归宿舍人员',
  349. type: 5
  350. })
  351. that.getUnInInfo();
  352. } else if (type == 6) {
  353. that.setData({
  354. listTitle: '未出宿舍人员',
  355. type: 6
  356. })
  357. that.getInUnOut();
  358. }
  359. },
  360. /**
  361. * 生命周期函数--监听页面加载
  362. */
  363. onLoad: function(options) {
  364. const that = this;
  365. that.getCurrentDate();
  366. that.data.userInfo = wx.getStorageSync('user');
  367. that.getCollegeInfo();
  368. },
  369. /**
  370. * 生命周期函数--监听页面初次渲染完成
  371. */
  372. onReady: function() {
  373. },
  374. /**
  375. * 生命周期函数--监听页面显示
  376. */
  377. onShow: function() {
  378. },
  379. /**
  380. * 生命周期函数--监听页面隐藏
  381. */
  382. onHide: function() {
  383. },
  384. /**
  385. * 生命周期函数--监听页面卸载
  386. */
  387. onUnload: function() {
  388. },
  389. /**
  390. * 页面相关事件处理函数--监听用户下拉动作
  391. */
  392. onPullDownRefresh: function() {
  393. },
  394. /**
  395. * 页面上拉触底事件的处理函数
  396. */
  397. onReachBottom: function() {
  398. }
  399. })