statistics.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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.attendance * 100,
  150. stroke: false,
  151. color: '#6282f4'
  152. }, {
  153. name: '缺勤',
  154. data: 100 - that.data.totalInfo.attendance * 100,
  155. stroke: false,
  156. color: '#ed5c68'
  157. }],
  158. disablePieStroke: true,
  159. width: 160,
  160. height: 160,
  161. dataLabel: false,
  162. legend: false,
  163. background: '#fff',
  164. padding: 0
  165. });
  166. ringChart.addEventListener('renderComplete', () => {
  167. console.log('renderComplete');
  168. });
  169. setTimeout(() => {
  170. ringChart.stopAnimation();
  171. }, 500);
  172. },
  173. touchHandler: function(e) {
  174. console.log(ringChart.getCurrentDataIndex(e));
  175. },
  176. getStatisticsInfo: function(e) {
  177. const that = this;
  178. let deptId;
  179. if (that.data.listDept != '') {
  180. deptId = that.data.listDept[that.data.value[1]].deptId
  181. } else {
  182. deptId = that.data.listCollege[that.data.value[0]].deptId
  183. }
  184. util.httpRequest(api.getStatisticsInfo, {
  185. start: that.data.startDate,
  186. end: that.data.endDate,
  187. deptId: deptId
  188. }, 'post').then(res => {
  189. that.setData({
  190. totalInfo: res.data.data
  191. })
  192. that.getChart();
  193. })
  194. },
  195. getUnInInfo: function(e) {
  196. const that = this;
  197. util.httpRequest(api.getUnInInfo, {
  198. start: that.data.startDate,
  199. end: that.data.endDate,
  200. page: 1,
  201. rows: 20
  202. }, 'post').then(res => {
  203. that.setData({
  204. list: res.data.data.data
  205. })
  206. })
  207. },
  208. getOutAndInInfo: function(e) {
  209. const that = this;
  210. let deptId;
  211. if (that.data.listDept != '') {
  212. deptId = that.data.listDept[that.data.value[1]].deptId
  213. } else {
  214. deptId = that.data.listCollege[that.data.value[0]].deptId
  215. }
  216. util.httpRequest(api.getOutAndInInfo, {
  217. startDate: that.data.startDate,
  218. endDate: that.data.endDate,
  219. page: 1,
  220. rows: 20,
  221. deptId: deptId,
  222. state: that.data.state
  223. }, 'post').then(res => {
  224. that.setData({
  225. list: res.data.data.data
  226. })
  227. })
  228. },
  229. getUnOut: function(e) {
  230. const that = this;
  231. let deptId;
  232. if (that.data.listDept != '') {
  233. deptId = that.data.listDept[that.data.value[1]].deptId
  234. } else {
  235. deptId = that.data.listCollege[that.data.value[0]].deptId
  236. }
  237. util.httpRequest(api.getUnOut, {
  238. start: that.data.startDate,
  239. end: that.data.endDate,
  240. page: 1,
  241. rows: 20,
  242. deptId: deptId
  243. }, 'post').then(res => {
  244. that.setData({
  245. list: res.data.data.data
  246. })
  247. })
  248. },
  249. getLateIn: function(e) {
  250. const that = this;
  251. let deptId;
  252. if (that.data.listDept != '') {
  253. deptId = that.data.listDept[that.data.value[1]].deptId
  254. } else {
  255. deptId = that.data.listCollege[that.data.value[0]].deptId
  256. }
  257. util.httpRequest(api.getLateIn, {
  258. start: that.data.startDate,
  259. end: that.data.endDate,
  260. page: 1,
  261. rows: 20,
  262. deptId: deptId
  263. }, 'post').then(res => {
  264. that.setData({
  265. list: res.data.data.data
  266. })
  267. })
  268. },
  269. getInUnOut: function(e) {
  270. const that = this;
  271. let deptId;
  272. if (that.data.listDept != '') {
  273. deptId = that.data.listDept[that.data.value[1]].deptId
  274. } else {
  275. deptId = that.data.listCollege[that.data.value[0]].deptId
  276. }
  277. util.httpRequest(api.getInUnOunt, {
  278. start: that.data.startDate,
  279. end: that.data.endDate,
  280. page: 1,
  281. rows: 20,
  282. deptId: deptId
  283. }, 'post').then(res => {
  284. that.setData({
  285. list: res.data.data.data
  286. })
  287. })
  288. },
  289. qiehuan: function(e) {
  290. const that = this;
  291. let type = e.currentTarget ? e.currentTarget.dataset.type : e;
  292. let state = e.currentTarget ? e.currentTarget.dataset.state : that.data.state;
  293. if (type == 1) {
  294. that.setData({
  295. listTitle: '无进出记录人员',
  296. type: 1
  297. })
  298. that.getUnOut();
  299. } else if (type == 2) {
  300. that.setData({
  301. listTitle: '已出宿舍人员',
  302. type: 2,
  303. state: state
  304. })
  305. that.getOutAndInInfo();
  306. } else if (type == 3) {
  307. that.setData({
  308. listTitle: '已归宿舍人员',
  309. type: 3,
  310. state: state
  311. })
  312. that.getOutAndInInfo();
  313. } else if (type == 4) {
  314. that.setData({
  315. listTitle: '晚归宿舍人员',
  316. type: 4
  317. })
  318. that.getLateIn();
  319. } else if (type == 5) {
  320. that.setData({
  321. listTitle: '未归宿舍人员',
  322. type: 5
  323. })
  324. that.getUnInInfo();
  325. } else if (type == 6) {
  326. that.setData({
  327. listTitle: '未出宿舍人员',
  328. type: 6
  329. })
  330. that.getInUnOut();
  331. }
  332. },
  333. /**
  334. * 生命周期函数--监听页面加载
  335. */
  336. onLoad: function(options) {
  337. const that = this;
  338. that.getCurrentDate();
  339. that.data.userInfo = wx.getStorageSync('user');
  340. that.getCollegeInfo();
  341. },
  342. /**
  343. * 生命周期函数--监听页面初次渲染完成
  344. */
  345. onReady: function() {
  346. },
  347. /**
  348. * 生命周期函数--监听页面显示
  349. */
  350. onShow: function() {
  351. },
  352. /**
  353. * 生命周期函数--监听页面隐藏
  354. */
  355. onHide: function() {
  356. },
  357. /**
  358. * 生命周期函数--监听页面卸载
  359. */
  360. onUnload: function() {
  361. },
  362. /**
  363. * 页面相关事件处理函数--监听用户下拉动作
  364. */
  365. onPullDownRefresh: function() {
  366. },
  367. /**
  368. * 页面上拉触底事件的处理函数
  369. */
  370. onReachBottom: function() {
  371. }
  372. })