/**
 * 订单支付
 */
import Vue from "vue";
//#ifdef H5
import $wxApi from "./wxapi.js";
//#endif
import Request from '@/js_sdk/luch-request/luch-request/index.js';
const $http = new Request();

import {config} from './config/config.js';
export default {
	//微信支付
	wxPay(obj = {}) {
		uni.showLoading({
			title: '支付中'
		});
		return new Promise(r => {
			let token = uni.getStorageSync("token");
			$http.post(config.apiBaseurl + "/app/pay",obj,{
				header: {
					Accept:'application/json',
					Authorization: 'Bearer '+ token, //注意Bearer后面有一空格
				},
			}).then(res=>{
				console.log('res',res);
					//#ifdef H5
					$wxApi.JSAPI(res.data.data).then(r);
					//#endif
					this.payError(res);
				})
		});
	},
	//支付错误处理
	payError(res){
		uni.hideLoading();
		// uni.navigateTo({
		// 	url: '/pages/usercenter/myorder/myorder',
		// 	fail:function(err){
		// 		console.log(err)
		// 	}
		// });
		// console.log('1',res);
		if(res.code == 623){
			setTimeout(i=>{
				new Vue().$api.goto("/pages/userCenter/myorder/myorder");
			},2000);
			uni.showToast({
				title:res.msg + "    即将跳转到订单页",
				icon:"none",
				duration:2000
			});
		}
	}
}