C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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