pass.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. month = month < 10 ? "0" + month : month;
  80. day = day < 10 ? "0" + day : day;
  81. date = year + '-' + month + '-' + day;
  82. console.log(date);
  83. return date;
  84. },
  85. /**
  86. * 生命周期函数--监听页面加载
  87. */
  88. onLoad: function(options) {
  89. const that = this;
  90. that.getDeviceInfo();
  91. },
  92. /**
  93. * 生命周期函数--监听页面初次渲染完成
  94. */
  95. onReady: function() {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function() {
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function() {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function() {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function() {
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function() {
  121. }
  122. })