list.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. const util = require('../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. searchParams: {
  9. pageNo: 1,
  10. pageSize: 20,
  11. storeId: ''
  12. },
  13. deviceList: [],
  14. loadding: false,
  15. pullUpOn: true,
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. this.setData({
  22. ["searchParams.storeId"]: options.storeId
  23. })
  24. this.bindDeviceList()
  25. },
  26. /**
  27. * 生命周期函数--监听页面初次渲染完成
  28. */
  29. onReady: function () {
  30. },
  31. /**
  32. * 生命周期函数--监听页面显示
  33. */
  34. onShow: function () {
  35. },
  36. /**
  37. * 生命周期函数--监听页面隐藏
  38. */
  39. onHide: function () {
  40. },
  41. /**
  42. * 生命周期函数--监听页面卸载
  43. */
  44. onUnload: function () {
  45. },
  46. /**
  47. * 页面相关事件处理函数--监听用户下拉动作
  48. */
  49. onPullDownRefresh: function () {
  50. this.setData({
  51. ["searchParams.pageNo"]: 1,
  52. pullUpOn: true,
  53. loadding: false,
  54. deviceList: []
  55. })
  56. this.bindDeviceList()
  57. setTimeout(() => {
  58. wx.stopPullDownRefresh()
  59. }, 300);
  60. },
  61. /**
  62. * 页面上拉触底事件的处理函数
  63. */
  64. onReachBottom: function () {
  65. //只是测试效果,逻辑以实际数据为准
  66. this.setData({
  67. loadding: true,
  68. pullUpOn: true
  69. })
  70. this.setData({
  71. ["searchParams.pageNo"]: this.data.searchParams.pageNo + 1
  72. })
  73. this.bindDeviceList()
  74. },
  75. /**
  76. * 用户点击右上角分享
  77. */
  78. onShareAppMessage: function () {
  79. },
  80. toDetail(e) {
  81. wx.navigateTo({
  82. url: '/pages/device/detail?deviceId=' + e.currentTarget.dataset.id,
  83. })
  84. },
  85. bindDeviceList() {
  86. var that = this
  87. util.request(util.api.deviceListPage, that.data.searchParams, "GET", true, false, app.globalData.token).then((res) => {
  88. if (res.code == 200) {
  89. if (res.result.records.length > 0) {
  90. if (that.data.deviceList.length > 0) {
  91. let list = that.data.deviceList
  92. res.result.records.forEach((e)=>{
  93. list.push(e)
  94. })
  95. that.setData({
  96. deviceList: list
  97. })
  98. } else {
  99. that.setData({
  100. deviceList: res.result.records
  101. })
  102. }
  103. } else {
  104. that.setData({
  105. loadding: false,
  106. pullUpOn: false
  107. })
  108. }
  109. }
  110. }).catch((res) => {})
  111. }
  112. })