<template>
	<view class="page">
		<u-navbar title="订单详情" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='45'  back-icon-color='#000'></u-navbar>
		
		<view class="jiaoyi">
			<view class="pic">
				<image src="https://api.ccttiot.com/smartmeter/img/static/uiXte3LpSV30jyvTUR2R" mode=""></image> 
				<text v-if="info.status == 'PROCESSING'">进行中</text>
				<text v-if="info.status == 'WAIT_PAY'">待支付</text>
				<text v-if="info.status == 'CANCELED'">已取消</text>
				<text v-if="info.status == 'FINISHED'">交易完成</text>
				<text v-if="info.status == 'WAIT_VERIFY'">待审核</text>
			</view>
			<view class="gx">
				<text v-if="info.status == 'PROCESSING'">订单进行中</text>
				<text v-if="info.status == 'WAIT_PAY'">订单待支付</text>
				<text v-if="info.status == 'CANCELED'">订单已取消</text>
				<text v-if="info.status == 'FINISHED'">感谢您的支持，欢迎再次光临</text>
				<text v-if="info.status == 'WAIT_VERIFY'">订单待审核</text>
			</view>
		</view>
		<view class="ordermx">
			<view class="top">
				订单明细
			</view>
			<view class="xuxian">
				<view class="one">
					<view class="qian">
						订单编号
					</view>
					<view class="shen">
						{{info.no == null ? '--' : info.no}} <image src="https://api.ccttiot.com/smartmeter/img/static/uimYURcxkn9ItLquwPpM" mode=""></image>
					</view>
				</view>
				<view class="one">
					<view class="qian">
						下单时间
					</view>
					<view class="shen">
						{{info.createTime == null ? '--' : info.createTime}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						结束时间
					</view>
					<view class="shen">
						{{info.endTime == null ? '--' : info.endTime}}
					</view>
				</view>
			</view>
			<view class="xuxian">
				<view class="one">
					<view class="qian">
						骑行费
					</view>
					<view class="shen">
						{{info.ridingFee == null ? '0.00' : info.ridingFee}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						停车点外调度费
					</view>
					<view class="shen">
						{{info.manageFee == null ? '0.00' : info.manageFee}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						运营区外调度费
					</view>
					<view class="shen">
						{{info.dispatchFee == null ? '0.00' : info.dispatchFee}}元
					</view>
				</view>
			</view>
			<view class="xuxian">
				<view class="one">
					<view class="qian">
						合计
					</view>
					<view class="shen">
						{{info.totalFee == null ? '0.00' : info.totalFee}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						预存金额
					</view>
					<view class="shen">
						{{info.depositFee == null ? '0.00' : info.depositFee}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						退款金额
					</view>
					<view class="shen">
					    {{info.payRefunded == null ? '0.00' : info.payRefunded}}元
					</view>
				</view>
			</view>
			<view class="xuxian" style="border: 0;">
				<view class="one">
					<view class="qian">
						实付金额
					</view>
					<view class="shen">
						<span style="color: #E7612E;font-size: 40rpx;">{{info.payAmount == null ? '0.00' : info.payAmount}}</span>元
					</view>
				</view>
			</view>
		</view>
		<view class="qixing">
			<view class="top">
				骑行信息
			</view>
			<view class="xuxian">
				<view class="one">
					<view class="qian">
						骑行时长                                        
					</view>
					<view class="shen">
						{{ rideDuration == '' ? '--' : rideDuration}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						骑行距离                                                  
					</view>
					<view class="shen">
						{{info.distance > 1000 ? (info.distance / 1000).toFixed(2) + 'km' : info.distance + 'm'}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						运营区                                                  
					</view>
					<view class="shen">
					    {{info.areaName == null ? '--' : info.areaName}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						车牌号                                               
					</view>
					<view class="shen">
					   {{info.deviceVehicleNum == null ? '--' : info.deviceVehicleNum}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						车辆编号（SN）                                 
					</view>
					<view class="shen">
					   {{info.deviceSn == null ? '--' : info.deviceSn}}
					</view>
				</view>
			</view>
		</view>
		<view class="kefu" @click="btntel">
			联系商家客服
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: "#fff",
				},
				id: 0,
				info: {},
				rideDuration: '' // 新增属性用于存储骑行时间
			}
		},
		onLoad(e) {
			this.id = e.id
			this.orderInfo()
		},
		methods: {
			// 请求订单详情
			orderInfo() {
				this.$u.get("/app/order/mineDetail?id=" + this.id).then((res) => {
					if (res.code == 200) {
						this.info = res.data
						this.calculateRideDuration() // 计算骑行时间
					}
				})
			},
			// 计算骑行时间
			calculateRideDuration() {
				const createTime = new Date(this.info.startTime)
				let returnTime = ''
				if(this.info.endTime == null){
					 returnTime = new Date()
				}else{
					 returnTime = new Date(this.info.endTime)
				}
				console.log(returnTime,'0202020');
				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}秒`
				}
			},
			btntel(){
				if(this.info.areaPhone == null){
					uni.showToast({
						title: '暂无商家客服电话',
						icon: 'none',
						duration:2000
					})
				}else{
					uni.makePhoneCall({
						phoneNumber: this.info.areaPhone,
						success: function(res) {
							console.log('拨打电话成功', res)
						},
						fail: function(err) {
							console.error('拨打电话失败', err)
						}
					})
				}
			}
		}
	}
</script>
<style lang="scss" >
page{
	background-color: #F7FAFE;
}
.page{
	width: 750rpx;
	background: #F7F7F7;
	border-radius: 0rpx 0rpx 0rpx 0rpx;
	padding-bottom: 200rpx;
	box-sizing: border-box;
	.kefu{
		width: 680rpx;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #4C97E7;
		color: #fff;
		font-size: 36rpx;
		font-weight: 600;
		text-align: center;
		position: fixed;
		left: 50%;
		transform: translateX(-50%);
		bottom: 50rpx;
		border-radius: 20rpx;
	}
	.qixing{
		width: 702rpx;
		height: 466rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 0 42rpx;
		box-sizing: border-box;
		margin: auto;
		margin-top: 32rpx;
		.top{
			font-weight: 600;
			font-size: 32rpx;
			color: #3D3D3D;
			padding: 36rpx 0 24rpx 0;
			box-sizing: border-box;
			border-bottom: 1px dashed #D8D8D8;
		}
		.xuxian{
			.one{
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 30rpx;
				.qian{
					color: #808080;
					font-size: 28rpx;
				}
				.shen{
					color: #3D3D3D;
				}
			}
		}
	}
	.ordermx{
		width: 702rpx;
		max-height: 1862rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 0 42rpx;
		box-sizing: border-box;
		margin: auto;
		margin-top: 32rpx;
		.xuxian{
			padding-bottom: 24rpx;
			box-sizing: border-box;
			border-bottom: 1px dashed #D8D8D8;
			.one{
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 30rpx;
				.qian{
					color: #808080;
					font-size: 28rpx;
				}
				.shen{
					color: #3D3D3D;
					image{
						width: 23rpx;
						height: 28rpx;
						vertical-align: baseline;
						margin-left: 10rpx;
					}
				}
			}
		}
		.top{
			font-weight: 600;
			font-size: 32rpx;
			color: #3D3D3D;
			padding: 36rpx 0 24rpx 0;
			box-sizing: border-box;
			border-bottom: 1px dashed #D8D8D8;
		}
		
	}
	.jiaoyi{
		width: 702rpx;
		height: 182rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: auto;
		text-align: center;
		margin-top: 26rpx;
		.pic{
			padding-top: 34rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			image{
				width: 38rpx;
				height: 38rpx;
				margin-right: 10rpx;
			}
			font-weight: 600;
			font-size: 40rpx;
			color: #4C97E7;
		}
		.gx{
			font-size: 28rpx;
			color: #808080;
			margin-top: 20rpx;
		}
	}
}
</style>
