<template>
	<view>
		<u-navbar title="充电详情"></u-navbar>
		<view class="details">
			<view class="details-head">
				<u-icon name="charging-pile-fill" custom-prefix="custom-icon" color="#27B148" size="48"></u-icon>
				<h4 class="oldTextjp" oldstyle="font-size: 20px;">{{chargeDetail.stationName}}</h4>
			</view>
			<view class="details-main">
				<view class="details-price">
					<h3>{{chargeDetail.actualFee != null ? chargeDetail.actualFee : '0.00'}}</h3><span>元</span>
				</view>
				<p :style="elderStatus ? 'font-size: 18px;' : ''">订单总额</p>
			</view>
			<view class="oldTextjp2" oldstyle="font-size: 18px;">
				<view class="details-row"><p>电费</p><span>{{chargeDetail.totalElecMoney != null ? chargeDetail.totalElecMoney : '0.00'}}元</span></view>
				<view class="details-row" v-if="!chargeDetail.discountAmount"><p>服务费</p><span>{{chargeDetail.totalServiceMoney != null ? chargeDetail.totalServiceMoney : '0.00'}}元</span></view>
				
				<view class="details-row" v-if="chargeDetail.discountAmount" ><p>服务费</p><span>{{chargeDetail.totalServiceMoney != null ? chargeDetail.totalServiceMoney-chargeDetail.discountAmount : '0.00'}}元({{chargeDetail.totalServiceMoney}}-{{chargeDetail.discountAmount}})</span></view>
				
				<view class="details-row"><p>优惠券抵扣</p><span style="color:red">{{userCouponObj? userCouponObj.useText : '未使用'}}</span></view>
			</view>
		</view>
		<view class="details">
			<view class="details-title">
				<h4 class="oldTextjp" oldstyle="font-size: 20px;">充电详情</h4>
			</view>
			<view class="oldTextjp2" oldstyle="font-size: 18px;">
				<view class="details-row"><p>消费电量(度)</p><span>{{chargeDetail.electricQuantity != null ? chargeDetail.electricQuantity/10000 : '0.000'}}</span></view>
				<view class="details-row"><p>开始时间</p><span>{{chargeDetail.startTime}}</span></view>
				<view class="details-row"><p>结束时间</p><span>{{chargeDetail.endTime}}</span></view>
				<view class="details-row"><p>充电时长</p><span>{{chargeDetail.chargingMinute != null ? chargeDetail.chargingMinute+'分钟' : '00分00秒'}}</span></view>
			</view>
		</view>
		<view class="details">
			<view class="details-title">
				<h4 class="oldTextjp" oldstyle="font-size: 20px;">更多信息</h4>
			</view>
			<view class="oldTextjp2" oldstyle="font-size: 18px;">
				<view class="details-row"><p>结束原因</p><span>{{chargeDetail.remark}}</span></view>
				<view class="details-row"><p>订单状态</p><span>{{chargeDetail.statusText}}</span></view>
				<view class="details-row"><p>充电桩编号</p><span>{{chargeDetail.deviceNo}}</span></view>
				<view class="details-row"><p>更新时间</p><span>{{chargeDetail.updateTime}}</span></view>
				<view class="details-row"><p>充电车辆</p><span>{{chargeDetail.carNumber}}</span></view>
			</view>
		</view>
		<view class="detailsBtn">
			<u-button class="detailsBtn-btn oldTextjp2" oldstyle="font-size: 16px;" type="primary" shape="circle" plain @click="toHome">返回主页</u-button>
		</view>
	</view>
</template>

<script>
	import * as API from '@/apis/index.js'
	
	export default {
		data() {
			return {
				id: '',
				chargeDetail: {},
				userCouponObj:{},
				elderStatus: false,
			}
		},
		onLoad(op) {
			if(op.id) {
				this.id = op.id;
				this.getchargingDetail();
			}
			
			if(this.carhelp.get("getElderModeClass") == "长辈模式") {
				this.elderStatus = true;
			} else {
				this.elderStatus = false;
			}
		},
		methods: {
			toHome() {
				uni.navigateTo({
					url: '/pages/index/index'
				})
			},
			getchargingDetail() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})		
				API.chargingDetail(this.id).then((res) => {
					uni.hideLoading();
					
					this.chargeDetail = res.data.chargingRecord;
					this.userCouponObj = res.data.userCoupon;
					
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			}
		}
	}
</script>
<style>
	page{
		background-color: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.detailsBtn{
		margin: 16px;
		.detailsBtn-btn{
			border-color:#00B962!important;
			border-radius: 8px!important;
			background: none!important;
			color:#00B962!important;
		}
	}
	.details-title{
		margin-bottom: 16px;
		h4{
			font-weight: normal;
			font-size: 16px;
			position: relative;
			padding-left:10px;
			&::after{
				content: '';
				position: absolute;
				height: 12px;
				width: 4px;
				background-color: #27B148;
				left: 0;
				top:5px;
			}
		}
	}
	.details-row{
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 15px;
		p{color:#888}
	}
	.details{
		margin: 16px;
		padding: 20px;
		background-color: #fff;
		border-radius: 8px;
		.details-head{
			display: flex;
			align-items: center;
			justify-content: center;
			h4{
				font-size: 18px;
				font-weight: normal;
				margin-left: 4px;
			}
		}
		.details-price{
			margin-top: 28px;
			display: flex;
			align-items: flex-end;
			justify-content: center;
			h3{
				font-size: 36px;
				color:#FF6200;
				line-height: 36px;
				margin: 0  4px;
				font-weight: normal;
			}
			span{
				font-size: 20px;
				color:#FF6200;
			}
		}
		.details-main{
			text-align: center;
			margin-bottom: 20px;
			p{
				color:#777;
				margin-top: 4px;
			}
		}
	}
</style>
