<style>
	.orderDetail {
		background: #f6f6f6;
		font-family: 'oswald';
		padding:0 5px;
		padding-bottom:60px;
		height:100%;
	}

	.orderDetail .orderItem {
		background-color: #fff;
		margin-bottom: 10px;
		padding: 0 15px;
		border-radius: 10px;
	}

	.orderDetail .orderDay {
		display: flex;
		justify-content: space-between;
		padding-top: 20px;
	}

	.orderDetail .order_big {
		font-size: 14px;
		color: #08090E;
		font-weight: bold;
	}

	.orderDetail .order_mini {
		font-size: 11px;
		color: #919191;
		margin-top: 10px;
	}

	.orderDetail .orderCar {
		display: flex;
		justify-content: space-between;
		padding: 30px 0;
	}

	.orderDetail .order_carImg image {
		width: 200rpx;
		height: 130rpx;
	}

	.orderDetail .order_small {
		font-size: 14px;
		color: #919191;
	}

	.orderDetail .order_GName {
		width: 100%;
		height: 50px;
		border-top: 1px solid rgba(0, 0, 0, 0.03);
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.orderDetail .order_dList {
		border-bottom: 1px solid rgba(0, 0, 0, 0.03);
		padding: 20px 0;
	}

	.order_dList:last-child {
		border-bottom: 0;
	}

	.orderDetail .order_comLeft {
		margin-left: 70px;
	}

	.orderDetail .order_Tprice {
		display: flex;
		justify-content: space-between;
	}

	.order_redPrice {
		color: #F20707;
		font-size: 14px;
	}

	.order_Apply,
	.order_Sure {
		width: 50%;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 60px;
	}

	.orderDetail .order_ImgS {
		width: 17px;
		height: 17px;
		margin-right: 5px;
	}

	.orderDetail .order_Line {
		width: 1px;
		height: 40px;
		background-color: #e2e2e2;
	}

	.orderDetail .order_nonBtm {
		border-bottom: 0 !important;
	}

	.orderDetail .btn-box {
		display: flex;
		flex-direction: row-reverse;
		height: 60px;
		padding: 10px 20px;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 2;
		border-top: 1px solid #f5f5f5;
		background: #fff;
		display: flex;
		align-items: center;
	}

	.order_Btn_Com {
		padding: 5px 10px;
		border: 1px solid #888888;
		border-radius: 14px;
		color: #888888;
		font-size: 12px;
		float: right;
		margin-right: 15px;
	}
</style>
<template>
	<view class="orderDetail">
		<template v-if="dataList">
			<view class="orderItem">
				<view class="orderDay">
					<view>
						<template v-if="dataList.DetailList&&dataList.DetailList.length>0">
							<view class="order_big">{{getStart(dataList.DetailList[0].TripSTime)}}</view>
							<view class="order_mini">{{getWeek(dataList.DetailList[0].TripSTime)}}</view>
						</template>
					</view>
					<view style="text-align: center;margin-top:8px;">
						<view style="font-size:13px;color:#1B1D1E;" v-if="dataList.DetailList&&dataList.DetailList.length>0">{{getDays()}}</view>
						<view style="position: relative;top:-8px;">
							<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/dir_arrow.png" mode="aspectFill" style="width: 55px;height: 4px;"></image>
						</view>
					</view>
					<view>
						<template v-if="dataList.DetailList&&dataList.DetailList.length>0">
							<view class="order_big">{{getStart(dataList.DetailList[0].TripETime)}}</view>
							<view class="order_mini">{{getWeek(dataList.DetailList[0].TripETime)}}</view>
						</template>
					</view>
				</view>
				<view class="orderCar">
					<view class="order_carImg">
						<image mode="aspectFit" :src="dataList.DetailList[0].CoverImagePath" />
						</image>
					</view>
					<view style="width:52%">
						<view class="order_big" style="overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-weight: bold;
							width: 100%;">
							{{dataList.DetailList[0].CarBrandName}}
						</view>
						<view class="order_small" style="margin-top:5px;">
							{{dataList.DetailList[0].UseDay==0.5?'半':dataList.DetailList[0].UseDay}}天,
							{{dataList.DetailList[0].CarName}},
							{{dataList.DetailList[0].GuideCarType}},
							{{dataList.DetailList[0].RideNum}}座,
						</view>
						<view class="order_small" style="margin-top:5px;">
						    {{dataList.DetailList[0].CarNumber}},
							{{dataList.DetailList[0].IsSpell==1?'拼座':'不拼座'}},
							{{dataList.DetailList[0].CarColorName}},
							{{dataList.CarTypeStr}}
						</view>
					</view>
					<view style="text-align: right;width:55px;">
						<view class="order_big">¥ {{getPrice()}}</view>
						<view style="color:#727272;font-size:13px;">×{{dataList.DetailList[0].Number}}</view>
					</view>
				</view>
				<view class="order_GName">
					<view class="order_small">匹配导游</view>
					<view style="display: flex;align-items: center;">
						<u-avatar mode="circle" style="margin-top:8px;" :src="dataList.DetailList[0].GuidePhoto" size="60"></u-avatar>
						<text class="order_big" style="margin-left:5px;">{{dataList.DetailList[0].GuideName}}</text>
					</view>
				</view>
			</view>
			<view class="orderItem">
				<view class="order_dList order_Tprice">
					<text class="order_small">订单编号</text>
					<text class="order_big" style="margin-left:20px;">{{dataList.OrderNo}}</text>
				</view>
				<view class="order_dList order_Tprice">
					<text class="order_small">下单时间</text>
					<text class="order_big" style="margin-left:20px;">{{dataList.CreateDate}}</text>
				</view>
				<view class="order_dList order_Tprice">
					<text class="order_small">支付方式</text>
					<text class="order_big" style="margin-left:20px;">{{dataList.PaymentWayName}}</text>
				</view>
			</view>
			<view class="orderItem">
				<view class="order_dList order_Tprice">
					<text class="order_small">商品总额</text>
					<text class="order_big">¥ {{dataList.Income}}</text>
				</view>
				<view class="order_dList order_Tprice">
					<text class="order_small">优惠</text>
					<text class="order_big">¥ {{dataList.CouponMoney}}</text>
				</view>
				<view class="order_dList order_Tprice">
					<text class="order_small">保险费用</text>
					<text class="order_big">¥ {{dataList.DetailList[0].InsuranceMoney}}</text>
				</view>
				<view class="order_dList order_Tprice">
					<text class="order_small">积分使用/抵扣</text>
					<text class="order_big">{{dataList.DetailList[0].IntegralNumber!=null?dataList.DetailList[0].IntegralNumber:'0'}}积分/-¥{{dataList.DetailList[0].IntegralMoney!=null?dataList.DetailList[0].IntegralMoney:'0'}} </text>
				</view>
				<view class="order_dList" style="text-align: right" :class="{'order_nonBtm':dataList.OrderStatus!=3}">
					<text class="order_big">实付款：</text>
					<text class="order_redPrice">¥ {{dataList.Income}}</text>
				</view>
				<view class="btn-box" v-if="dataList.OrderStatus != 5">
					<view class="item" v-if="dataList.OrderStatus == 1">
						<view class="order_Btn_Com" v-on:click.stop="payment(dataList)" style="color:#FF4048;border-color:#FF4048;">立即支付</view>
					</view>
					<view class="item" v-if="dataList.OrderStatus == 1||dataList.OrderStatus==2||dataList.OrderStatus==3">
						<view class="order_Btn_Com" @click="cancel">取消订单</view>
					</view>
				</view>
			</view>
		</template>
		<after-sale :list="dataList.DetailList" v-if="showAfter" @close="closeAfterHandler"></after-sale>
		<u-popup v-model="showModal" mode="center" length="80%">
			<view style='display: flex;flex-direction: column;align-items: center;background: #fff;'>
				<view style="display: flex;align-items: center;justify-content: center;height:70px ;">
					<Text>是否取消订单？</Text>
				</view>
				<view style="display: flex;flex-direction: column;height:80px ;margin-left: 15px;width: 100%;" v-if='dataList.OrderStatus==2'>
					<Text style='margin-left: 10px;margin-top: 5px;'>备注</Text>
					<input class="uni-input inputM" style='margin-left: 10px;margin-top: 5px;' v-model="Cancelmsg.Remark" placeholder="输入备注" />
				</view>
				<view style="display: flex;flex-direction: row;align-items: center;height: 50px;border-top: 1px solid #F5F5F5;width: 100%;">
					<view style="width: 50%;display: flex;align-items: center;justify-content: center" @click="showModal=false">
						<Text>取消</Text>
					</view>
					<view style="width: 50%;color: #a0cfff;display: flex;align-items: center;justify-content: center" @click="confirm">
						<Text>确定</Text>
					</view>
				</view>
			</view>
		</u-popup>
		<payCom v-if="payBtn" :payInfo="payInfo" @closePay="closePay"></payCom>
		<u-popup v-model="payExit" mode="center" :mask-close-able="false">
			<view style="background:#fff;width:500rpx">
				<view style="padding:10px 0 0 10px">提交失败</view>
				<view style="text-align:center;padding-bottom:40rpx">
					<view style="margin:80rpx 0">支付取消</view>
					<span @click="exitPay" style="padding:10rpx 50rpx;color:#fff;background:#19be6b;border-radius: 12px;">确定</span>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import payCom from '@/components/pay/pay';
	import afterSale from "@/components/userorder/after-sale";
	export default {
		components: {
			afterSale,
			payCom
		},
		data() {
			return {
				pageTitle: '订单详情',
				mainColor: '',
				msg: {
					OrderId: 0,
					NewUserId: 0
				},
				dataList: {},
				showAfter: false,
				themCustomStyle: {
					marginLeft: "20px",
					padding: "0 2rpx",
					color: "#FFF",
				},
				showModal: false,
				Cancelmsg: {
					OrderId: 0,
					Type: 1,
					Remark: '',
				},
				payInfo: {
					OpenId: 'ow_7I5XC1-RGwwk8QANBmWKYKmOc',
					OrderId: '',
					OrderPayType: 1,
					GoodsName: ''
				},
				payBtn: false,
				payExit: false
			}
		},
		created() {
			this.mainColor = this.$uiConfig.mainColor;
		},
		mounted() {
			let currentPages = getCurrentPages();
			let u = "/" + currentPages[currentPages.length - 1].route;
			let pages = wx.getStorageSync("basedata") ?
				wx.getStorageSync("basedata").bar_title : [];
			pages.forEach((x) => {
				if (x.value == u) {
					this.pageTitle = x.new_name ? x.new_name : x.name;
				}
			});
			uni.setNavigationBarTitle({
				title: this.pageTitle,
			});
		},
		onLoad(option) {
			this.u = uni.getStorageSync("mall_UserInfo");
			this.msg.OrderId = option.OrderId;
			this.payInfo.OpenId = uni.getStorageSync('mall_UserInfo').OpenId;
			this.getData();
		},
		methods: {
			//获取数据
			getData() {
				this.request2({
						url: "/api/AppletGCOrder/GetAppletGuidecarOrderOrderInfo",
						data: this.msg,
					},
					(res) => {
						if (res.resultCode == 1) {
							this.dataList = res.data;
						}
					}
				);
			},
			//获取价格
			getPrice() {
				if (this.dataList.DetailList && this.dataList.DetailList.length > 0) {
					var price = 0;
					var p1 = this.dataList.DetailList[0].Final_Price;
					var number = this.dataList.DetailList[0].Number;
					price = (p1 / number).toFixed(2);
					return price;
				}
			},
			//获取日期
			getStart(data) {
				if (data) {
					var data = data;
					var year = data.split(' ')[0];
					var days = year.split('-');
					return days[1] + '月' + days[2] + '日';
				}
			},
			//获取周几
			getWeek(data) {
				if (data) {
					var data = data;
					var weekArray = new Array("日", "一", "二", "三", "四", "五", "六");
					var year = data.split(' ')[0];
					var b = new Date(Date.parse(year.replace(/\-/g, "/")));
					var days = b.getDay();
					var days = weekArray[days];
					var time = data.split(' ')[1];
					var time2 = time.split(':');
					return '周' + days + ' ' + time2[0] + ':' + time2[1];
				}
			},
			//计算天数
			getDays() {
				let startTime = new Date(this.dataList.DetailList[0].TripSTime);
				let endTime = new Date(this.dataList.DetailList[0].TripETime);

				let usedTime = endTime - startTime; // 相差的毫秒数
				let days = Math.floor(usedTime / (24 * 3600 * 1000)); // 计算出天数
				let leavel = usedTime % (24 * 3600 * 1000); // 计算天数后剩余的时间
				let hours = Math.floor(leavel / (3600 * 1000)); // 计算剩余的小时数
				let Str = '';
				if (days > 0) {
					if (leavel > 0) {
						Str = days + 1 + ' ' + '天'
					} else {
						Str = days + ' ' + '天'
					}
				} else {
					if (hours >= 6) {
						Str = 1 + ' ' + '天'
					} else {
						Str = '半天'
					}
				}
				return Str;
			},
			closeAfterHandler() {
				this.showAfter = false;
			},
			//取消订单
			cancel() {
				this.showModal = true;
				this.Cancelmsg.OrderId = this.dataList.OrderId;
				this.Cancelmsg.Type = this.dataList.OrderStatus;
				this.Cancelmsg.Remark = ''
			},
			confirm() {
				let that = this
				if (that.Cancelmsg.Type == 2 && that.Cancelmsg.Remark == '') {
					uni.showToast({
						title: '备注不能为空',
						icon: 'none'
					})
					return
				}
				let pages = getCurrentPages(); // 当前页面
				uni.requestSubscribeMessage({ //订阅消息 退款和审核通知
					tmplIds: that.dataList.template_message_list,
					complete(res) {
						that.request2({
								url: '/api/AppletOrder/CancelAppletGoodsOrderInfo',
								data: that.Cancelmsg
							},
							(res) => {
								that.showModal = false;
								uni.showToast({
									title: res.message,
									icon: 'none'
								})
								uni.redirectTo({
									url: "/pages/guidecar/orderList?status=1",
								});

							}
						);
					}
				})
			},
			//支付
			payment(e) {
				this.payInfo.OrderId = e.OrderId;
				this.payInfo.GoodsName = e.DetailList[0].GoodsName.slice(0, 10);
				this.payInfo.PaymentWay = e.PaymentWay;
				this.payInfo.total_price = e.Income;
				this.payBtn = true
			},
			closePay() {
				this.payBtn = false;
				this.payExit = true;
			},
			exitPay() {
				this.payExit = false;
			},
		}
	}
</script>
