pay.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * 订单支付
  3. */
  4. import Vue from "vue";
  5. //#ifdef H5
  6. import $wxApi from "./wxapi.js";
  7. //#endif
  8. import Request from '@/js_sdk/luch-request/luch-request/index.js';
  9. const $http = new Request();
  10. import {config} from './config/config.js';
  11. export default {
  12. //微信支付
  13. wxPay(obj = {}) {
  14. uni.showLoading({
  15. title: '支付中'
  16. });
  17. return new Promise(r => {
  18. let token = uni.getStorageSync("token");
  19. $http.post(config.apiBaseurl + "/app/pay",obj,{
  20. header: {
  21. Accept:'application/json',
  22. Authorization: 'Bearer '+ token, //注意Bearer后面有一空格
  23. },
  24. }).then(res=>{
  25. console.log('res',res);
  26. //#ifdef H5
  27. $wxApi.JSAPI(res.data.data).then(r);
  28. //#endif
  29. this.payError(res);
  30. })
  31. });
  32. },
  33. //支付错误处理
  34. payError(res){
  35. uni.hideLoading();
  36. if(res.code == 623){
  37. setTimeout(i=>{
  38. new Vue().$api.goto("/pages/userCenter/myorder/myorder");
  39. },2000);
  40. uni.showToast({
  41. title:res.msg + " 即将跳转到订单页",
  42. icon:"none",
  43. duration:2000
  44. });
  45. }
  46. }
  47. }