pay.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. wechatPay(obj = {}) {
  32. uni.showLoading({
  33. title: '支付中'
  34. });
  35. return new Promise(r => {
  36. $http.post("/pay/wechat",obj)
  37. .then(res=>{
  38. //#ifdef H5
  39. $wxApi.JSAPI(res.data.wx).then(r);
  40. //#endif
  41. this.payError(res);
  42. }).catch(err =>{
  43. // alert(err.msg);
  44. console.log('pay err',err);
  45. })
  46. });
  47. },
  48. //支付错误处理
  49. payError(res){
  50. uni.hideLoading();
  51. if(res.code == 623){
  52. setTimeout(i=>{
  53. new Vue().$api.goto("/pages/userCenter/myOrder/myOrder");
  54. },2000);
  55. uni.showToast({
  56. title:res.msg + " 即将跳转到订单页",
  57. icon:"none",
  58. duration:2000
  59. });
  60. }
  61. }
  62. }