C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 regels
2.8 KiB

  1. let Common = require('../../../common/common.js')
  2. var app = getApp()
  3. Page({
  4. data: {
  5. list:{},
  6. couponId:null
  7. },
  8. onLoad(e) {
  9. console.log(e.id)
  10. Common.getCouponDetail(e.id)
  11. .then(res =>{
  12. console.log(res)
  13. this.setData({
  14. list: res.data.data,
  15. couponId: e.id
  16. })
  17. })
  18. },
  19. orderfunc(){
  20. var orderId = '';
  21. var payOrderId = '';
  22. wx.showLoading({
  23. title: '加载中...',
  24. })
  25. console.log(this.data.couponId)
  26. Common.orderSave(''+this.data.couponId)
  27. .then(res => {
  28. wx.hideLoading();
  29. console.log(res)
  30. if (res.data.code == 200) {
  31. return res;
  32. } else {
  33. wx.showToast({
  34. title: res.data.message,
  35. duration: 3000
  36. })
  37. }
  38. })
  39. .then(res => {
  40. orderId = '' + res.data.data.id;
  41. return Common.payOrderCreate(orderId)
  42. })
  43. .then(res => {
  44. console.log(res)
  45. payOrderId = res.data.data.payOrderId;
  46. if (res.data.code == 200) {
  47. wx.requestPayment({
  48. timeStamp: res.data.data.timeStamp,
  49. nonceStr: res.data.data.nonceStr,
  50. package: res.data.data.package,
  51. signType: 'MD5',
  52. paySign: res.data.data.paySign,
  53. 'success': function (res) {
  54. Common.payOrderUpdate(orderId, payOrderId, 1); // 支付成功
  55. console.log(res);
  56. console.log('支付成功');
  57. wx.showToast({
  58. title: '购买成功',
  59. duration: 2500
  60. })
  61. wx.navigateBack({
  62. delta: 2
  63. })
  64. },
  65. 'fail': function (res) {
  66. Common.payOrderUpdate(orderId, payOrderId, 2); // 支付失败
  67. console.log(res)
  68. console.log('支付失败');
  69. return;
  70. },
  71. 'complete': function (res) {
  72. console.log(res);
  73. console.log('支付完成');
  74. var url = that.data.url;
  75. console.log('get url', url)
  76. if (res.errMsg == 'requestPayment:ok') {
  77. wx.showModal({
  78. title: '提示',
  79. content: '支付成功'
  80. });
  81. if (url) {
  82. setTimeout(function () {
  83. wx.redirectTo({
  84. url: '/pages' + url
  85. });
  86. }, 2000)
  87. } else {
  88. setTimeout(() => {
  89. wx.navigateBack()
  90. }, 2000)
  91. }
  92. } else {
  93. wx.showModal({
  94. title: '错误提示',
  95. content: res.errMsg
  96. });
  97. }
  98. return;
  99. }
  100. })
  101. }
  102. })
  103. }
  104. })