activityInfo.js 4.0 KB

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