activityInfo.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. if (this.data.detail.isPay == 1 && _self.data.orderInfo.orderSn) {
  116. _self.goPay();
  117. } else {
  118. _self.setData({
  119. hideWindowValue:true
  120. })
  121. }
  122. } catch (err) {
  123. app.showToast(err.msg);
  124. }
  125. },
  126. /**
  127. * 获取订单参数
  128. */
  129. async goPay() {
  130. console.log(wx.getStorageSync('loginInfo').openId)
  131. var _self = this;
  132. let result = await WelfareMall.getOrderParams(_self.data.orderInfo.orderSn,wx.getStorageSync('loginInfo').openId);
  133. console.log(result);
  134. let res = result.data
  135. wx.requestPayment({
  136. timeStamp: res.wxPrePayVo.timeStamp,
  137. package: res.wxPrePayVo.pack,
  138. nonceStr: res.wxPrePayVo.nonceStr,
  139. signType: res.wxPrePayVo.signType,
  140. paySign: res.wxPrePayVo.paySign,
  141. success: function (res) {
  142. //支付成功,跳转领取成功页面
  143. _self.setData({
  144. hideWindowValue:true
  145. })
  146. // wx.reLaunch({
  147. // url: '/pages/couponSuccess/couponSuccess'
  148. // })
  149. },
  150. fail: function (res) {
  151. }
  152. })
  153. },
  154. goToOrderList(){
  155. wx.redirectTo({
  156. url: '/pages/welfareMall/historical/historical'
  157. })
  158. },
  159. hideWindow(){
  160. this.setData({
  161. hideWindowValue:false
  162. })
  163. }
  164. })