C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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