pass.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. userIndex: 0,
  10. userArray: ['软件学院计算机系刘天仙', '文学院哲学系陈方明'],
  11. deviceIndex: 2,
  12. deviceArray: [],
  13. deviceList: '',
  14. startDate: '2019-10-29',
  15. endDate: '2019-10-29',
  16. list: []
  17. },
  18. bindUserChange: function(e) {
  19. this.setData({
  20. userIndex: e.detail.value
  21. })
  22. },
  23. bindDeviceChange: function(e) {
  24. this.setData({
  25. deviceIndex: e.detail.value
  26. })
  27. this.getPassInfo();
  28. },
  29. bindStartDateChange: function(e) {
  30. this.setData({
  31. startDate: e.detail.value
  32. })
  33. },
  34. bindendDateChange: function(e) {
  35. this.setData({
  36. endDate: e.detail.value
  37. })
  38. },
  39. getDeviceInfo: function(e) {
  40. const that = this;
  41. util.httpRequest(api.getDeviceInfo, {
  42. }, 'post').then(res => {
  43. let deviceArray = [];
  44. for (let i = 0; i < res.data.length; i++) {
  45. deviceArray.push(res.data[i].name)
  46. if (i == res.data.length - 1) {
  47. that.setData({
  48. deviceArray: deviceArray,
  49. deviceList: res.data
  50. })
  51. that.getPassInfo();
  52. }
  53. }
  54. })
  55. },
  56. getPassInfo: function(e) {
  57. const that = this;
  58. util.httpRequest(api.getPassInfo, {
  59. loginId: 15286831873,
  60. start: that.data.startDate,
  61. end: that.data.endDate,
  62. driviceId: that.data.deviceList[that.data.deviceIndex].id,
  63. rows: 20,
  64. page: 1
  65. }, 'post').then(res => {
  66. for (let i = 0; i < res.data.data.length; i++) {
  67. res.data.data[i].openTime = that.getLocalTime(res.data.data[i].openTime)
  68. }
  69. that.setData({
  70. list: res.data.data
  71. })
  72. })
  73. },
  74. getLocalTime: function(nS) {
  75. let date = new Date(nS);
  76. let year = date.getFullYear();
  77. let month = date.getMonth() + 1;
  78. let day = date.getDate();
  79. let hour = date.getHours();
  80. let minute = date.getMinutes();
  81. let second = date.getSeconds();
  82. month = month < 10 ? "0" + month : month;
  83. day = day < 10 ? "0" + day : day;
  84. hour = hour < 10 ? "0" + hour : hour;
  85. minute = minute < 10 ? "0" + minute : minute;
  86. second = second < 10 ? "0" + second : second;
  87. date = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  88. console.log(date);
  89. return date;
  90. },
  91. /**
  92. * 生命周期函数--监听页面加载
  93. */
  94. onLoad: function(options) {
  95. const that = this;
  96. that.getDeviceInfo();
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady: function() {
  102. },
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow: function() {
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide: function() {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload: function() {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh: function() {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function() {
  127. }
  128. })