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.

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