<template>
	<view>
		<view class="top-cont">
			<!-- 背景图片 -->
			<image class="bg" src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/order_top_bg.png" mode=""></image>
			<view class="top-inner">			
				<!-- 这里是状态栏 -->
				<view class="fixed-top-box">
					<view class="status_bar" :style="{height: statusBarHeight}"></view>
					<view class="back-box" @click="back">
						<image src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/back_white.png" mode=""></image>
						<text class="title">订单详情</text>
						<text></text>
					</view>
				</view>
				
				<!-- 顶部固定后站位元素 -->
				<view style="padding-bottom: 88upx;">
					<view :style="{height: statusBarHeight}"></view>
				</view>
				<!-- 订单状态 -->
				<view class="order-status">
					<!-- 待付款 -->
					<view v-if="order.status == 0" class="inner">
						<view class="img-box">
							<image src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/pag96.png" mode=""></image>
						</view>
						<view class="status-box">
							<text class="status">待付款</text>
							<text class="desc">请在{{payLimitTime}}前完成支付</text>
						</view>
					</view>
					<!-- 待发货 -->
					<view v-if="order.status == 1" class="inner">
						<view class="img-box">
							<image src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/pag96.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://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/receipt.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://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/finish96.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://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/close_trade.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://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/close_trade.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://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/close_trade.png" mode=""></image>
						</view>
						<view class="status-box">
							<text class="status">退款成功</text>
							<text class="desc">已成功退款</text>
						</view>
					</view>
				</view>
				<!-- 下单人信息 -->
				<view class="order-placer">
					<view class="inner">
						<image class="location" src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/location.png" mode=""></image>
						<view class="info">
							<view class="name-phone">
								<text class="text">{{order.realName}}</text>
								<text class="text" v-if="order.userPhone!=null">{{utils.parsePhone(order.userPhone)}}</text>
							</view>
							<view class="address ellipsis2">
								{{order.userAddress}}
							</view>
						</view>
					</view>
				</view>
				<view class="content">
					<!-- 药品列表 -->
					<view class="goods-list">
						<view   v-if="order.isPackage!=1" v-for="(item,index) in items" :key="index" class="item">
							<view class="img-box">
								<image :src="JSON.parse(item.jsonInfo).image" mode="aspectFill"></image>
							</view>
							<view class="info-box">
								<view>
									<view class="name-box ellipsis2">
										<view v-if="item.isPrescribe==1" class="tag">处方药</view>{{JSON.parse(item.jsonInfo).productName}}
									</view>
									<view class="spec">{{JSON.parse(item.jsonInfo).sku}}</view>
								</view>
								<view class="price-num">
									<view class="price">
										<text class="unit">¥</text>
										<text class="num">{{JSON.parse(item.jsonInfo).price.toFixed(2)}}</text>
									</view>
									<view class="num">x{{JSON.parse(item.jsonInfo).num}}</view>
								</view>
							</view>
						</view>
						<view  v-if="order.isPackage==1&&order.packageJson!=null"   class="item">
							<view class="img-box">
								<image :src="JSON.parse(order.packageJson).imgUrl" mode="aspectFill"></image>
							</view>
							<view class="info-box">
								<view>
									<view class="name-box ellipsis2">
										<view class="tag">套餐</view>{{JSON.parse(order.packageJson).title}}
									</view>
									<view class="spec">{{JSON.parse(order.packageJson).descs}}</view>
								</view>
								 
							</view>
						</view>
						<!-- 已优惠、小计 -->
						<view class="sub-total">
							<view class="discount">
								订单金额：￥{{order.totalPrice}}
							</view>
							<text class="label">实付金额：</text>
							<view class="price">
								<text class="unit">¥</text>
								<text class="num">{{order.payPrice}}</text>
							</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.orderCode}}</text>
								<view class="copy-btn" @click="copyOrderSn(order.orderCode)">复制</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>
						</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.payDelivery!=null">¥{{order.payDelivery.toFixed(2)}}</text>
						</view>
						<view v-if="order.status>0" class="item">
							<text class="label">支付时间</text>
							<text class="text">{{order.payTime}}</text>
						</view>
						<!-- <view v-if="order.status >1" class="item">
							<text class="label">发货时间</text>
							<text class="text"></text>
						</view> -->
						 
					</view>
					<!-- 处方信息 -->
					<view class="order-info" v-if="order.isPrescribe&&prescribe!=null">
						<view class="title">处方信息</view>
						<view class="item">
							<text class="label">处方单号</text>
							<text class="text">{{prescribe.rpId}}</text>
						</view>
						<view class="item">
							<text class="label">开方医生</text>
							<text class="text">{{prescribe.doctorName}}</text>
						</view>
						<view class="item">
							<text class="label">电子处方</text>
							<view class="check-box" @click="showImg()">
								<text class="text">查看</text>
								<image src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/arrow4.png" mode=""></image>
							</view>
						</view>
					</view>
				</view>
				
			</view>
		</view>
		<!-- 按钮 -->
		<view   class="btn-box">
			<view class="btn share-btn" v-if="order.status==0">
				支付分享
				<button  class="share" data-name="shareBtn" open-type="share">分享</button>
			</view>
			<view class="btn share-btn" v-if="order.status==0" @click="openEditMoney()">
				修改定金
			</view>
		</view>
	 
		<view class="popup-box" v-if="editShow">
		  <view class="info-mask"  @tap="cancelEditMoney()" ></view>
		  <view class="info-form"   >
				<view class="title">修改订金</view>
				<view class="form-box">
					<view class="form-item">
						<text class="label">支付金额</text>
						<input type="text" @input="moneyChange()" v-model="payMoney" maxlength="10" placeholder="支付金额" class="form-input" />
					</view>
					<view class="form-item">
						<text class="label">代收金额</text>
						<input type="text" disabled v-model="payDelivery" maxlength="10" placeholder="代收金额" class="form-input" />
					</view>
				</view>
				<view class="btns">
					<view class="sub-btn" @click="confirmEditMoney()">提交</view>
				</view>
		  </view>
		</view>
	</view>
</template>

<script>
	import {getMyStoreOrderById } from '@/api/storeOrder'
	import {editOrderMoney} from '@/api/companyOrder.js'
	export default {
		data() {
			return {
				payMoney:0,
				payDelivery:0,
				editShow:false,
				payLimitTime:null,
				orderId:null,
				order:{},
				items:[],
				prescribe:null,
				// 状态栏的高度
				statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
		 
			};
		},
		onLoad(option) {
			this.orderId = option.id
			this.getMyStoreOrderById()
		},
		onShareAppMessage(res) {
			return {
				title: "订单:"+this.order.orderCode,
				path: `/pages/shopping/paymentOrder?orderId=${this.order.id}`,
			}
		},
		methods: {
			moneyChange(){
				this.payDelivery=this.order.payPrice-this.payMoney
			},
			openEditMoney(){
				console.log(1)
				this.editShow = true
			},
			cancelEditMoney(){
				this.editShow = false
			},
			confirmEditMoney(){
				if(parseFloat(this.payMoney)>=0){
					var that=this;
					var data={orderId:this.order.id,token:uni.getStorageSync('CompanyUserToken'),money:this.payMoney}
					editOrderMoney(data).then(
						res => {
							if(res.code==200){
								this.editShow = false
								this.getMyStoreOrderById();
							}else{
								uni.showToast({
									icon:'none',
									title: res.msg,
								});
							}
						},
						rej => {}
					);
					
				}
				else{
					uni.showToast({
						icon:'none',
						title: "支付金额应大于等于0",
					});
				}
			},
			showImg(){
				var imgArr = [];
				imgArr.push(this.prescribe.rpUrl)
				//预览图片
				uni.previewImage({
					urls: imgArr,
					current: imgArr[0]
				});
			},
			getMyStoreOrderById(){
				var data={orderId:this.orderId};
				getMyStoreOrderById(data).then(res => {
					if(res.code==200){
						 this.order=res.order;
						 this.items=res.items;
						 this.payLimitTime=res.payLimitTime;
						 this.prescribe=res.prescribe;
						 this.payMoney=this.order.payMoney;
						 this.payDelivery=this.order.payDelivery
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						 
					}
				});
			},
			express(){
				uni.navigateTo({
					url: './storeOrderDelivery?orderId='+this.order.orderId
				})
			},
			 
			// 返回上一页
			back() {
				uni.navigateBack()
			},
			// 复制订单编号
			copyOrderSn(text) {
				// 复制方法
				uni.setClipboardData({
					data:text,
					success:()=>{
						uni.showToast({
							title:'内容已成功复制到剪切板',
							icon:'none'
						})
					}
				});
			},
			 
		}
	}
</script>

<style lang="scss">
	.fixed-top-box{
		width: 100%;
		background: linear-gradient(135deg, #66b2ef 0%, #2BC7B9 100%);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 1000;
	}
	.top-cont{
		width: 100%;
		height: 476upx;
		position: relative;
		.bg{
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 1;
		}
		.top-inner{
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 2;
			.back-box{
				height: 88upx;
				padding-left: 22upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 20upx;
				image{
					width: 40upx;
					height: 40upx;
				}
				.title{
					font-size: 36upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}
			}
			.order-status{
				margin-top: 60upx;
				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;
						}
					}
				}
			}
			.order-placer{
				margin-top: 50upx;
				padding: 0 20upx;
				.inner{
					box-sizing: border-box;
					border-radius: 16upx;
					height: 150upx;
					padding: 40upx 30upx;
					display: flex;
					align-items: center;
					background: #FFFFFF;
					.location{
						width: 24upx;
						height: 27upx;
						margin-right: 18upx;
						flex-shrink: 0;
					}
					.info{
						.name-phone{
							display: flex;
							align-items: center;
							.text{
								font-size: 28upx;
								font-family: PingFang SC;
								font-weight: bold;
								color: #333333;
								line-height: 1;
								margin-right: 20upx;
								&:last-child{
									margin-right: 0;
								}
							}
						}
						.address{
							font-size: 26upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #999999;
							line-height: 1.3;
							margin-top: 10upx;
						}
					}
				}
				
			}
		}
	}
	.content{
		margin: 20rpx 0rpx;
		padding: 0 20upx 140rpx 20upx;
		.goods-list{
			padding: 0 30upx;
			background-color: #FFFFFF;
			border-radius: 16upx;
			.item{
				padding: 30upx 0;
				border-bottom: 1px solid #EDEEEF;
				display: flex;
				align-items: center;
				.img-box{
					width: 160upx;
					height: 160upx;
					margin-right: 30upx;
					image{
						width: 100%;
						height: 100%;
					}
				}
				.info-box{
					width: calc(100% - 190upx);
					height: 160upx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					.name-box{
						font-size: 28upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #111111;
						line-height: 40upx;
						.tag{
							display: inline-block;
							padding: 0 6upx;
							height: 30upx;
							background: linear-gradient(90deg, #66b2ef 0%, #2BC7B9 100%);
							border-radius: 4upx;
							margin-right: 10upx;
							font-size: 22upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #FFFFFF;
							line-height: 30upx;
							float: left;
							margin-top: 7upx;
						}
					}
					.spec{
						margin-top: 18upx;
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
						line-height: 1;
					}
					.price-num{
						display: flex;
						align-items: center;
						justify-content: space-between;
						.price{
							display: flex;
							align-items: flex-end;
							.unit{
								font-size: 24upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #111111;
								line-height: 1.2;
								margin-right: 4upx;
							}
							.num{
								font-size: 32upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #111111;
								line-height: 1;
							}
						}
						.num{
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #999999;
							line-height: 1;
						}
					}
				}
			}
			.sub-total{
				height: 88upx;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				.discount{
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 1;
					margin-right: 30upx;
				}
				.label{
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
				.price{
					display: flex;
					align-items: flex-end;
					.unit{
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #FF6633;
						line-height: 1.2;
						margin-right: 4upx;
					}
					.num{
						font-size: 32upx;
						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;
					}
				}
				.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;
			&.share-btn{
				background: #2BC7B9;
				color: #FFFFFF;
				position: relative;
				.share{
					display: inline-block;
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					height: 100%rpx;
					opacity: 0;
				}
				
			}
		}
	}
	.popup-box{
		position: fixed;
		top: 0;
		right: 0;
		left: 0;
		bottom: 0;
		z-index: 999;
		display: flex;
		justify-content: center;
		align-items: center;
		.info-mask {
			position: fixed;
			top: 0;
			right: 0;
			bottom: 0;
			left: 0;
			background-color: rgba($color: #000000, $alpha: 0.5);
			z-index: 999;
		}
		.info-form {
			z-index: 1000;
			width: 650rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			padding: 0 30upx;
			background: #FFFFFF;
			border-radius: 16upx;
			.title{
				padding: 30rpx 0rpx 15rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 40upx;
				line-height: 44upx;
				font-family: PingFang SC;
				color: #222222;
			}
			.form-box{
				width: 100%;
				.form-item{
					padding: 30upx 0;
					display: flex;
					align-items: flex-start;
					border-bottom: 1px solid #F1F1F1;
					.label{
						width: 160upx;
						text-align: left;
						font-size: 30upx;
						line-height: 44upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #222222;
						flex-shrink: 0;
					}
					input{
						text-align: left;
					}
					.form-input{
						font-size: 34upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #222222;
						text-align: left;
					}
					 
				}
			}
			.btns{
				width: 100%;
				height: 120upx;
				padding: 0 30upx;
				display: flex;
				align-items: center;
				justify-content: center;
				.sub-btn{
					width: 100%;
					height: 88upx;
					line-height: 88upx;
					text-align: center;
					font-size: 30upx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #FFFFFF;
					background: #2BC7B9;
					border-radius: 44upx;
				}
			}
			
		}
	}
</style>
