C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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