敢为人鲜小程序前端代码仓库
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.

65 lines
1.3 KiB

5 months ago
5 months ago
5 months ago
5 months ago
2 days ago
4 months ago
5 months ago
  1. import { mapMutations } from 'vuex'
  2. export default {
  3. data() {
  4. return {
  5. }
  6. },
  7. computed: {
  8. },
  9. methods: {
  10. ...mapMutations(['clearCouponData']),
  11. // 支付接口
  12. handlePay(orderParams) {
  13. uni.showLoading({
  14. title: '支付处理中...'
  15. })
  16. if (!orderParams.userCouponId) {
  17. // 没有优惠卷 则不传
  18. delete orderParams.userCouponId
  19. }
  20. if (orderParams.remark == '') {
  21. delete orderParams.remark
  22. }
  23. this.$api('createOrder', {
  24. ...orderParams
  25. }, res => {
  26. uni.hideLoading()
  27. if (res.code === 200) {
  28. if (orderParams.payType == '0') {
  29. uni.requestPaymentWxPay(res)
  30. .then(n => {
  31. setTimeout(uni.redirectTo, 700, {
  32. url: '/pages/index/order?tabIndex=1'
  33. })
  34. })
  35. .catch(err => {
  36. uni.showToast({
  37. title: '支付失败',
  38. icon: 'error'
  39. })
  40. setTimeout(uni.redirectTo, 700, {
  41. url: '/pages/index/order?tabIndex=0'
  42. })
  43. })
  44. } else {
  45. uni.showToast({
  46. title: '下单成功',
  47. icon: 'success'
  48. })
  49. // 重新刷新剩余金额
  50. this.$store.commit('getUserInfo')
  51. setTimeout(uni.redirectTo, 700, {
  52. url: '/pages/index/order?tabIndex=1'
  53. })
  54. }
  55. }
  56. })
  57. },
  58. },
  59. beforeDestroy() {
  60. this.clearCouponData();
  61. }
  62. }