C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

172 linhas
3.7 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. // 跳往商户详情
  127. godetail: function (e) {
  128. console.log(e)
  129. wx.navigateTo({
  130. url: `/pages/order/detail/index?orderId=${e.currentTarget.dataset.id}`
  131. })
  132. },
  133. phone: function (e) {
  134. let that = this;
  135. if (e.currentTarget.dataset.merchantlinkphone) {
  136. wx.makePhoneCall({
  137. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  138. })
  139. }
  140. },
  141. /**
  142. * 页面上拉触底事件的处理函数
  143. */
  144. onReachBottom: function () {
  145. let that = this;
  146. that.data.page++;
  147. that.setData({
  148. page: that.data.page
  149. });
  150. console.log(that.data.page);
  151. // 如果是最后一页
  152. //就不发送请求
  153. if (!that.data.isLastPage || that.data.isFirstPage && that.data.isLastPage){
  154. that.getList(that.data.page, that.data.businessId);
  155. }
  156. }
  157. })
  158. function compare(pro) {
  159. return function (obj2, obj1) {
  160. var val1 = obj1[pro];
  161. var val2 = obj2[pro];
  162. if (val1 < val2) {
  163. return 1;
  164. } else if (val1 > val2) {
  165. return -1;
  166. } else {
  167. return 0;
  168. }
  169. }
  170. }