<template>
	<view>
		<ujp-navbar title="预约单详情" :custom-back="customback" >

		</ujp-navbar>
		
		<u-alert-tips type="warning" v-if="detail.status==0"  :description="description"></u-alert-tips>
		<view class="reverse-time">
			<view class="time">
				预留30分钟
			</view>
			<view class="details-item">
				<view class="item">
					<view class="item-name">
						预约单号
					</view>
					<view class="item-content">
						0000111122223333
					</view>
				</view>
				<view class="item">
					<view class="item-name">
						预计开始充电
					</view>
					<view class="item-content">

						2022-05-31 09:30:00

					</view>
				</view>
				<view class="item">
					<view class="item-name">
						预计充电时长
					</view>
					<view class="item-content">
						6小时
					</view>
				</view>
			</view>

		</view>
		<!-- 充电桩详情 -->
		<view class="charge-pile">
			<view class="box" @click="gotoUrl('pages/searchPile/stationAndPile/stationDetails?id=3865b3a3-13fd-461a-8145-ee9711df35a2')">
				<view class="name">
					荆鹏软件园充电站/1号快充桩
				</view>
				<view class="address">
					湖北省荆州市沙市区江津东路附155号
				</view>
				<text class="iconfont more">
					&#xe600;
				</text>
			</view>

		<!-- 	<view class="tel">
				<view class="tel-text">
					联系电话
				</view>
				<view class="tel-num">
					李先生 15100001111
					<text class="iconfont more2">
						&#xe600;
					</text>
				</view>
			</view> -->
			<view class="details-item">
				<view class="item">
					<view class="item-name">
						预约单生成时间

					</view>
					<view class="item-content">
						2022-05-31 09:00:00

					</view>
				</view>
				<view class="item">
					<view class="item-name">

						电费单价

					</view>
					<view class="item-content">
						1.00元/度
					</view>
				</view>
				<view class="item">
					<view class="item-name">

						充电服务费 
					</view>
					<view class="item-content">
						1.00元/度
					</view>
				</view>
			</view>
		</view>

		<!-- 底部按钮 -->
		<view class="bottom" v-if="false">
			<u-button shape='circle' class="refuse-btn">拒绝</u-button>
			<u-button type="success" shape='circle'>确认</u-button>
			
		</view>
	</view>
</template>

<script>
	import * as API from '@/apis/apointment.js'
	
	import {
		newDate,
		hourDistanceArr,
		currentTimeStamp,
		parseUnixTime
	} from '@/utils'
	export default {
		data() {
			return {
				isback:false,
				detail:{},
				price:{},
				chargingDevice:{},
				description: '等待桩主确认预约单，剩余时间04:59:59'
			}
			
		},onLoad(op) {
			//预约充电跳转过来则 返回首页
			if(op.isback){
				this.isback=true
			}
			if(op.qr){
				//扫码进入的
			}
			this.id= op.id;
			this.getInfo()
		},
		methods:{
			getInfo(bl){
				//(bl)
				if(!bl){
					uni.showLoading({
						title: "加载中",
						mask: true,
					})	
				}
				
				API.myAppointmentDetail({
					id:this.id,			
				
				}).then((res) => {
					if(!bl){
						uni.hideLoading()
					}
					this.detail= res.data.chargingAppointment;
					this.chargingDevice=res.data.chargingDevice;
					this.price=res.data.price;
					
					if(this.detail.status=="0"){
						//this.description= '等待桩主确认预约单，剩余时间'
						var data=newDate(this.detail.createTime).getTime()
						var c=hourDistanceArr(new Date(),new Date(data+5*60*1000))
					
						this.description= '等待桩主确认预约单，剩余时间'+c[1]+'分'+c[2]+"秒";		
						
						
						setTimeout(()=>{
							this.getInfo(true);
						},1000)
					}
					
				}).catch(error => {
					uni.showToast({
						title: error
					})
				})
				
			},
			customback(){
				if(this.isback){
					uni.reLaunch({
						url:"/pages/index/index"
					})
				}else{
					uni.navigateBack({
						
					})
				}
				
			},
		}
		
	}
</script>

<style lang="scss" scoped>
	page{
		padding-bottom: 151px;
	}
	.tittle-font {

		font-size: 24px;
		position: fixed;
		top: 12px;
		right: 16px;
		z-index: 99999;

	}

	::v-deep .u-alert-desc {
		width: 100vw;
		text-align: center;
		color: #ff5a00;
	}

	.reverse-time {
		background-color: #fff;
		padding: 36px 12px 16px 28px;

		.time {
			height: 36px;
			color: rgba(0, 185, 98, 100);
			font-size: 36px;
			text-align: center;
		}

	}

	.details-item {
		margin-top: 32px;
		padding-right: 16px;
		padding-bottom: 12px;

		.item {
			display: flex;
			justify-content: space-between;
			margin-top: 8px;
		}
	}

	// 充电桩详情
	.charge-pile {
		background-color: #fff;
		margin-top: 12px;
		padding: 0 0 12px 16px;

		.box {
			position: relative;
			height: 66px;
			padding: 12px 0;

			.more {
				position: absolute;
				top: 19px;
				right: 12px;
				font-size: 24px;
				color: #b3b3b3;
			}
		}

		.name {
			line-height: 18px;
			color: rgba(16, 16, 16, 100);
			font-size: 18px;
			font-weight: 600;
		}

		.address {
			line-height: 20px;
			color: rgba(51, 51, 51, 100);
			margin-top: 4px;
		}

		// 联系电话
		.tel {
			line-height: 48px;
			display: flex;
			justify-content: space-between;
			border: 1px solid #eef2f0;
			border-left: none;
			position: relative;

			.tel-num {
				width: 50%;
			}

			.more2 {
				display: inline-block;
				font-size: 24px;
				color: #b3b3b3;
				height: 48px;
				position: absolute;
				top: 1px;
				right: 12px;

			}
		}

		.item {
			margin-top: 20px;
		}
	}


// 按钮
.bottom{
	width: 100%;
	height: 56px;
	position: fixed;
	bottom: 0;
	background-color: #fff;
	display: flex;
	.refuse-btn{
		background-color: #DBDBDB;
	}
	.u-btn{
		width: 44%;
		height: 40px;
		margin: auto;
		font-size: 18px;
		
	}
}
</style>
