<template>
	<view class="page" v-if="loading">
		<u-navbar title="财务报表" :border-bottom="false" :background="bgc" title-color='#000' title-size='36'
			height='45'></u-navbar>
		<view class="top_box">
			<view class="left_text">
				时间范围
			</view>
			<view class="timebox">
				<view class="left_time" @click="time1=true">
					{{firsTime}}
				</view>
				-
				<view class="right_time" @click="time2=true">
					{{lasTime}}
				</view>
			</view>
		</view>
		<view class="data_box">
			<view class="data_cont " :class="cutidx==0?'act1':''" @click="changeTime(0)">
				今日
			</view>
			<view class="data_cont" :class="cutidx==1?'act1':''" @click="changeTime(1)">
				昨日
			</view>
			<view class="data_cont" :class="cutidx==2?'act1':''" @click="changeTime(2)">
				本月
			</view>
			<view class="data_cont" :class="cutidx==3?'act1':''" @click="changeTime(3)">
				上个月
			</view>
		</view>
		
		<view class="cont_box">
			<view class="info_top">
				<view class="txt1">
					库存现金余额 
					<!-- <image src="https://lxnapi.ccttiot.com/bike/img/static/uJFB9IlTZQG31V17R5Pn" mode=""></image> -->
				</view>
				<view class="lines" style="margin-top: 14rpx;"></view>
				<view class="txt2">
					¥{{info.income.accountSurplus}}
				</view>
				
			<!-- 	<view class="txt_box">
					<view class="txt_box_li">
						<view class="txttop">
							净利润
						</view>
						<view class="txtbot">
							¥{{info.accountSurplus}}
						</view>
					</view>
					<view class="txt_box_li">
						<view class="txttop">
							应退押金余额
						</view>
						<view class="txtbot">
							¥1235.00
						</view>
					</view>
				</view> -->
			</view>
			<view class="tit">
				订单明细
			</view>
			<view class="box2">
				<view class="box2_li">
					<view class="box2_txt1">
						主营业务收入
						 <!-- <image src="https://lxnapi.ccttiot.com/bike/img/static/uJFB9IlTZQG31V17R5Pn" mode=""></image> -->
					</view>
					<view class="box2_txt2" >
						¥{{info.income.orderPaid }}
					</view>
					<view class="box2_txt3">
						订单收入:{{info.income.orderPaid }}
					</view>
				</view>
				<view class="line1"></view>
				<view class="box2_li " style="margin-left: 20rpx;">
					<view class="box2_txt1">
						主营业务成本
						 <!-- <image src="https://lxnapi.ccttiot.com/bike/img/static/uJFB9IlTZQG31V17R5Pn" mode=""></image> -->
					</view>
					<view class="box2_txt2">
						¥{{info.income.businessCost}}
					</view>
					<view class="box2_txt3">
						订单退款:{{info.income.orderRefund}}
					</view>
					<view class="box2_txt3">
						订单支付手续费:{{info.income.handlingFee}}
					</view>
					
				</view>
			</view>
			<view class="tit2">
				净利润
				 <!-- <image src="https://lxnapi.ccttiot.com/bike/img/static/uJFB9IlTZQG31V17R5Pn" mode=""></image> -->
			</view>
			<view class="money">
				¥ {{info.income.operatingIncome }}
			</view>
			<view class="tit">
				押金明细
			</view>
			<view class="box3">
				<view class="box3_txt1">
					押金收入:{{info.income.depositPaid }}
				</view>
				<view class="box3_txt1">
					押金抵扣转订单收入:{{info.income.deductionAmount }}
				</view>
				<view class="box3_txt1">
					押金支出:{{info.income.depositRefund }}
				</view>
				<view class="box3_txt1">
					押金收入手续费:{{info.income.depositHandlingCharge  }}
				</view>
				
			</view>
			<view class="tit2">
				应退押金余额 
				<!-- <image src="https://lxnapi.ccttiot.com/bike/img/static/uJFB9IlTZQG31V17R5Pn" mode=""></image> -->
			</view>
			<view class="money">
				¥{{info.income.depositBalance}}
			</view>
		</view>
		
	
			
		<u-picker mode="time" v-model="time1" :params="params" @confirm="confirm1" :default-time='firsTime'></u-picker>
		<u-picker mode="time" v-model="time2" :params="params" @confirm="confirm2" :default-time='lasTime'></u-picker>
		<u-mask :show="showtips" :z-index='100' />
		<view class="tip_box1" v-if="showtips">
			<image class="close" src="https://lxnapi.ccttiot.com/bike/img/static/uyRmNa7d2WThHjr1Jzqk" mode="" @click="showtips=false"></image>
			<view class="top1">
				<view class="tip">
					{{tiptit}}
				</view>
		
				<view class="txt" v-html="tiptxt">
					<!-- {{tiptxt}} -->
				</view>
			</view>
			<!-- <view class="bot1">
				
				<view class="bot_right" @click="showtips=false">
					确定
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: "#fff",
				},
				time1: false,
				time2: false,
				lasTime: '',
				firsTime: '',
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				cutidx: 0,
				info: {},
				areaId: 0,
				loading:false,
				showtips:false,
				tiptxt:'',
				tiptit:''
			}
		},
		onLoad() {
			let today = new Date();
			// 获取七天前的日期

			// 格式化日期为 yyyy-MM-dd
			this.firsTime = this.formatDate(today);
			this.lasTime = this.formatDate(today);
			if (uni.getStorageSync('adminAreaid')) {
				this.areaId = uni.getStorageSync('adminAreaid')
				this.operatingData()
			}

		},
		methods: {
			showtipss(num){
				if(num==1){
					this.tiptxt='该时间段骑车实际利润'
					this.tiptit='营业收入'
				}else if(num==2){
					this.tiptxt='该时间段押金余额'
					this.tiptit='押金余额'
				}else if(num==3){
					this.tiptxt='该时间段账户盈余<br/>总流水减去总支出'
					this.tiptit='账户盈余'
					
				}
				this.showtips=true
			},
			displayAmount(amount) {
				return amount ? amount : '--';
			},
			changeTime(num) {
				if (num == 0) {
					this.cutidx = num;
					let today = new Date();
					this.firsTime = this.formatDate(today);
					this.lasTime = this.formatDate(today);
					this.operatingData()
				} else if (num == 1) {
					this.cutidx = num;
					let yesterday = new Date();
					yesterday.setDate(yesterday.getDate() - 1);
					this.firsTime = this.formatDate(yesterday);
					this.lasTime =this.formatDate(yesterday);
					this.operatingData()
				} else if (num == 2) {
					this.cutidx = num;
					let today = new Date();
					let firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
					this.firsTime = this.formatDate(firstDayOfMonth);
					this.lasTime = this.formatDate(new Date());
					this.operatingData()
				} else if (num == 3) {
					this.cutidx = num;
					let today = new Date();
					let firstDayOfLastMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1);
					let lastDayOfLastMonth = new Date(today.getFullYear(), today.getMonth(), 0);
					this.firsTime = this.formatDate(firstDayOfLastMonth);
					this.lasTime = this.formatDate(lastDayOfLastMonth);
					this.operatingData()
				}
			},
			formatDate(date) {
				let year = date.getFullYear();
				let month = String(date.getMonth() + 1).padStart(2, '0');
				let day = String(date.getDate()).padStart(2, '0');
				return `${year}-${month}-${day}`;
			},
			operatingData() {
				let data = {
					timeStart: this.firsTime,
					timeEnd: this.lasTime,
					areaId: this.areaId
				}
				this.$u.get('/appVerify/operatingData2', data).then((res) => {
					if (res.code === 200) {
						// 处理接口返回的数据,将边界数据转换为地图组件需要的折线结构
						this.info = res.data
						this.loading=true
					}
				}).catch(error => {
					console.error("Error fetching area data:", error);
				});
			},
			confirm1(e) {

				this.firsTime = e.year + '-' + e.month + '-' + e.day
				this.cutidx = -1
				this.operatingData()
			},
			confirm2(e) {
				this.lasTime = e.year + '-' + e.month + '-' + e.day
				this.cutidx = -1
				this.operatingData()
			},
		}

	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.page {
		width: 750rpx;
		
		.cont_box{
			margin-top: 38rpx;
			padding: 34rpx;
			border-radius: 40rpx 40rpx 0 0;
			background: #FFFFFF;
			box-shadow: 0rpx 4rpx 22rpx 0rpx rgba(0,0,0,0.2);
			.box3{
				margin-top: 28rpx;
				padding: 32rpx 20rpx;
				background: #F0F0F0;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				.box3_txt1{
					width: 100%;
					margin-bottom: 14rpx;
					font-weight: 400;
					font-size: 30rpx;
					color: #3D3D3D;
				}
				.box3_txt2{
					width: 100%;
					font-weight: 500;
					font-size: 30rpx;
					color: #4C97E7;
				}
			}
			.money{
				margin-left: 20rpx;
				margin-top: 12rpx;
				font-weight: 500;
				font-size: 40rpx;
				color: #4C97E7;
			}
			.tit2{
				margin-left: 20rpx;
				margin-top: 26rpx;
				width: 100%;
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				font-weight: 500;
				font-size: 32rpx;
				color: #3D3D3D;
				image{
					margin-left: 24rpx;
					width: 32rpx;
					height: 32rpx;
				}
			}
			.box2{
				margin-top: 28rpx;
				width: 100%;
				padding: 30rpx 20rpx;
				background: #F0F0F0;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				display: flex;
				flex-wrap: nowrap;
				// align-items: center;
				
				.box2_li{
					// display: flex;
					// flex-wrap: wrap;
					// align-items: flex-start;
					width: 49%;
					.box2_txt1{
						width: 100%;
						display: flex;
						flex-wrap: nowrap;
						align-items: center;
						font-weight: 500;
						font-size: 32rpx;
						color: #3D3D3D;
						image{
							margin-left: 24rpx;
							width: 32rpx;
							height: 32rpx;
						}
					}
					.box2_txt2{
						margin-top: 12rpx;
						font-weight: 500;
						font-size: 40rpx;
						color: #4C97E7;
					
					}
					.box2_txt3{
						margin-top: 10rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #3D3D3D;
					}
					
				}
				.line1{
					width: 1rpx;
					height: 200rpx;
					background: #bbb;
				}
			}
			
			.tit{
				margin-top: 50rpx;
				margin-left: 20rpx;
				font-weight: 500;
				font-size: 40rpx;
				color: #3D3D3D;
			}
			.info_top{
				width: 100%;
				padding: 22rpx;
				background: linear-gradient( 90deg, #4C97E7 0%, #92C6FD 100%);
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				.txt1{
					width: 100%;
					display: flex;
					flex-wrap: nowrap;
					align-items: center;
					font-weight: 500;
					font-size: 40rpx;
					color: #FFFFFF;
					image{
						margin-left: 24rpx;
						width: 32rpx;
						height: 32rpx;
					}
				}
				.txt2{
					margin-top: 6rpx;
					font-weight: 600;
					font-size: 48rpx;
					color: #FFFFFF;
				}
				.txt_box{
					margin-top: 20rpx;
					display: flex;
					flex-wrap: nowrap;
					align-items: center;
					.txt_box_li{
						width: 50%;
						.txttop{
							width: 100%;
							font-weight: 500;
							font-size: 32rpx;
							color: #FFFFFF;
						}
						.txtbot{
							margin-top: 8rpx;
							font-weight: 500;
							font-size: 42rpx;
							color: #FFFFFF;
						}
					}
				}
				.lines{
					width: 632rpx;
					height: 1rpx;
					background-color: #FFFFFF;
				}
			}
		}
		.tip_box1 {
			position: fixed;
			left: 72rpx;
			top: 628rpx;
			width: 610rpx;
			// height: 282rpx;
			background: #FFFFFF;
			border-radius: 30rpx 30rpx 30rpx 30rpx;
			z-index: 110;
			padding-bottom: 10rpx;
			.close{
				position: absolute;
				width: 60rpx;
				height: 60rpx;
				bottom: -98rpx;
				left: 274rpx;
			}
			.top1 {
				padding: 52rpx 38rpx 42rpx 36rpx;
		
				.ipt_box {
					margin-top: 22rpx;
					display: flex;
					flex-wrap: nowrap;
					align-items: center;
		
					.text {
						width: 350rpx;
						font-weight: 400;
						font-size: 32rpx;
						color: #3D3D3D;
					}
		
					.ipt {
						padding: 10rpx 18rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-left: 26rpx;
						width: 420rpx;
						height: 64rpx;
						border-radius: 0rpx 0rpx 0rpx 0rpx;
						border: 2rpx solid #979797;
		
						.input {
							width: 80%;
						}
					}
				}
		
				.tip {
					width: 100%;
					text-align: center;
					font-weight: 700;
					font-size: 32rpx;
					color: #3D3D3D;
				}
		
				.txt {
					margin-top: 32rpx;
					width: 100%;
					text-align: center;
					font-weight: 500;
					font-size: 24	rpx;
					color: #3D3D3D;
				}
			}
		
			.bot1 {
				position: absolute;
		
				width: 610rpx;
				// border-top: 2rpx solid #D8D8D8;
				display: flex;
				flex-wrap: nowrap;
				// height: 100%;
				// bottom: -20rpx;
				justify-content: center;
				.bot_left {
					border-radius: 0rpx 0rpx 0rpx 30rpx;
					width: 50%;
					height: 86rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-weight: 500;
					font-size: 32rpx;
					color: #3D3D3D;
					background: #EEEEEE;
				}
		
				.bot_right {
					border-radius: 30rpx 30rpx 30rpx 30rpx;
					width: 60%;
					height: 86rpx;
					background: #4C97E7;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #FFFFFF;
					// border-left: 2rpx solid #D8D8D8;
					font-weight: 500;
					font-size: 32rpx;
					// color: #4C97E7;
		
				}
		
			}
		}
		
	
		
		.lines {
			width: 748rpx;
			height: 22rpx;
			background: #F6F6F6;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
		}

	


		

		.data_box {
			width: 672rpx;
			margin: 36rpx auto;
			display: flex;
			flex-wrap: nowrap;
			align-items: center;
			justify-content: space-between;

			.data_cont {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 150rpx;
				height: 60rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 4rpx 22rpx 0rpx rgba(0, 0, 0, 0.07);
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				font-weight: 400;
				font-size: 32rpx;
				color: #3D3D3D;
				border: 2rpx solid #fff;
			}

			.act1 {
				background: #E2F2FF;
				box-shadow: 0rpx 4rpx 22rpx 0rpx rgba(0, 0, 0, 0.07);
				color: #4C97E7;
				border: 2rpx solid #4C97E7;
			}
		}

		.top_box {
			display: flex;
			flex-wrap: nowrap;
			align-items: center;
			padding: 28rpx 30rpx;
			margin: 20rpx auto;
			width: 672rpx;
			height: 100rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 4rpx 22rpx 0rpx rgba(0, 0, 0, 0.07);
			border-radius: 10rpx 10rpx 10rpx 10rpx;

			.left_text {
				width: 25%;
				font-weight: 400;
				font-size: 32rpx;
				color: #3D3D3D;
			}

			.timebox {
				width: 75%;
				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				margin-left: 34rpx;

				.left_time {
					text-align: center;
					margin-right: 6rpx;
					height: 50rpx;
					width: 45%;
					border: 2rpx solid #ccc;
					border-radius: 12rpx;
					font-weight: 400;
					font-size: 32rpx;
					color: #979797;
				}

				.right_time {
					text-align: center;
					margin-left: 6rpx;
					height: 50rpx;
					width: 45%;
					border: 2rpx solid #ccc;
					border-radius: 12rpx;
					font-weight: 400;
					font-size: 32rpx;
					color: #979797;
				}
			}
		}
	}
</style>