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.

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