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.

157 lines
3.4 KiB

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