C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

150 řádky
3.2 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. },
  49. onShow(){
  50. let that = this;
  51. wx.getSystemInfo({
  52. success: function (res) {
  53. console.log(res.windowHeight);
  54. that.setData({
  55. windowHeight: res.windowHeight
  56. })
  57. },
  58. })
  59. },
  60. getBussiness:function(){
  61. let that = this;
  62. Http.get({
  63. url: config.api.businessList,
  64. data:{
  65. filter:1
  66. }
  67. }).then(res => {
  68. that.setData({
  69. lists: [{ id: 0, title: "全部", type: 1 }].concat(res.data)
  70. });
  71. })
  72. .catch(err => {
  73. wx.showToast({
  74. title: err.errMsg,
  75. icon: 'none',
  76. duration: 2000,
  77. mask: false
  78. });
  79. })
  80. },
  81. getList: function (page, businessId) {
  82. let that = this;
  83. let data;
  84. if(businessId == 0){
  85. data = {
  86. pageNum: page,
  87. pageSize: 8
  88. }
  89. }else{
  90. data = {
  91. pageNum: page,
  92. pageSize: 8,
  93. businessId: businessId
  94. }
  95. }
  96. Http.get({
  97. url: config.api.merchantList,
  98. data: data
  99. }).then(res => {
  100. if (page == 1) {
  101. that.setData({
  102. merchantVoList: [],
  103. })
  104. }
  105. var tmpArr = that.data.merchantVoList;
  106. tmpArr.push.apply(tmpArr, res.data.list);
  107. console.log(tmpArr)
  108. that.setData({
  109. merchantVoList: tmpArr,
  110. isFirstPage: res.data.isFirstPage,
  111. isLastPage: res.data.isLastPage
  112. })
  113. console.log(that.data.merchantVoList)
  114. })
  115. .catch(err => {
  116. wx.showToast({
  117. title: err.errMsg,
  118. icon: 'none',
  119. duration: 2000,
  120. mask: false
  121. });
  122. })
  123. },
  124. phone: function (e) {
  125. let that = this;
  126. if (e.currentTarget.dataset.merchantlinkphone) {
  127. wx.makePhoneCall({
  128. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  129. })
  130. }
  131. },
  132. /**
  133. * 页面上拉触底事件的处理函数
  134. */
  135. onReachBottom: function () {
  136. let that = this;
  137. that.data.page++;
  138. that.setData({
  139. page: that.data.page
  140. });
  141. console.log(that.data.page);
  142. // 如果是最后一页
  143. //就不发送请求
  144. if (!that.data.isLastPage || that.data.isFirstPage && that.data.isLastPage){
  145. that.getList(that.data.page, that.data.businessId);
  146. }
  147. }
  148. })