// 根目录的static下创建js文件夹并创建mixin.js文件   
export const mixin = { 
	data() {
		return {
			buyId:'',
		}
	},
	methods: {
		// 购买
		creadOrd(item){
			console.log(item);
			if(item.my_is_pay==1) return this.$api.toast('您已经购买过了')
			this.buyId= item.id; 
			this.$refs['popup'].open();
		},
		onConfirm(){
			this.$api
				.request('payment/newVcPay',{
					cate_id:this.buyId,
					pay_type:1,
				})
				.then(data => {
					console.log(data);
					if (data.code && data.code != 200) {
						this.$api.toast(data.msg || '获取支付信息失败');
						return;
					}
					console.log(data);
					const orderInfo = data;
					const { timeStamp, nonceStr, paySign } = orderInfo;
					const payParams = {
						provider: 'wxpay',
						orderInfo: data,
						timeStamp,
						nonceStr,
						package: orderInfo.package,
						signType: 'MD5',
						paySign,
						success: e => {
							setTimeout(res => {
								this.page = 1; 
								this.list = []; 
								this.loadData(); 
							}, 600);
						},
						fail: err => {
							if (err.errMsg.indexOf('取消') > -1 || err.errMsg.indexOf('cancel') > 1 || err.errMsg.indexOf('-2') > -1) {
								this.$api.toast('取消支付');
							} else {
								this.$api.toast('支付遇到错误，请稍候重试');
								console.log(err);
							}
						}
					};
					uni.requestPayment(payParams);
				});
		},
		
 }
}
