C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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