store.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. util.request(api.BrandList, this.data.fetcherData).then((res) => {
  42. this.setData({
  43. loading:false
  44. })
  45. if (res.errno === 0) {
  46. if (res.data.data.length != 0) {
  47. this.setData({
  48. storeList: this.data.storeList.concat(res.data.data),
  49. 'fetcherData.page': this.data.fetcherData.page + 1
  50. })
  51. } else {
  52. this.setData({
  53. hasData: false
  54. })
  55. }
  56. }
  57. }).catch(err=>{
  58. this.setData({
  59. loading:false
  60. })
  61. });
  62. }
  63. } else {
  64. console.log('没有更多数据')
  65. }
  66. },
  67. /**
  68. * 生命周期函数--监听页面加载
  69. */
  70. onLoad: function (options) {
  71. getApp().checkNetStatu();
  72. this.getStoreList()
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面隐藏
  86. */
  87. onHide: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面卸载
  91. */
  92. onUnload: function () {
  93. },
  94. /**
  95. * 页面相关事件处理函数--监听用户下拉动作
  96. */
  97. onPullDownRefresh() {
  98. this.setData({
  99. storeList: [],
  100. 'fetcherData.page': 1,
  101. hasData: true
  102. });
  103. this.getStoreList()
  104. app.onPullDownRefresh()
  105. },
  106. onReachBottom: function () {
  107. this.getStoreList()
  108. console.log('onReachBottom')
  109. },
  110. /**
  111. * 用户点击右上角分享
  112. */
  113. onShareAppMessage: function () {
  114. }
  115. })