pay.js 867 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * 订单支付
  3. */
  4. import Vue from "vue";
  5. //#ifdef H5
  6. import $wxApi from "./wxapi.js";
  7. //#endif
  8. // import $http from "./utils/axios.js"
  9. import $http from "./uview-ui/libs/request"
  10. export default {
  11. //微信支付
  12. wxPay(obj = {}) {
  13. uni.showLoading({
  14. title: '支付中'
  15. });
  16. return new Promise(r => {
  17. $http.post("/wechat/pay",obj)
  18. // this.$u.post("/wechat/h5/pay",obj)
  19. .then(res=>{
  20. //#ifdef H5
  21. $wxApi.JSAPI(res.data).then(r);
  22. //#endif
  23. this.payError(res);
  24. }).catch(err =>{
  25. console.log('pay err',err);
  26. })
  27. });
  28. },
  29. //支付错误处理
  30. payError(res){
  31. uni.hideLoading();
  32. if(res.code == 623){
  33. setTimeout(i=>{
  34. new Vue().$api.goto("/pages/userCenter/myOrder/myOrder");
  35. },2000);
  36. uni.showToast({
  37. title:res.msg + " 即将跳转到订单页",
  38. icon:"none",
  39. duration:2000
  40. });
  41. }
  42. }
  43. }