C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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