activityList.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. const { default: activity } = require("../../api/activity");
  2. import {getMobileCache, getPhoneNumberNew as getPhoneNumberSync} from '../../utils/user'
  3. // pages/activityList/activityList.js
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userMobile:'',
  10. //火热
  11. list: [], //卡券列表
  12. page:1,
  13. pageNum:10,
  14. count:0,
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function () {
  20. let _self = this;
  21. //获取列表
  22. _self.getList();
  23. },
  24. /**
  25. * 生命周期函数--监听页面初次渲染完成
  26. */
  27. onReady: function () {
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow: function () {
  33. },
  34. /**
  35. * 生命周期函数--监听页面隐藏
  36. */
  37. onHide: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面卸载
  41. */
  42. onUnload: function () {
  43. },
  44. /**
  45. * 页面相关事件处理函数--监听用户下拉动作
  46. */
  47. onPullDownRefresh: function () {
  48. },
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom: function () {
  53. var totalPage = Math.ceil(this.data.count/this.data.pageNum)
  54. console.log('到底了')
  55. var page = this.data.page
  56. page++;
  57. this.setData({
  58. page:page
  59. })
  60. if(page<=totalPage){
  61. console.log(123)
  62. this.getList();
  63. }
  64. },
  65. /**
  66. * 用户点击右上角分享
  67. */
  68. onShareAppMessage: function () {
  69. },
  70. goToShare(e){
  71. console.log(e)
  72. let _self = this;
  73. wx.navigateTo({
  74. url: '/pages/activityInfo/activityInfo?id='+e.currentTarget.dataset.id+'&mobile='+_self.data.userMobile,
  75. })
  76. },
  77. //获取手机号
  78. getPhoneNumber(e) {
  79. let _self = this;
  80. getPhoneNumberSync(e, async () => {
  81. let userMobile = activity.getMobileCache();
  82. console.log(userMobile)
  83. if (userMobile.length !== 0) {
  84. _self.setData({
  85. userMobile: userMobile,
  86. })
  87. //判断该手机号在不在分享名单里
  88. _self.isShareByMobile();
  89. }
  90. })
  91. // let _self = this;
  92. // var encryptedData = e.detail.encryptedData;
  93. // console.log(encryptedData);
  94. // var iv = e.detail.iv;
  95. // if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
  96. // return;
  97. // }
  98. //获取手机号
  99. // getApp().doDecodePhone(encryptedData, iv, function () {
  100. // let userMobile = activity.getMobileCache();
  101. // console.log(userMobile)
  102. // if (userMobile.length !== 0) {
  103. // _self.setData({
  104. // userMobile: userMobile,
  105. // })
  106. // //判断该手机号在不在分享名单里
  107. // _self.isShareByMobile();
  108. // }
  109. //
  110. // });
  111. },
  112. //获取活动列表
  113. getList: async function() {
  114. let _self = this;
  115. var result = await activity.getActivityList(this.data.page,this.data.pageNum,2);
  116. var list = this.handleCouponList(result.list);
  117. if(this.data.page != 1){
  118. var nowResult = this.data.list.concat(list)
  119. }else{
  120. var nowResult = list
  121. }
  122. //判断该电话是否存在 如果不存在 取第一条
  123. if(_self.data.userMobile=='') {
  124. nowResult = nowResult.length>0?[nowResult[0]]:nowResult;
  125. }
  126. this.setData({
  127. list:nowResult,
  128. count:result.count,
  129. page:result.page
  130. })
  131. },
  132. async isShareByMobile(){
  133. let _self = this;
  134. var result = await activity.isShareByMobile(_self.data.userMobile);
  135. if(result.isShare==1){
  136. _self.setData({
  137. page:1
  138. })
  139. _self.getList();
  140. }
  141. },
  142. handleCouponList(list) {
  143. if (list.length === 0) {
  144. return list;
  145. }
  146. var objSwitch = getApp().globalData.typeSwitchObj
  147. for (let i = 0; i < list.length; i++) {
  148. var couponList = list[i].activityCouponList;
  149. var couponTypeAndNumObj = {};
  150. for (let j = 0; j < couponList.length; j++) {
  151. var couponNum = couponList[j]['num'] ? couponList[j]['num'] : 1;
  152. var value = couponList[j]['coupon']['type'];
  153. var showText = objSwitch[couponList[j]['coupon']['type']];
  154. var nowNume = 0;
  155. if (couponTypeAndNumObj[value]) {
  156. nowNume = couponTypeAndNumObj[value]['num'];
  157. console.log(nowNume)
  158. }
  159. couponTypeAndNumObj[value] = {
  160. "typeText": showText,
  161. "num": couponNum + nowNume
  162. }
  163. }
  164. list[i].couponTypeAndNum = couponTypeAndNumObj
  165. }
  166. console.log(list);
  167. return list;
  168. },
  169. })