/*
 * 手太欠
 * 企获客商城
 */

const app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		orderData: '', //订单详情
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		console.log(options.orderid)
		this.orderInfo(options.orderid)
	},

	/**
	 * 订单支付
	 */
	orderInfo(orderId) {
		wx.$api.order.paymen(orderId).then(res => {
			this.setData({
				orderData: res
			})
		})
	},

	/**
	 * 订单支付
	 */
	payment() {
		// 获取code
		wx.login({
			success: res => {
				wx.$api.mall.wechat({
					code: res.code,
					trade_no: this.data.orderData.trade_no
				}).then(res => {
					let payInfo = JSON.parse(res)
					wx.requestPayment({
						timeStamp: payInfo.timeStamp,
						nonceStr: payInfo.nonceStr,
						package: payInfo.package,
						paySign: payInfo.paySign,
						signType: payInfo.signType,
						success: res => {
							if (res.errMsg == "requestPayment:ok") {
								wx.showToast({
									title: '支付成功',
									icon: 'success'
								})
								setTimeout(() => {
									wx.navigateBack({
										delta: 0,
									})
								}, 2000)
							}
						},
						fail: res => {
							wx.navigateBack({
								delta: 0,
							})
						}
					})
				})
			}
		})
	}
})