C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

155 строки
3.3 KiB

  1. const Http = require("../../../utils/HttpBasics");
  2. const imgurl = require("../../../utils/imgurl");
  3. const config = require("../../../config/config");
  4. let app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. lists: [],
  11. merchantVoList:[],
  12. indexId: 0,
  13. businessId:0,
  14. windowHeight:"",
  15. page:1,
  16. isFirstPage:false,
  17. isLastPage:false,
  18. teljpgUrl: imgurl.teljpg.url,
  19. },
  20. // 左侧点击事件
  21. jumpIndex(e) {
  22. let that = this;
  23. let index = e.currentTarget.dataset.menuindex;
  24. that.setData({
  25. indexId: index,
  26. businessId: index
  27. });
  28. that.setData({
  29. page:1
  30. })
  31. that.getList(1, that.data.businessId);
  32. },
  33. /**
  34. * 跳转到门店列表的详情页面
  35. */
  36. gotoDetail(e){
  37. wx.navigateTo({
  38. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  39. })
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. let that = this;
  46. that.getBussiness();
  47. that.getList(1, 0);
  48. wx.showLoading({
  49. title: '加载中...',
  50. })
  51. },
  52. onShow(){
  53. let that = this;
  54. wx.getSystemInfo({
  55. success: function (res) {
  56. console.log(res.windowHeight);
  57. that.setData({
  58. windowHeight: res.windowHeight
  59. })
  60. },
  61. })
  62. },
  63. getBussiness:function(){
  64. let that = this;
  65. Http.get({
  66. url: config.api.businessList,
  67. data:{
  68. filter:1
  69. }
  70. }).then(res => {
  71. that.setData({
  72. lists: [{ id: 0, title: "全部", type: 1 }].concat(res.data)
  73. });
  74. })
  75. .catch(err => {
  76. wx.showToast({
  77. title: err.errMsg,
  78. icon: 'none',
  79. duration: 2000,
  80. mask: false
  81. });
  82. })
  83. },
  84. getList: function (page, businessId) {
  85. let that = this;
  86. let data;
  87. if(businessId == 0){
  88. data = {
  89. pageNum: page,
  90. pageSize: 8
  91. }
  92. }else{
  93. data = {
  94. pageNum: page,
  95. pageSize: 8,
  96. businessId: businessId
  97. }
  98. }
  99. Http.get({
  100. url: config.api.merchantList,
  101. data: data
  102. }).then(res => {
  103. wx.hideLoading();
  104. if (page == 1) {
  105. that.setData({
  106. merchantVoList: [],
  107. })
  108. }
  109. var tmpArr = that.data.merchantVoList;
  110. tmpArr.push.apply(tmpArr, res.data.list);
  111. console.log(tmpArr)
  112. that.setData({
  113. merchantVoList: tmpArr,
  114. isFirstPage: res.data.isFirstPage,
  115. isLastPage: res.data.isLastPage
  116. })
  117. console.log(that.data.merchantVoList)
  118. })
  119. .catch(err => {
  120. wx.hideLoading();
  121. wx.showToast({
  122. title: err.errMsg,
  123. icon: 'none',
  124. duration: 2000,
  125. mask: false
  126. });
  127. })
  128. },
  129. phone: function (e) {
  130. let that = this;
  131. if (e.currentTarget.dataset.merchantlinkphone) {
  132. wx.makePhoneCall({
  133. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  134. })
  135. }
  136. },
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom: function () {
  141. let that = this;
  142. that.data.page++;
  143. that.setData({
  144. page: that.data.page
  145. });
  146. console.log(that.data.page);
  147. // 如果是最后一页
  148. //就不发送请求
  149. if (!that.data.isLastPage || that.data.isFirstPage && that.data.isLastPage){
  150. that.getList(that.data.page, that.data.businessId);
  151. }
  152. }
  153. })