<template>
	<view class="content">
		<view>
			<u-navbar
				title="亲友代付"
				@leftClick="leftClick"
			>
			</u-navbar>
		</view>
		<view class="inner">
			<view class="status_bar" :style="{height: statusBarHeight}"></view>
			<!-- 时间、价格 -->
			<view class="time-price">
				<text class="time">请帮好友支付</text>
				<view class="price-box">
					<text class="unit">¥</text>
					<text class="num" v-if="order.payMoney!=null">{{order.payMoney.toFixed(2)}}</text>
				</view>
			</view>
			<!-- 订单详情查看 -->
			<view class="order-info">
				<view class="title">订单信息</view>
				<view class="item">
					<text class="label">订单编号</text>
					<view class="sn-box">
						<text class="text">{{order.orderSn}}</text>
						<view class="copy-btn" @click="copyTest(order.orderSn)">复制</view>
					</view>
				</view>
				<view class="item">
					<text class="label">下单时间</text>
					<text class="text">{{order.createTime}}</text>
				</view>
			</view>
		</view>
		<view class="btn-box">
			<view class="btn" @click="payOrder()">帮TA支付</view>
		</view>
	</view>
</template>

<script>
	import {getSharePackageOrderById,payment} from '@/api/packageOrder'
	
	export default {
		data() {
			return {
				statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
				orderId:null,
				order:null,
			}
		},
		onLoad(option) {
			this.orderId=option.orderId;
		},
		onShow() {
			this.getPackageOrderById();
		},
		methods: {
			leftClick() {
				uni.showToast({
					title:'请帮好友支付',
					icon:'none'
				})
			},
			copyTest(text) {
				// 复制方法
				uni.setClipboardData({
					data:text,
					success:()=>{
						uni.showToast({
							title:'内容已成功复制到剪切板',
							icon:'none'
						})
					}
				});
			},
			getPackageOrderById(){
				var data = {orderId:this.orderId};
				var that=this;
				uni.showLoading();
				getSharePackageOrderById(data).then(
					res => {
						if(res.code==200){
							uni.hideLoading();
							that.order=res.order;
						}else{
							uni.showToast({
								icon:'none',
								title: res.msg,
							});
						}
					},
					rej => {}
				);
				
			},
			payOrder(){
				var data = {
					orderId:this.orderId,
					appId: getApp().globalData.appId
				};
				var that=this;
				uni.showLoading();
				payment(data).then(
					res => {
						if(res.code==200){
							if(res.isPay==0){
								if(res.type=="tz"){
									uni.setStorageSync("ztPayUrl",res.data.body.url)
									uni.navigateTo({
										url:"/pages_order/tzPay"
									})
								}
								if(res.type=="yb"){
									var payData=JSON.parse(res.data.pay_info)
									console.log(payData)
									uni.requestPayment({
									 	provider: 'wxpay',
									 	timeStamp: payData.timeStamp,
									 	nonceStr: payData.nonceStr,
									 	package: payData.package,
									 	signType: payData.signType,
									 	paySign: payData.paySign,
									 	success: function(res) {
											console.log(that.order.orderId)
									 		 uni.hideLoading();
											 uni.redirectTo({
											 	url:"./packageOrderPaySuccess?orderId="+that.order.orderId
											 }) 
											 
									 	},
									 	fail: function(err) {
											uni.showToast({
												icon:'none',
												title:'fail:' + JSON.stringify(err),
											});
									 		uni.hideLoading();
											
									 	}
									});
									
								}
								else if(res.type=="wx"){
									uni.requestPayment({
									 	provider: 'wxpay',
									 	timeStamp: res.data.timeStamp,
									 	nonceStr: res.data.nonceStr,
									 	package: res.data.packageValue,
									 	signType: res.data.signType,
									 	paySign: res.data.paySign,
									 	success: function(res) {
											console.log(that.order.orderId)
									 		 uni.hideLoading();
											 uni.redirectTo({
											 	url:"./packageOrderPaySuccess?orderId="+that.order.orderId
											 }) 
											 
									 	},
									 	fail: function(err) {
											uni.showToast({
												icon:'none',
												title:'fail:' + JSON.stringify(err),
											});
									 		uni.hideLoading();
											
									 	}
									});
									
								}
							}
							else{
								uni.hideLoading();
								uni.redirectTo({
									url:"./packageOrderPaySuccess?orderId="+that.order.orderId
								}) 
							}
						}else{
							uni.showToast({
								icon:'none',
								title: res.msg,
							});
							this.$reLoginCheck(res.msg)
						}
					},
					rej => {}
				);
				
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.content{
		margin-top: 44px;
		height: 100%;
		.inner{
			padding: 20upx;
			.time-price{
				box-sizing: border-box;
				padding: 50upx 0upx;
				background: #FFFFFF;
				border-radius: 16upx;
				display: flex;
				flex-direction: column;
				align-items: center;
				.time{
					font-size: 32upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #222222;
					line-height: 1;
					text-align: center;
				}
				.desc{
					margin: 30upx 0upx 15upx;
					font-size: 26upx;
					font-family: PingFang SC;
					color: #999999;
					line-height: 1;
					text-align: center;
				}
				.price-box{
					display: flex;
					align-items: flex-end;
					margin-top: 28upx;
					.unit{
						font-size: 32upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #FF6633;
						line-height: 1.3;
						margin-right: 10upx;
					}
					.num{
						font-size: 56upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #FF6633;
						line-height: 1;
					}
				}
			}
			 
			.order-info{
				margin-top: 20upx;
				background: #FFFFFF;
				border-radius: 16upx;
				padding: 40upx 30upx;
				.title{
					font-size: 30upx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #222222;
					line-height: 1;
				}
				.item{
					margin-top: 40upx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.label{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #666666;
						line-height: 1;
					}
					.text{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #222222;
						line-height: 32upx;
					}
					.cont-text{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #666666;
						.bold{
							color: #111111;
						}
					}
					.sn-box{
						display: flex;
						align-items: center;
						.copy-btn{
							width: 58upx;
							height: 32upx;
							line-height: 32upx;
							text-align: center;
							font-size: 22upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #222222;
							background: #F5F5F5;
							border-radius: 4upx;
							margin-left: 24upx;
						}
					}
					 
				}
				.line{
					width: 100%;
					height: 1px;
					background: #F0F0F0;
					margin-top: 30upx;
				}
			}
		}
		.btn-box{
			width:100%;
			height: 121upx;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			.btn{
				width: 91.73%;
				height: 88upx;
				line-height: 88upx;
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				text-align: center;
				background: #2583EB;
				border-radius: 44upx;
				margin-bottom: 10rpx;
			}
		}
	}
	
</style>
