vip.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // pages/user/walletDetails/walletDetails.js
  2. import Date from '../../../utils/util.js'
  3. import APIClient from '../../../utils/APIClient.js'
  4. import utils from '../../../utils/util'
  5. Page({
  6. data: {
  7. buyBtnText: '立即开通',
  8. price: '29',
  9. bottomText: '原价99元/年',
  10. productId: 0,
  11. modalType: 'image',
  12. isModalShow: false,
  13. isVIP: false
  14. },
  15. onLoad: function (options) {
  16. if (options.title) {
  17. wx.setNavigationBarTitle({
  18. title: VIP购买
  19. });
  20. }
  21. APIClient.getProductData().success(res => {
  22. this.setData({
  23. price: res.data.data.price,
  24. productId: res.data.data.id
  25. })
  26. }).fail(err => {
  27. console.log(err);
  28. });
  29. APIClient.getUserAuth().success(res => {
  30. if (res.data.data) {
  31. this.setData({
  32. isVIP: true,
  33. bottomText: `有效期:${utils.formatDate(res.data.data.endTime,2)}`
  34. })
  35. } else {
  36. this.setData({
  37. isVIP: false
  38. })
  39. }
  40. })
  41. },
  42. createOrder() {
  43. APIClient.postOrder(this.data.productId).success(res => {
  44. this.prePayMap(res.data.data)
  45. }).fail(err => {
  46. console.log(err);
  47. });
  48. },
  49. prePayMap(prePayMap) {
  50. const that = this;
  51. wx.requestPayment({
  52. 'appId': prePayMap.appId,
  53. 'timeStamp': prePayMap.timeStamp,
  54. 'nonceStr': prePayMap.nonceStr,
  55. 'package': prePayMap.package,
  56. 'signType': 'MD5',
  57. 'paySign': prePayMap.sign,
  58. 'success': function (res) {
  59. that.setData({
  60. isModalShow: true,
  61. })
  62. },
  63. 'fail': function (res) {
  64. console.log('支付失败', res)
  65. }
  66. })
  67. },
  68. modalConfirmHandler() {
  69. this.setData({
  70. isModalShow: false
  71. })
  72. wx.redirectTo({
  73. url: `/pages/index/index`
  74. })
  75. },
  76. })