index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. storeName:'',
  12. },
  13. storeList: [],
  14. loadding: false,
  15. pullUpOn: true,
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. this.bindStoreList()
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady: function () {
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面隐藏
  35. */
  36. onHide: function () {
  37. },
  38. onUnload: function () {
  39. wx.reLaunch({
  40. url: '../index/index',
  41. })
  42. },
  43. /**
  44. * 页面相关事件处理函数--监听用户下拉动作
  45. */
  46. onPullDownRefresh: function () {
  47. this.setData({
  48. ["searchParams.pageNo"]: 1,
  49. pullUpOn: true,
  50. loadding: false,
  51. storeList: []
  52. })
  53. this.bindStoreList()
  54. setTimeout(() => {
  55. wx.stopPullDownRefresh()
  56. }, 300);
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. onReachBottom: function () {
  62. var that = this
  63. //只是测试效果,逻辑以实际数据为准
  64. this.setData({
  65. loadding: true,
  66. pullUpOn: true
  67. })
  68. this.setData({
  69. ["searchParams.pageNo"]: that.data.searchParams.pageNo + 1
  70. })
  71. this.bindStoreList()
  72. },
  73. /**
  74. * 用户点击右上角分享
  75. */
  76. onShareAppMessage: function () {
  77. },
  78. toDevice(e) {
  79. wx.navigateTo({
  80. url: '/pages/device/list?storeId=' + e.currentTarget.dataset.id,
  81. })
  82. },
  83. searchStore(){
  84. this.setData({
  85. ["searchParams.pageNo"]: 1,
  86. pullUpOn: true,
  87. loadding: false,
  88. storeList: []
  89. })
  90. this.bindStoreList()
  91. },
  92. bindStoreList() {
  93. var that = this
  94. util.request(util.api.storeListPage, that.data.searchParams, "GET", true, false, app.globalData.token).then((res) => {
  95. if (res.code == 200) {
  96. if (res.result.records.length > 0) {
  97. if (that.data.storeList.length > 0) {
  98. let list = that.data.storeList
  99. res.result.records.forEach((e)=>{
  100. list.push(e)
  101. })
  102. that.setData({
  103. storeList: list
  104. })
  105. }else{
  106. that.setData({
  107. storeList: res.result.records
  108. })
  109. }
  110. } else {
  111. that.setData({
  112. loadding: false,
  113. pullUpOn: false,
  114. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  115. })
  116. }
  117. }
  118. }).catch((res) => {})
  119. },
  120. inputedit: function (e) {
  121. let _this = this;
  122. let dataset = e.currentTarget.dataset;
  123. let value = e.detail.value;
  124. let name = dataset.name;
  125. _this.data[name] = value;
  126. _this.setData({
  127. [name]: _this.data[name]
  128. });
  129. },
  130. })