pass.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. const util = require('../../../utils/util.js');
  2. const api = require('../../../utils/api.js');
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userInfo: '',
  10. apiTotal: '',
  11. listCollege: '',
  12. listDept: '',
  13. listUser: '',
  14. userArray: [
  15. [],
  16. [],
  17. []
  18. ],
  19. value: [0, 0, 0],
  20. deviceIndex: 2,
  21. deviceArray: [],
  22. deviceList: '',
  23. startDate: '2019-10-29',
  24. endDate: '2019-10-29',
  25. list: []
  26. },
  27. getCollegeInfo: function(e) {
  28. const that = this;
  29. util.httpRequest(api.getDeptInfo, {
  30. companyId: that.data.userInfo.companyId,
  31. level: 1
  32. }, 'post').then(res => {
  33. let arrayCollege = [];
  34. if (res.data.length >= 1) {
  35. for (let i = 0; i < res.data.length; i++) {
  36. arrayCollege.push(res.data[i].deptName)
  37. if (i == res.data.length - 1) {
  38. let userArray = that.data.userArray;
  39. userArray[0] = arrayCollege;
  40. that.setData({
  41. userArray: userArray,
  42. listCollege: res.data
  43. })
  44. that.getDeptInfo();
  45. }
  46. }
  47. }
  48. })
  49. },
  50. getDeptInfo: function(e) {
  51. const that = this;
  52. util.httpRequest(api.getDeptInfo, {
  53. companyId: that.data.userInfo.companyId,
  54. parentId: that.data.listCollege[that.data.value[0]].deptId
  55. }, 'post').then(res => {
  56. let arrayDept = [];
  57. if (res.data.length >= 1) {
  58. for (let i = 0; i < res.data.length; i++) {
  59. arrayDept.push(res.data[i].deptName)
  60. if (i == res.data.length - 1) {
  61. let userArray = that.data.userArray
  62. userArray[1] = arrayDept
  63. that.setData({
  64. userArray: userArray,
  65. listDept: res.data
  66. })
  67. that.getRegisterInfo()
  68. }
  69. }
  70. } else {
  71. let userArray = that.data.userArray;
  72. userArray[1] = arrayDept
  73. userArray[2] = []
  74. that.setData({
  75. userArray: userArray,
  76. listDept: '',
  77. list: ''
  78. })
  79. }
  80. })
  81. },
  82. getRegisterInfo: function(status = 0) {
  83. const that = this;
  84. util.httpRequest(api.getRegisterInfo, {
  85. deptId: that.data.listDept[that.data.value[1]].deptId,
  86. register: status
  87. }, 'post').then(res => {
  88. let arrayUser = [];
  89. if (res.data.data.data.length >= 1) {
  90. for (let i = 0; i < res.data.data.data.length; i++) {
  91. arrayUser.push(res.data.data.data[i].userName)
  92. if (i == res.data.data.data.length - 1) {
  93. let userArray = that.data.userArray
  94. userArray[2] = arrayUser
  95. that.setData({
  96. userArray: userArray,
  97. listUser: res.data.data.data
  98. })
  99. that.getPassInfo();
  100. }
  101. }
  102. } else {
  103. let userArray = that.data.userArray
  104. userArray[2] = arrayUser
  105. that.setData({
  106. userArray: userArray,
  107. listUser: '',
  108. list: ''
  109. })
  110. }
  111. })
  112. },
  113. bindUserChange: function(e) {
  114. },
  115. columnChange: function(e) {
  116. const that = this;
  117. let value = that.data.value
  118. value[e.detail.column] = e.detail.value
  119. that.setData({
  120. value: value
  121. })
  122. if (e.detail.column == 0) {
  123. that.getDeptInfo()
  124. } else if (e.detail.column == 1) {
  125. that.getRegisterInfo()
  126. } else if (e.detail.column == 2) {
  127. that.getPassInfo();
  128. }
  129. },
  130. bindDeviceChange: function(e) {
  131. this.setData({
  132. deviceIndex: e.detail.value
  133. })
  134. this.getPassInfo();
  135. },
  136. bindStartDateChange: function(e) {
  137. this.setData({
  138. startDate: e.detail.value
  139. })
  140. },
  141. bindendDateChange: function(e) {
  142. this.setData({
  143. endDate: e.detail.value
  144. })
  145. },
  146. getDeviceInfo: function(e) {
  147. const that = this;
  148. util.httpRequest(api.getDeviceInfo, {
  149. }, 'post').then(res => {
  150. let deviceArray = [];
  151. for (let i = 0; i < res.data.length; i++) {
  152. deviceArray.push(res.data[i].name)
  153. if (i == res.data.length - 1) {
  154. that.setData({
  155. deviceArray: deviceArray,
  156. deviceList: res.data
  157. })
  158. }
  159. }
  160. })
  161. },
  162. getPassInfo: function(e) {
  163. const that = this;
  164. util.httpRequest(api.getPassInfo, {
  165. loginId: that.data.listUser[that.data.value[2]].loginid,
  166. start: that.data.startDate,
  167. end: that.data.endDate,
  168. driviceId: that.data.deviceList[that.data.deviceIndex].id,
  169. rows: 20,
  170. page: 1
  171. }, 'post').then(res => {
  172. for (let i = 0; i < res.data.data.length; i++) {
  173. res.data.data[i].openTime = that.getLocalTime(res.data.data[i].openTime)
  174. }
  175. that.setData({
  176. list: res.data.data
  177. })
  178. })
  179. },
  180. getLocalTime: function(nS) {
  181. let date = new Date(nS);
  182. let year = date.getFullYear();
  183. let month = date.getMonth() + 1;
  184. let day = date.getDate();
  185. let hour = date.getHours();
  186. let minute = date.getMinutes();
  187. let second = date.getSeconds();
  188. month = month < 10 ? "0" + month : month;
  189. day = day < 10 ? "0" + day : day;
  190. hour = hour < 10 ? "0" + hour : hour;
  191. minute = minute < 10 ? "0" + minute : minute;
  192. second = second < 10 ? "0" + second : second;
  193. date = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  194. return date;
  195. },
  196. /**
  197. * 生命周期函数--监听页面加载
  198. */
  199. onLoad: function(options) {
  200. const that = this;
  201. that.setData({
  202. apiTotal: api.total.substring(0, api.total.length - 4)
  203. })
  204. that.data.userInfo = wx.getStorageSync('user');
  205. that.getCollegeInfo();
  206. that.getDeviceInfo();
  207. },
  208. /**
  209. * 生命周期函数--监听页面初次渲染完成
  210. */
  211. onReady: function() {
  212. },
  213. /**
  214. * 生命周期函数--监听页面显示
  215. */
  216. onShow: function() {
  217. },
  218. /**
  219. * 生命周期函数--监听页面隐藏
  220. */
  221. onHide: function() {
  222. },
  223. /**
  224. * 生命周期函数--监听页面卸载
  225. */
  226. onUnload: function() {
  227. },
  228. /**
  229. * 页面相关事件处理函数--监听用户下拉动作
  230. */
  231. onPullDownRefresh: function() {
  232. },
  233. /**
  234. * 页面上拉触底事件的处理函数
  235. */
  236. onReachBottom: function() {
  237. }
  238. })