<template>
	<view>
		<u-navbar :title="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>{{detail.stationName}}/{{detail.deviceNo}}</h4>
			</view>
			<view class="details-main">
				<view class="details-price">
					<span>￥</span><h3>{{iswuye?detail.costAmount:detail.shareProfitAmount}}</h3><span>元</span>
				</view>
				<p>本单收益</p>
			</view>
			<view class="details-row" v-if="!iswuye" ><p>电费(元)</p><span>￥{{detail.costAmount}}</span></view>
			<view class="details-row" v-if="!iswuye"><p>服务费(元)</p><span>￥{{detail.surplusAmount}}</span></view>
			<view class="details-row" v-if="!iswuye"><p>桩号</p><span>{{detail.deviceNo}}</span></view>
			<view class="details-row" v-if="!iswuye"><p>分润标准</p><span>{{detail.disProportion}}%</span></view>
		</view>
		<view class="details">
			<view class="details-title">
				<h4>充电详情</h4>
			</view>
			<view class="details-row"><p>消费电量(kW-h)</p><span>{{detail.electricQuantity/10000}}</span></view>
			<view class="details-row"><p>开始时间</p><span>{{detail.startTime}}</span></view>
			<view class="details-row"><p>结束时间</p><span>{{detail.endTime}}</span></view>
			<view class="details-row"><p>充电时长</p><span>{{getPercent(detail.chargingMinute)}}</span></view>
		</view>
		<view class="detailsBtn">
			<u-button class="detailsBtn-btn" @click="back" type="primary" plain>返回</u-button>
		</view>
	</view>
</template>

<script>
	import * as API from '@/apis/finance.js'
	
	export default {
		data() {
			return {
				id:'',
				
				detail:{
					
				},
				title:"",
				iswuye:false
			}
		},
		onLoad(op){
			
			this.title="收益详情"
			var obj=this.carhelp.getPersonInfoPlus("merchantUser");
			if(obj&&obj.role){
				var  role=obj.role;
				if(role.id=="4"){
					this.title="电费详情"
					this.iswuye=true;
				}
			}
			
			this.id=op.id;
			this.getInfo()
		},
		methods: {
			getPercent(estimateMinute) {
				var value="";
				 
				var ms =estimateMinute
				if (ms > 0) {
					var Hour = parseInt(Math.floor(ms / 60 ));
					var Fen = parseInt(Math.floor(ms % 60 ));	
					value = Hour + "小时"  + Fen+"分钟"
				}
			
				return value;
			},
			back(){
				uni.navigateBack({
					
				})
			},
			getInfo(){
				uni.showLoading({
					title:"加载中",mask:true,
				})
				API.incomeDetails({
					detailId:this.id
				}).then((res) => {
					this.detail=res.data.detail	 
					
					uni.hideLoading()
					 
				}).catch(error => {
						uni.showToast({
							
							title:error
						})
				})
			}
		}
	}
</script>
<style>
	page{
		background-color: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.detailsBtn{
		margin: 16px;
		.detailsBtn-btn{
			border-color:#185AC6!important;
			border-radius: 8px!important;
			background: none!important;
			color:#185AC6!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:#27B148;
				line-height: 36px;
				margin: 0  4px;
				font-weight: normal;
			}
			span{
				font-size: 20px;
				color:#27B148;
			}
		}
		.details-main{
			text-align: center;
			margin-bottom: 20px;
			p{
				color:#777;
				margin-top: 4px;
			}
		}
	}
</style>
