C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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