<template>
	<view class="page">
		<u-navbar title="费用明细" :border-bottom="false" :background="bgc" title-color='#fff' title-size='36' height='36'></u-navbar>
		<view class="tit">
			<view class="left">电单车</view>
			<!-- <view class="right">查看计费规则 ></view> -->
		</view>
		<view class="data">
			{{info.createTime}}
		</view>
		<view class="card">
			<view class="card_tit">
				账单信息
			</view>
			<view class="cont">
				<view class="cont_box">
					<view class="cont_left">
						预约费
					</view>
					<view class="cont_right">
						{{info.appointmentFee}}元
					</view>
				</view>
				<view class="cont_box" style="margin-top: 20rpx;">
					<view class="cont_left">
						骑行费
					</view>
					<view class="cont_right">
						{{info.ridingFee}}元
					</view>
				</view>
				<view class="cont_box" style="margin-top: 20rpx;">
					<view class="cont_left">
						管理费
					</view>
					<view class="cont_right">
						{{info.manageFee}}元
					</view>
				</view>
				<view class="cont_box" style="margin-top: 20rpx;">
					<view class="cont_left">
						调度费
					</view>
					<view class="cont_right">
						{{info.dispatchFee}}元
					</view>
				</view>
				<view class="tip">
					已骑行{{ rideDuration }}
				</view>
			</view>
			<view class="price">
				<view class="zhanwei"></view>
				<view class="prices">
					共计<span style="font-size:48rpx ;">{{info.totalFee}}</span>元
				</view>
			</view>
		</view>
		<view class="card" v-if="false">
			<view class="card_tit">
				账单信息
			</view>
			<view class="cont">
				<view class="cont_box">
					<view class="cont_left">
						起步价（15分钟）
					</view>
					<view class="cont_right">
						2.00元
					</view>
				</view>
				<view class="tip">
					已骑行30分9秒
				</view>
			</view>
			<view class="price">
				<view class="zhanwei"></view>
				<view class="prices">
					实付 <span style="font-size:48rpx ;">4.00</span>元
				</view>
			</view>
			<view class="price" style="margin-top: 0;">
				<view class="zhanwei"></view>
				<view class="showmore">
					查看支付方式
					<view class="iconfont icon-xiangxia1"></view>
				</view>
			</view>
			<view class="info_cont">
				<view class="info_left">
					微信支付
				</view>
				<view class="info_right">
					2.00元
				</view>
			</view>
			<view class="info_cont">
				<view class="info_left">
					支付时间
				</view>
				<view class="info_right">
					2023-12-31 19:23:59
				</view>
			</view>
			<view class="info_cont">
				<view class="info_left">
					订单号
				</view>
				<view class="info_right">
					3915479812278489
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: "",
				},
				id: 0,
				info: {},
				rideDuration: '' // 新增属性用于存储骑行时间
			}
		},
		onLoad(e) {
			this.id = e.orderId
			if(this.id){
				this.orderInfo()
			}
			
		},
		methods: {
			orderInfo() {
				this.$u.get("/appVerify/order/" + this.id).then((res) => {
					if (res.code == 200) {
						this.info = res.data
						this.calculateRideDuration(); // 计算骑行时间
					}
				});
			},
			calculateRideDuration() {
				const createTime = new Date(this.info.createTime);
				const returnTime = new Date(this.info.returnTime);
				const duration = (returnTime - createTime) / 1000; // 时间差，单位秒

				const hours = Math.floor(duration / 3600);
				const minutes = Math.floor((duration % 3600) / 60);
				const seconds = Math.floor(duration % 60);

				if (hours > 0) {
					this.rideDuration = `${hours}小时${minutes}分${seconds}秒`;
				} else {
					this.rideDuration = `${minutes}分${seconds}秒`;
				}
			}
		}
	}
</script>
