pass.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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: 0,
  21. deviceArray: [],
  22. deviceList: '',
  23. startDate: '',
  24. endDate: '',
  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. this.getPassInfo();
  141. },
  142. bindendDateChange: function(e) {
  143. this.setData({
  144. endDate: e.detail.value
  145. })
  146. this.getPassInfo();
  147. },
  148. getDeviceInfo: function(e) {
  149. const that = this;
  150. let loginId = wx.getStorageSync('loginId');
  151. util.httpRequest(api.getDeviceInfo, {
  152. loginId: loginId
  153. }, 'post').then(res => {
  154. let deviceArray = [];
  155. for (let i = 0; i < res.data.length; i++) {
  156. deviceArray.push(res.data[i].name)
  157. if (i == res.data.length - 1) {
  158. that.setData({
  159. deviceArray: deviceArray,
  160. deviceList: res.data
  161. })
  162. }
  163. }
  164. })
  165. },
  166. getPassInfo: function(e) {
  167. const that = this;
  168. util.httpRequest(api.getPassInfo, {
  169. loginId: that.data.listUser[that.data.value[2]].loginid,
  170. start: that.data.startDate,
  171. end: that.data.endDate,
  172. driviceId: that.data.deviceList[that.data.deviceIndex].id,
  173. rows: 20,
  174. page: 1
  175. }, 'post').then(res => {
  176. for (let i = 0; i < res.data.data.length; i++) {
  177. res.data.data[i].openTime = that.getLocalTime(res.data.data[i].openTime)
  178. }
  179. that.setData({
  180. list: res.data.data
  181. })
  182. })
  183. },
  184. getLocalTime: function(nS) {
  185. let date = new Date(nS);
  186. let year = date.getFullYear();
  187. let month = date.getMonth() + 1;
  188. let day = date.getDate();
  189. let hour = date.getHours();
  190. let minute = date.getMinutes();
  191. let second = date.getSeconds();
  192. month = month < 10 ? "0" + month : month;
  193. day = day < 10 ? "0" + day : day;
  194. hour = hour < 10 ? "0" + hour : hour;
  195. minute = minute < 10 ? "0" + minute : minute;
  196. second = second < 10 ? "0" + second : second;
  197. date = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  198. return date;
  199. },
  200. getCurrentDate: function(e) {
  201. let date = new Date();
  202. let year = date.getFullYear();
  203. let month = date.getMonth() + 1;
  204. let day = date.getDate();
  205. month = month < 10 ? "0" + month : month;
  206. day = day < 10 ? "0" + day : day;
  207. date = year + '-' + month + '-' + day
  208. this.setData({
  209. startDate: date,
  210. endDate: date
  211. })
  212. },
  213. /**
  214. * 生命周期函数--监听页面加载
  215. */
  216. onLoad: function(options) {
  217. const that = this;
  218. that.setData({
  219. apiTotal: api.total.substring(0, api.total.length - 4)
  220. })
  221. that.getCurrentDate();
  222. that.data.userInfo = wx.getStorageSync('user');
  223. that.getCollegeInfo();
  224. that.getDeviceInfo();
  225. },
  226. /**
  227. * 生命周期函数--监听页面初次渲染完成
  228. */
  229. onReady: function() {
  230. },
  231. /**
  232. * 生命周期函数--监听页面显示
  233. */
  234. onShow: function() {
  235. },
  236. /**
  237. * 生命周期函数--监听页面隐藏
  238. */
  239. onHide: function() {
  240. },
  241. /**
  242. * 生命周期函数--监听页面卸载
  243. */
  244. onUnload: function() {
  245. },
  246. /**
  247. * 页面相关事件处理函数--监听用户下拉动作
  248. */
  249. onPullDownRefresh: function() {
  250. },
  251. /**
  252. * 页面上拉触底事件的处理函数
  253. */
  254. onReachBottom: function() {
  255. }
  256. })