C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 rivejä
3.5 KiB

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