activityInfo.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // pages/welfareMall/activityInfo/activityInfo.js
  2. import WelfareMall from '../../../api/welfareMall';
  3. import Activity from '../../../api/activity';
  4. const util = require('../../../utils/util.js');
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. detail:[],
  12. activityId:'',
  13. statusShowText:'',
  14. buttonText:'',
  15. userMobile: '', //用户手机号
  16. orderInfo: [], //下单信息
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. console.log(options);
  23. if(options.activityId){
  24. this.getActivityDetail(options.activityId)
  25. }
  26. },
  27. /**
  28. * 生命周期函数--监听页面初次渲染完成
  29. */
  30. onReady: function () {
  31. },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面隐藏
  39. */
  40. onHide: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面卸载
  44. */
  45. onUnload: function () {
  46. },
  47. /**
  48. * 页面相关事件处理函数--监听用户下拉动作
  49. */
  50. onPullDownRefresh: function () {
  51. },
  52. /**
  53. * 页面上拉触底事件的处理函数
  54. */
  55. onReachBottom: function () {
  56. },
  57. /**
  58. * 用户点击右上角分享
  59. */
  60. onShareAppMessage: function () {
  61. },
  62. getActivityDetail: async function(activityId) {
  63. let res = await WelfareMall.getActivityDetail(activityId)
  64. let statusShowText = '';
  65. if(res.data.stock <=0){
  66. statusShowText == '已售罄'
  67. }
  68. if(res.data.status ==3){
  69. statusShowText == '已结束'
  70. }
  71. let buttonText = res.data.isPay == 1 ? '立即抢购' : '立即领取';
  72. this.setData({
  73. detail:res.data,
  74. statusShowText:statusShowText,
  75. buttonText:buttonText
  76. })
  77. },
  78. /**
  79. * 获取手机号
  80. * @param {*} e
  81. */
  82. getPhoneNumber(e) {
  83. let _self = this;
  84. var encryptedData = e.detail.encryptedData;
  85. var iv = e.detail.iv;
  86. if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
  87. return;
  88. }
  89. //获取手机号
  90. app.doDecodePhone(encryptedData, iv, function () {
  91. let userMobile = Activity.getMobileCache();
  92. if (userMobile.length !== 0) {
  93. _self.setData({
  94. userMobile: userMobile,
  95. })
  96. _self.nowBuy();
  97. }
  98. });
  99. },
  100. /**
  101. * 下单
  102. */
  103. async nowBuy() {
  104. let _self = this;
  105. try {
  106. let res = await WelfareMall.createOrder(_self.data.userMobile, _self.data.detail.activityId,1);
  107. _self.setData({
  108. orderInfo: res.data,
  109. })
  110. // console.log(this.data.activityInfo.isPay)
  111. // console.log(_self.data.orderInfo)
  112. if (this.data.detail.isPay == 1 && _self.data.orderInfo.orderSn) {
  113. // console.log(22222)
  114. _self.goPay();
  115. } else {
  116. // wx.reLaunch({
  117. // url: '/pages/couponSuccess/couponSuccess'
  118. // })
  119. }
  120. } catch (err) {
  121. app.showToast(err.msg);
  122. }
  123. },
  124. /**
  125. * 获取订单参数
  126. */
  127. async goPay() {
  128. console.log(wx.getStorageSync('loginInfo').openId)
  129. var _self = this;
  130. let res = await WelfareMall.getOrderParams(_self.data.orderInfo.orderSn,wx.getStorageSync('loginInfo').openId);
  131. console.log(res);
  132. // res = res.wxPrePayVo
  133. wx.requestPayment({
  134. timeStamp: res.wxPrePayVo.timeStamp,
  135. package: res.wxPrePayVo.pack,
  136. nonceStr: res.wxPrePayVo.nonceStr,
  137. signType: res.wxPrePayVo.signType,
  138. paySign: res.wxPrePayVo.paySign,
  139. success: function (res) {
  140. //支付成功,跳转领取成功页面
  141. // wx.reLaunch({
  142. // url: '/pages/couponSuccess/couponSuccess'
  143. // })
  144. },
  145. fail: function (res) {
  146. // console.log('payerror')
  147. // console.log(res);
  148. }
  149. })
  150. }
  151. })