pass.js 6.5 KB

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