C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

87 Zeilen
2.3 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. wx.showLoading({
  21. title: '加载中...',
  22. })
  23. console.log(this.data.couponId)
  24. Common.orderSave(''+this.data.couponId)
  25. .then(res => {
  26. wx.hideLoading();
  27. console.log(res)
  28. if (res.data.code == 200) {
  29. Common.payOrderCreate(res.data.data.id)
  30. .then(res =>{
  31. wx.requestPayment({
  32. timeStamp: res.data.data.timeStamp,
  33. nonceStr: res.data.data.nonceStr,
  34. package: res.data.data.package,
  35. signType: 'MD5',
  36. paySign: res.data.data.paySign,
  37. 'success': function (res) {
  38. console.log('支付成功');
  39. wx.showToast({
  40. title: '购买成功',
  41. duration: 2500
  42. })
  43. wx.navigateBack({
  44. delta: 2
  45. })
  46. },
  47. 'fail': function (res) {
  48. console.log('支付失败');
  49. console.log(res)
  50. return;
  51. },
  52. 'complete': function (res) {
  53. console.log('支付完成');
  54. var url = that.data.url;
  55. console.log('get url', url)
  56. if (res.errMsg == 'requestPayment:ok') {
  57. wx.showModal({
  58. title: '提示',
  59. content: '支付成功'
  60. });
  61. if (url) {
  62. setTimeout(function () {
  63. wx.redirectTo({
  64. url: '/pages' + url
  65. });
  66. }, 2000)
  67. } else {
  68. setTimeout(() => {
  69. wx.navigateBack()
  70. }, 2000)
  71. }
  72. }
  73. return;
  74. }
  75. })
  76. })
  77. } else {
  78. wx.showToast({
  79. title: res.data.message,
  80. duration: 3000
  81. })
  82. }
  83. })
  84. }
  85. })