store.js 2.7 KB

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