123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /**
- * 订单支付
- */
- import Vue from "vue";
- //#ifdef H5
- import $wxApi from "./wxapi.js";
- //#endif
- // import $http from "./utils/axios.js"
- import $http from "./uview-ui/libs/request"
- export default {
- //微信支付
- wxPay(obj = {}) {
- uni.showLoading({
- title: '支付中'
- });
- return new Promise(r => {
- $http.post("/client/wechat/pay",obj)
- .then(res=>{
- //#ifdef H5
- $wxApi.JSAPI(res.data).then(r);
- //#endif
- this.payError(res);
- }).catch(err =>{
- // alert(err.msg);
- console.log('pay err',err);
- })
- });
- },
- /**
- * 微信支付
- * obj 传入对象
- * url 提交地址
- * jumpUrl 支付成功跳转
- */
- wechatPay(obj = {}, url = '/client/pay/wechat', jumpUrl) {
- uni.showLoading({
- title: '支付中'
- });
- return new Promise(r => {
- $http.post(url, obj)
- .then(res=>{
- // 区分包月支付和普通支付
- if (res.data.needPay && !res.data.monthId) {
- //#ifdef H5
- $wxApi.JSAPI(res.data.wx, jumpUrl).then(r);
- //#endif
- } else if (res.data.monthId) {
- //#ifdef H5
- $wxApi.JSAPI(res.data.wx, jumpUrl).then(r);
- //#endif
- } else {
- uni.showToast({
- title: "无需支付",
- icon: "none",
- duration: 2000
- });
- setTimeout(() =>{
- //#ifdef H5
- if (jumpUrl) {
- window.location.href = jumpUrl;
- } else {
- window.location.reload();
- }
- //#endif
- }, 1500)
- }
- this.payError(res);
- }).catch(err =>{
- // alert(err.msg);
- console.log('pay err',err);
- })
- });
- },
- //支付错误处理
- payError(res){
- uni.hideLoading();
- if(res.code == 623){
- setTimeout(i=>{
- new Vue().$api.goto("/pages/userCenter/myOrder/myOrder");
- },2000);
- uni.showToast({
- title:res.msg + " 即将跳转到订单页",
- icon:"none",
- duration:2000
- });
- }
- }
- }
|