<template>
	<view>
		<view class="cont">
			<view class="bg"></view>
			<view class="inner">			
				<!-- 订单状态 -->
				<view class="order-status">
					<!-- 待付款 -->
					<view v-if="order.status == 1" class="inner">
						<view class="img-box">
							<image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/67eda0644e5847008096525b04cd12ca.png" mode=""></image>
						</view>
						<view class="status-box">
							<text class="status">待付款</text>
							<!-- <text class="desc">请在{{payLimitTime}}前完成支付</text> -->
						</view>
					</view>
					<!-- 服务中 -->
					<view v-if="order.status == 2" class="inner">
						<view class="img-box">
							<image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/b71efb4b5ca54564b553569d578738b4.png" mode=""></image>
						</view>
						<view class="status-box">
							<text class="status">服务中</text>
							<text class="desc">正在服务中</text>
						</view>
					</view>
					<!-- 已完成 -->
					<view v-if="order.status == 3" class="inner">
						<view class="img-box">
							<image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/0712ba14f3a648afa69c9912fcbf9b61.png" mode=""></image>
						</view>
						<view class="status-box">
							<text class="status">已完成</text>
							<text class="desc">服务已完成</text>
						</view>
					</view>
					<!--交易取消 -->
					<view v-if="order.status == -1" class="inner">
						<view class="img-box">
							<image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/02f95bd03e854a9c8076aef1e6c05e74.png" mode=""></image>
						</view>
						<view class="status-box">
							<text class="status">交易关闭</text>
							<text class="desc">订单已取消</text>
						</view>
					</view>
					<view v-if="order.status == -2" class="inner">
						<view class="img-box">
							<image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/6020712aa10f4bb08db92957cb7eb8ed.png" mode=""></image>
						</view>
						<view class="status-box">
							<text class="status">退款成功</text>
							<text class="desc">已成功退款</text>
						</view>
					</view>
				</view>
				<view class="content">
					<view class="package-box">
						<view class="left">
							<image :src="package.imgUrl"></image>
						</view>
						<view class="right">
							<view class="title">{{package.packageName}}</view>
							<view class="desc">
								<view class="cycle">用药周期{{package.cycle}}天</view>
								<view class="duration">签约时长{{package.duration}}天</view>
							</view>
							<!-- <view class="price-box">
								<view class="price">￥30元/日</view>
								<view class="count">6.2w人已购</view>
							</view> -->
						</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="copyOrderSn(order.orderSn)">复制</view>
							</view>
						</view>
						<view class="item">
							<text class="label">下单时间</text>
							<text class="text">{{order.createTime}}</text>
						</view>
						<view class="item">
							<text class="label">支付方式</text>
							<text class="text" v-if="order.payType==1">全款支付</text>
							<text class="text" v-if="order.payType==2">物流代收</text>
							<text class="text" v-if="order.payType==3">货到付款</text>
						</view>
						<view   class="item">
							<text class="label">订单金额</text>
							<text class="text" v-if="order.payPrice!=null">¥{{order.payPrice.toFixed(2)}}</text>
						</view>
						<view   class="item">
							<text class="label">支付金额</text>
							<text class="text" v-if="order.payMoney!=null">¥{{order.payMoney.toFixed(2)}}</text>
						</view>
						<view   class="item">
							<text class="label">抵扣金额</text>
							<text class="text" v-if="order.discountMoney!=null">¥{{order.discountMoney.toFixed(2)}}</text>
						</view>
						<view   class="item">
							<text class="label">代收金额</text>
							<text class="text" v-if="order.payRemain!=null">¥{{order.payRemain.toFixed(2)}}</text>
						</view>
						<view   class="item">
							<text class="label">运费金额</text>
							<text class="text" v-if="order.payDelivery!=null">¥{{order.payDelivery.toFixed(2)}}</text>
						</view>
						<view  class="item">
							<text class="label">支付时间</text>
							<text class="text">{{order.payTime}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 按钮 -->
		<view   class="btn-box">
			<view  class="btn cancel" v-if="order.status==1" @click="cancelOrder()">取消订单</view>
			<view class="btn pay" v-if="order.status==1" @click="pay()">支付</view>
			
		</view>
	</view>
</template>

<script>
	
	import {cancelOrder,getPackageOrderById,pay} from '@/api/packageOrder'
	
	export default {
		data() {
			return {
				orderId:null,
				order:{},
				package:null,
				items:[],
		 
			};
		},
		onLoad(option) {
			this.orderId = option.orderId
			this.getPackageOrderById();
		},
		onShow() {
			 
		},
		methods: {
			cancelOrder(){
				var that=this;
				uni.showModal({
					title:"提示",
					content:"确认取消订单吗?",
					showCancel:true,
					cancelText:'取消',
					confirmText:'确定',
					success:res=>{
						if(res.confirm){
							// 用户点击确定
							var data={orderId:that.orderId}
							cancelOrder(data).then(
								res => {
									if(res.code==200){
										uni.$emit('refreshPackageOrder');
										that.getPackageOrderById()
										uni.showToast({
										 	icon:'success',
										 	title: "操作成功",
										});
									}else{
										uni.showToast({
											icon:'none',
											title: res.msg,
										});
									}
								},
								rej => {}
							);
														
						}else{
							// 否则点击了取消  
						}
					}
				})
			}, 
			getPackageOrderById(){
				var data={orderId:this.orderId};
				getPackageOrderById(data).then(res => {
					if(res.code==200){
						this.order=res.order;
						this.package=JSON.parse(this.order.packageJson)
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						 
					}
				});
			},
			pay() {
				 uni.navigateTo({
				 	url: '/pages_order/packageOrderPay?orderId='+this.order.orderId
				 })
			},
			// 返回上一页
			back() {
				let pages = getCurrentPages();
				console.log(pages.length);
				if(pages.length>1){
					uni.navigateBack()
				}
				else{
					uni.reLaunch({
						url:"/pages/common/launch"
					})
				}
				
			},
			// 复制订单编号
			copyOrderSn(text) {
				// 复制方法
				uni.setClipboardData({
					data:text,
					success:()=>{
						uni.showToast({
							title:'内容已成功复制到剪切板',
							icon:'none'
						})
					}
				});
			},
			 
		}
	}
</script>

<style lang="scss">
	.cont{
		width: 100%;
		position: relative;
		.bg{
			width: 100%;
			height: 350upx;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 1;
			background-color: #C39A58;
			background: linear-gradient(#C39A58, #E2C99E);
			border-radius: 0rpx 0rpx 100rpx 100rpx;
		}
		.inner{
			position: relative;
			padding: 30upx 0rpx;
			width: 100%;
			height: 100%;
			z-index: 999;
			.order-status{
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 30upx;
				.inner{
					display: flex;
					align-items: center;
					.img-box{
						width: 96upx;
						height: 96upx;
						margin-right: 30upx;
						image{
							width: 100%;
							height: 100%;
						}
					}
					.status-box{
						height: 96upx;
						display: flex;
						flex-direction: column;
						justify-content: center;
						.status{
							font-size: 40upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #FFFFFF;
							line-height: 1;
						}
						.desc{
							font-size: 26upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #FFFFFF;
							line-height: 1;
							margin-top: 30upx;
						}
					}
				}
			}
			 
		}
	}
	.content{
		margin: 20rpx 0rpx;
		padding: 0 20upx 140rpx 20upx;
		.package-box{
			width: 100%;
			display: flex;
			padding: 20rpx;
			background-color: #fff;
			align-items: flex-start;
			justify-content: flex-start;
			box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
			border-radius: 15rpx;
			.left{
				width:200rpx;
				height:200rpx;
				image{
					border-radius: 15rpx;
					width:100%;
					height:100%;
				}
			}
			.right{
				height: 200rpx;
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				justify-content: flex-start;
				padding-left: 15rpx;
				width:calc(100% - 200rpx);
				.title{
					font-weight: bold;
					font-size: 34upx;
					font-family: PingFang SC;
					color: #111;
				}
				.desc{
					margin-top: 15rpx;
					display: flex;
					align-items: flex-start;
					justify-content: flex-start;
					.cycle{
						background-color: #eee;
						border-radius: 30rpx;
						padding: 5rpx 15rpx;
						font-size: 26upx;
						font-family: PingFang SC;
						color: #C39A58;
					}
					.duration{
						margin-left: 10rpx;
						background-color: #eee;
						border-radius: 30rpx;
						padding: 5rpx 15rpx;
						font-size: 26upx;
						font-family: PingFang SC;
						color: #C39A58;
					}
					
				}
				.price-box{
					flex: 1;
					display: flex;
					align-items: flex-end;
					justify-content: space-between;
					width: 100%;
					.price{
						padding: 5rpx 10rpx;
						background-color: #C39A58;
						border-radius: 30rpx;
						font-size: 20upx;
						font-family: PingFang SC;
						color: #ffffff;
					}
					.count{
						font-size: 24upx;
						font-family: PingFang SC;
						color: #333333;
					}
					
				}
			}
			
			 
		}
		.order-info{
			box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
			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;
					}
				}
				.check-box{
					display: flex;
					align-items: center;
					image{
						width: 14upx;
						height: 24upx;
						margin-left: 10upx;
					}
				}
			}
			.line{
				width: 100%;
				height: 1px;
				background: #F0F0F0;
				margin-top: 30upx;
			}
		}
	}
	.btn-box{
		z-index: 999;
		bottom: 0;
		width: 100%;
		position: fixed;
		height: 120upx;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 0 30upx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		.btn{
			width: 155upx;
			height: 64upx;
			line-height: 64upx;
			font-size: 26upx;
			font-family: PingFang SC;
			font-weight: 500;
			text-align: center;
			border-radius: 32upx;
			margin-left: 15upx;
			&.cancel{
				border: 1px solid #DDDDDD;
				color: #666666;
			}
			&.pay{
				background: #C39A58;
				color: #FFFFFF;
			}
		}
	}
</style>
