C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
3.6 KiB

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