<template>
	<view>
		<u-popup
			close-icon-color="red"
			v-model="show"
			mode="center"
			:mask-close-able="false"
			length="auto"
			:closeable="true"
			close-icon="close"
			:border-radius="20"
			:z-index="9999"
		>
			<view style="background:#fff;width:550rpx;padding:40rpx;border-radius:20px">
				<u-icon @click="closePay" name="close" style="float:right;font-size:40rpx"></u-icon>
				<p style="text-align: center;font-size: 26rpx;">支付方式</p>
				<p style="font-size: 36rpx;font-weight: 700;text-align: center;margin:30px 0">支付金额{{ payInfo.total_price }}元</p>
				<p>
					<img style="width:50rpx;height:50rpx;margin-right:10px" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/wx.png" alt="" />
					<span style="position:relative;top:-7px">微信支付</span>
				</p>
				<view style="margin-top:30px"><u-button @click="Pay" type="error" shape="circle">支付</u-button></view>
			</view>
		</u-popup>
	</view>
</template>

<script>
export default {
	props: ['payInfo'],
	data() {
		return {
			show: true,
			orderInfo: {},
			
			
		};
	},
	created() {
		this.getDataInfo();
	},
	methods: {
		closePay() {
			this.$emit('closePay');
		},
		getDataInfo() {
			let that=this;
			console.log("that.payInfo",that.payInfo)
			let msg = {
				OpenId: that.payInfo.OpenId,
				OrderId: that.payInfo.OrderId,
				OrderPayType:that.payInfo.OrderPayType,
				GoodsName: that.payInfo.GoodsName
			};
			this.request2(
				{
					url: '/api/WeChatPay/GetPayInfo',
					data: msg
				},
				res => {
					if (res.resultCode == 1) {
						this.orderInfo = JSON.parse(res.data);
					}
					uni.hideNavigationBarLoading();
				}
			);
		},
		Pay() {
			let that=this;
			let orderInfo = this.orderInfo;
			uni.requestPayment({
				provider: 'wxpay',
				timeStamp: this.orderInfo.timeStamp,
				nonceStr: this.orderInfo.nonceStr,
				package: this.orderInfo.package,
				signType: this.orderInfo.signType,
				paySign: this.orderInfo.sign,
				success: function(res) {
					console.log('success', res);
					if(that.payInfo.successType==1){
						uni.navigateTo({
							url: '/pages/reserve/offline-success?payInfo='+JSON.stringify(that.payInfo)
						});
					}else{
						uni.navigateTo({
							url: '/pages/order-submit/pay-success?payInfo='+JSON.stringify(that.payInfo)
						});
					}
					
				},
				fail: function(err) {
					console.log('fail:', err);
				}
			});
		}
	}
};
</script>

<style></style>
