store.js 2.8 KB

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