pay.js 888 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. alert(err.msg);
  26. console.log('pay err',err);
  27. })
  28. });
  29. },
  30. //支付错误处理
  31. payError(res){
  32. uni.hideLoading();
  33. if(res.code == 623){
  34. setTimeout(i=>{
  35. new Vue().$api.goto("/pages/userCenter/myOrder/myOrder");
  36. },2000);
  37. uni.showToast({
  38. title:res.msg + " 即将跳转到订单页",
  39. icon:"none",
  40. duration:2000
  41. });
  42. }
  43. }
  44. }