pay.js 785 B

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