buyMember.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api');
  3. var user = require('../../../utils/user.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. buyType: '2', //1月卡 2年卡
  11. oldPrice: '199',
  12. actualPrice: '199',
  13. typeList: [{
  14. url:'https://jzmall.lifejingzhi.com/file/jzmall/weixin/memberCard-1229/member-type-1.png',
  15. type: '2',
  16. name: '年卡',
  17. price: '199',
  18. typeName: '年',
  19. oldPrice: '199'
  20. },
  21. {
  22. url:'https://jzmall.lifejingzhi.com/file/jzmall/weixin/memberCard-1229/member-type-2.png',
  23. type: '1',
  24. name: '月卡',
  25. price: '19',
  26. typeName: '月',
  27. oldPrice: '19'
  28. },
  29. {
  30. url:'https://jzmall.lifejingzhi.com/file/jzmall/weixin/memberCard-1229/member-type-3.png',
  31. type: '3',
  32. name: '年卡',
  33. },
  34. ],
  35. memberUserInfo:{
  36. nickName: '用户',
  37. avatarUrl: '/static/images/new/icon-user.png',
  38. level:'0'
  39. }
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. },
  46. switchType(e) {
  47. let type = e.currentTarget.dataset.type;
  48. let actualPrice = e.currentTarget.dataset.price;
  49. this.setData({
  50. buyType: type,
  51. actualPrice: actualPrice,
  52. oldPrice: type == '2' ? '199' : '19'
  53. });
  54. },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function () {
  64. this.setData({
  65. memberUserInfo:app.globalData.memberUserInfo
  66. });
  67. },
  68. /**
  69. * 生命周期函数--监听页面隐藏
  70. */
  71. onHide: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面卸载
  75. */
  76. onUnload: function () {
  77. },
  78. /**
  79. * 页面相关事件处理函数--监听用户下拉动作
  80. */
  81. onPullDownRefresh: function () {
  82. },
  83. /**
  84. * 页面上拉触底事件的处理函数
  85. */
  86. onReachBottom: function () {
  87. },
  88. /**
  89. * 用户点击右上角分享
  90. */
  91. onShareAppMessage: function () {
  92. },
  93. payNow() {
  94. let that=this
  95. wx.showModal({
  96. title: "会员开卡确认",
  97. content: "会员权益卡,购买后无法退换,确定购买?",
  98. showCancel: true,
  99. cancelText: "取消",
  100. cancelColor: "#000",
  101. confirmText: "购买",
  102. confirmColor: "#0f0",
  103. success: function (res) {
  104. if (res.confirm) {
  105. that.memberSubmit();
  106. }
  107. }
  108. })
  109. },
  110. memberSubmit() {
  111. let orderInfo = {
  112. userId: app.globalData.userInfo.id,
  113. memberType: this.data.buyType,
  114. };
  115. util.request(api.memberSubmit, orderInfo, 'POST').then(res => {
  116. if (res.errno === 0) {
  117. let orderId = res.data.memberOrderNo;
  118. this.prepayMember(orderId);
  119. } else {
  120. util.showErrorToast(res.errmsg);
  121. }
  122. });
  123. },
  124. prepayMember(orderId) {
  125. util.request(api.prepayMember, {
  126. memberOrderNo: orderId
  127. }, 'POST').then(res => {
  128. if (res.errno === 0) {
  129. let payParam = res.data;
  130. console.log("支付过程开始");
  131. wx.requestPayment({
  132. 'timeStamp': payParam.timeStamp,
  133. 'nonceStr': payParam.nonceStr,
  134. 'package': payParam.packageValue,
  135. 'signType': payParam.signType,
  136. 'paySign': payParam.paySign,
  137. 'success': res => {
  138. console.log("支付过程成功");
  139. wx.redirectTo({
  140. url: '/pages/member/becomeMember/becomeMember',
  141. })
  142. },
  143. 'fail': res => {
  144. console.log("支付过程失败");
  145. util.showErrorToast('支付失败');
  146. },
  147. 'complete': function (res) {
  148. console.log("支付过程结束")
  149. }
  150. });
  151. } else {
  152. util.showErrorToast(res.errmsg);
  153. }
  154. });
  155. },
  156. goConvert() {
  157. wx.navigateTo({
  158. url: '/pages/member/memberConvert/memberConvert',
  159. })
  160. },
  161. })