store.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/store/store.js
  2. const util = require('../../utils/util.js');
  3. const api = require('../../config/api.js');
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. type: 21,
  11. storeList: [],
  12. hasData: true,
  13. loading:false,
  14. fetcherData: {
  15. type: 21,
  16. address: '',
  17. page: 1,
  18. size: 20,
  19. name: ''
  20. }
  21. },
  22. gotoWV: function (event) {
  23. let id = event.detail
  24. wx.navigateTo({
  25. url: `/pages/webview/index?id=${id}`,
  26. })
  27. },
  28. toSearch(e) {
  29. var type = e.currentTarget.dataset.type
  30. console.log(type)
  31. wx.navigateTo({
  32. url: `/pages/searchRoom/searchRoom?type=` + type
  33. })
  34. },
  35. getStoreList() {
  36. if (this.data.hasData) {
  37. if(!this.data.loading){
  38. this.setData({
  39. loading:true
  40. })
  41. wx.showLoading({
  42. title: '加载中...',
  43. })
  44. util.request(api.BrandList, this.data.fetcherData).then((res) => {
  45. this.setData({
  46. loading:false
  47. })
  48. if (res.errno === 0) {
  49. if (res.data.data.length != 0) {
  50. this.setData({
  51. storeList: this.data.storeList.concat(res.data.data),
  52. 'fetcherData.page': this.data.fetcherData.page + 1
  53. })
  54. } else {
  55. this.setData({
  56. hasData: false
  57. })
  58. }
  59. }
  60. }).catch(err=>{
  61. this.setData({
  62. loading:false
  63. })
  64. });
  65. }
  66. } else {
  67. console.log('没有更多数据')
  68. }
  69. },
  70. /**
  71. * 生命周期函数--监听页面加载
  72. */
  73. onLoad: function (options) {
  74. getApp().checkNetStatu();
  75. this.getStoreList()
  76. },
  77. /**
  78. * 生命周期函数--监听页面初次渲染完成
  79. */
  80. onReady: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面显示
  84. */
  85. onShow: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面隐藏
  89. */
  90. onHide: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面卸载
  94. */
  95. onUnload: function () {
  96. },
  97. /**
  98. * 页面相关事件处理函数--监听用户下拉动作
  99. */
  100. onPullDownRefresh() {
  101. this.setData({
  102. storeList: [],
  103. 'fetcherData.page': 1,
  104. hasData: true
  105. });
  106. this.getStoreList()
  107. app.onPullDownRefresh()
  108. },
  109. onReachBottom: function () {
  110. this.getStoreList()
  111. console.log('onReachBottom')
  112. },
  113. /**
  114. * 用户点击右上角分享
  115. */
  116. onShareAppMessage: function () {
  117. }
  118. })