<template>
	<view class="page">
		<u-navbar title="运营状况" :border-bottom="false" :background="bgc" title-color='#3D3D3D' back-icon-color="#3D3D3D"
			title-size='36' height='45'></u-navbar>
		<view class="leiji">
			<view class="li">
				<view class="top">
				    {{qbobj.orderUserCount == null ? '0人' : qbobj.orderUserCount + '人'}}
				</view>
				<view class="bot">
					累计用户
				</view>
			</view>
			<view class="li">
				<view class="top">
					￥{{qbobj.bonusActualAmount == null ? 0 : qbobj.bonusActualAmount}}
				</view>
				<view class="bot">
					累计收益
				</view>
			</view>
			<view class="li">
				<view class="top">
					￥{{qbobj.orderActualTotalAmount == null ? 0 : qbobj.orderActualTotalAmount}}
				</view>
				<view class="bot">
					订单金额 
				</view>
			</view>
			<view class="li">
				<view class="top">
					{{qbobj.orderCount == null ? '0' : qbobj.orderCount}}笔
				</view>
				<view class="bot">
					订单数量
				</view>
			</view>
		</view>
		<view class="time">
			<view class="timewz">
				时间范围 
			</view>
			<view class="inptime">
				<view class="" style="display: flex;align-items: center;" @click="showTimePicker('start')">
				  <u-icon name="calendar" color="#fff" size="28"></u-icon>	{{kstime}}
				</view> 
				--
		        <view class="" @click="showTimePicker('end')">
		        	{{jstime}}
		        </view> 					
			</view>
		</view>
		<u-picker mode="time" v-model="oneshow" :params="oneparams" @confirm="confirmone"></u-picker>
		<u-picker mode="time" v-model="twoshow" :params="twoparams" @confirm="confirmtwo"></u-picker>
		
	    <view class="riqi">
	    	<view :class="riqiindex == 0 ? 'actives' : ''" @click="btnriqi(0)">
	    		今日
	    	</view>
	    	<view :class="riqiindex == 1 ? 'actives' : ''" @click="btnriqi(1)">
	    		昨日
	    	</view>
	    	<view :class="riqiindex == 2 ? 'actives' : ''" @click="btnriqi(2)">
	    		本月
	    	</view>
	    	<view :class="riqiindex == 3 ? 'actives' : ''" @click="btnriqi(3)">
	    		上月
	    	</view>
	    </view>
		
		
		<view class="" style="width: 100%;height: 20rpx;"></view>
		<!-- 营收类 -->
		<view class="" style="height: 80vh;overflow: scroll;" v-if="index == 0">
			<!-- <view class="yinshoubox">
				<view class="lt">
					<view class="zhye">
						账户余额（元）
					</view>
					<view class="price">
						￥{{infoobj.balance == null ? '0.00' : (Number(infoobj.balance) + Number(waitDivideAmount)).toFixed(2)}}
					</view>
					<view class="ljtx">
						累积提现：{{successAmount == null ? '￥0.00' : '￥' + Number(successAmount).toFixed(2)}}
					</view>
				</view>
				<view class="rt">
					<view class="tx" @click="btntx">
						提现
					</view>
					<view class="txjl" style="text-align: center;font-size: 30rpx;" @click="btnmx">
						账户明细
					</view>
				</view>
			</view> -->
			<!-- <view class="leiji">
				<view class="li">
					<view class="top">
					    {{qbobj.orderUserCount == null ? '0人' : qbobj.orderUserCount + '人'}}
					</view>
					<view class="bot">
						累计用户
					</view>
				</view>
				<view class="li">
					<view class="top">
						￥{{qbobj.bonusActualAmount == null ? 0 : qbobj.bonusActualAmount}}
					</view>
					<view class="bot">
						累计收益
					</view>
				</view>
				<view class="li">
					<view class="top">
						￥{{qbobj.orderActualTotalAmount == null ? 0 : qbobj.orderActualTotalAmount}}
					</view>
					<view class="bot">
						订单金额 
					</view>
				</view>
				<view class="li">
					<view class="top">
						{{qbobj.orderCount == null ? '0' : qbobj.orderCount}}笔
					</view>
					<view class="bot">
						订单数量
					</view>
				</view>
			</view> -->
			
			
			<view class="ordertj">
				<view class="one">
					<view class="two">
						￥{{yunyingobj.orderActualAmount == null ? 0 : yunyingobj.orderActualAmount}}
					</view>
					<view class="thr">
						订单总金额
					</view>
				</view>
				<view class="one">
					<view class="two">
						{{yunyingobj.orderCount == null ? 0 : yunyingobj.orderCount}}笔
					</view>
					<view class="thr">
						订单总数
					</view>
				</view>
				<view class="one">
					<view class="two">
						{{yunyingobj.finishedOrderCount == null ? 0 : yunyingobj.finishedOrderCount}}笔
					</view>
					<view class="thr">
						已完成订单
					</view>
				</view>
				<view class="one">
					<view class="two">
						{{yunyingobj.orderStatusMap.PROCESSING == null ? 0 : yunyingobj.orderStatusMap.PROCESSING}}笔
					</view>
					<view class="thr">
						进行中订单
					</view>
				</view>
			</view>
			<view class="yinshouqk">
				<view class="name">
					我的收入<text style="color: rgb(242,75,23);margin-left: 10rpx;font-size: 32rpx;">{{yunyingobj.bonusActualAmount == null ? 0 : yunyingobj.bonusActualAmount}}</text>元
				</view>
				<view class="name" style="margin-top: 10rpx;">
					订单收入<text style="color: rgb(242,75,23);margin-left: 10rpx;font-size: 32rpx;">{{yunyingobj.orderActualReceivedAmount == null ? 0 : yunyingobj.orderActualReceivedAmount}}</text>元
				</view>
				<view class="zupibox">
					<view class="zupi">
						<view class="one">
							<view class="onewz">
								骑行费
							</view>
							<view class="twowz">
								￥{{yunyingobj.orderRiddingFee == null ? 0 : yunyingobj.orderRiddingFee}}
							</view>
						</view>
						<view class="one">
							<view class="onewz">
								调度费
							</view>
							<view class="twowz">
								￥{{yunyingobj.orderDispatchFee == null ? 0 : yunyingobj.orderDispatchFee}}
							</view>
						</view>
						<view class="one">
							<view class="onewz">
								管理费
							</view>
							<view class="twowz">
								￥{{yunyingobj.orderManageFee == null ? 0 : yunyingobj.orderManageFee}}
							</view>
						</view>
					</view>
					<view class="zupi" style="margin-top: 30rpx;">
						<view class="one">
							<view class="onewz">
								车损费
							</view>
							<view class="twowz">
								￥{{yunyingobj.orderDeductionFee == null ? 0 : yunyingobj.orderDeductionFee}}
							</view>
						</view>
						<view class="one">
							<view class="onewz">
								自动退款
							</view>
							<view class="twowz">
								￥{{yunyingobj.orderAutoRefundAmount == null ? 0 : yunyingobj.orderAutoRefundAmount}}
							</view>
						</view>
						<view class="one">
							<view class="onewz">
								人工退款
							</view>
							<view class="twowz">
								￥{{yunyingobj.orderAdminRefundAmount == null ? 0 : yunyingobj.orderAdminRefundAmount}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 运维类 -->
		<view class="yunwei" v-if="index == 1">
			<view class="cheliang" style="padding: 30rpx 62rpx;box-sizing: border-box;">
				<view class="name">
					工单管理
				</view>
				<view class="dabox">
					<view class="li">
						<view class="bfb">
							236
						</view>
						<view class="cl">
							调度工单
						</view>
					</view>
					<view class="li">
						<view class="bfb">
							365
						</view>
						<view class="cl">
							维修工单
						</view>
					</view>
					<view class="li">
						<view class="bfb">
							3256
						</view>
						<view class="cl">
							投诉工单
						</view>
					</view>
				</view>
			</view>
			<view class="clzb">
				<view class="name">
					车辆指标
				</view>
				<view class="ul">
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							总投放
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							待使用
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							使用中
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							临时锁车
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							仓库中
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							禁用中
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							投放中
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							运营中P点外
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							运营中超区
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							零收益车辆
						</view>
					</view>
					<view class="li">
						<view class="shu">
							100
						</view>
						<view class="zi">
							调度设备
						</view>
					</view>
					<view class="li"></view>
				</view>
			</view>
		</view>
        <!-- <TabBar :indexs='1' style=""></TabBar> -->
	</view>
</template>

<script>
	import TabBar from '@/page_shanghu/components/tab-bar/tab-bar.vue'
	export default {
		components: {
			TabBar
		},
		data() {
			return {
                bgc: {
                	backgroundColor: "#fff",
                },
				index:0,
				successAmount:'',
				riqiindex:0,
				oneparams: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				oneshow: false,
				twoparams: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				twoshow: false,
				kstime:'',
				jstime:'',
				yunyingobj:{},
				qbobj:{},
				infoobj:{},
				areaId:'',
				waitDivideAmount:''
			}
		},
		onLoad() {

		},
		onShow() {
			if (uni.getStorageSync('adminAreaid')) {
				this.areaId = uni.getStorageSync('adminAreaid')
				console.log(this.areaId);
				this.getinfo()
				this.getCurrentDate(this.riqiindex)
			}else{
				this.getinfo()
				this.getCurrentDate(this.riqiindex)
			}
			
		},
		methods: {
			// 点击跳转到账户明细
			btnmx(){
				uni.navigateTo({
					url:'/page_shanghu/mingxi?userId=' + this.infoobj.userId
				})
			},
			// 请求个人信息
			getinfo() {
			    this.$u.get(`/getInfo`).then(res => {
			        if (res.code == 200) {
			            this.infoobj = res.user
						this.successAmount = res.stat.withdraw.successAmount == null ? 0 : Number(res.stat.withdraw.successAmount)
						this.waitDivideAmount = res.stat.bonus.waitDivideAmount == null ? 0 : res.stat.bonus.waitDivideAmount
						this.gettongji()
						this.getqb()
			        }
			    })
			}, 
			// 请求全部运营统计数据
			getqb() {
				
			    let StatKeys = 'order_user_count,bonus_actual_amount,order_actual_amount,order_count'
			    this.$u.get(`/dashboard/revenueStat?keys=${StatKeys}&dateRange=&userId=${this.infoobj.userId}&areaId=${this.areaId}`).then(res => {
			        if (res.code == 200) {
			            this.qbobj = res.data
			        }
			    })
			}, 
			// 请求筛选运营统计数据
			gettongji() {
			    let StatKeys = 'order_actual_amount,order_count,order_end_status_count,order_status_count,bonus_actual_amount,order_ridding_fee,order_deduction_fee,order_dispatch_fee,order_manage_fee,order_refund_amount'
			    this.$u.get(`/dashboard/revenueStat?keys=${StatKeys}&dateRange=${this.kstime + ',' + this.jstime}&userId=${this.infoobj.userId}&areaId=${this.areaId}`).then(res => {
			        if (res.code == 200) {
			            this.yunyingobj = res.data
			        }
			    })
			}, 
			// 一开始就获取当前年月日
			getCurrentDate(num) {
			    const currentDate = new Date()
			    const year = currentDate.getFullYear()
			    const month = currentDate.getMonth() + 1
			    const day = currentDate.getDate()
			    const formatDate = (year, month, day) => {
			        const formattedMonth = month < 10 ? `0${month}` : month
			        const formattedDay = day < 10 ? `0${day}` : day
			        return `${year}-${formattedMonth}-${formattedDay}`
			    }
			    const getFirstDayOfMonth = (year, month) => {
			        return new Date(year, month - 1, 1)
			    }
			    const getLastDayOfMonth = (year, month) => {
			        return new Date(year, month, 0)
			    }
			    switch (num) {
			        case 0:
			            this.kstime = formatDate(year, month, day)
			            this.jstime = formatDate(year, month, day)
			            break
			        case 1:
			            const yesterday = new Date(currentDate)
			            yesterday.setDate(currentDate.getDate() - 1)
			            this.kstime = formatDate(yesterday.getFullYear(), yesterday.getMonth() + 1, yesterday.getDate())
			            this.jstime = formatDate(yesterday.getFullYear(), yesterday.getMonth() + 1, yesterday.getDate())
			            break
			        case 2:
			            const firstDayOfMonth = getFirstDayOfMonth(year, month)
			            this.kstime = formatDate(firstDayOfMonth.getFullYear(), firstDayOfMonth.getMonth() + 1, firstDayOfMonth.getDate())
			            this.jstime = formatDate(year, month, day)
			            break
			        case 3:
			            const lastMonthFirstDay = getFirstDayOfMonth(year, month - 1)
			            const lastMonthLastDay = getLastDayOfMonth(year, month - 1)
			            this.kstime = formatDate(lastMonthFirstDay.getFullYear(), lastMonthFirstDay.getMonth() + 1, lastMonthFirstDay.getDate())
			            this.jstime = formatDate(lastMonthLastDay.getFullYear(), lastMonthLastDay.getMonth() + 1, lastMonthLastDay.getDate())
			            break
			        default:
			            this.kstime = formatDate(year, month, day)
			            this.jstime = formatDate(year, month, day)
			            break
			    }
			},
			// 选择开始时间
			confirmone(e){
				this.kstime = e.year + '-' + e.month + '-' + e.day
				this.riqiindex = -1
				this.gettongji()
			},
			// 选择结束时间
			confirmtwo(e){
				this.jstime = e.year + '-' + e.month + '-' + e.day
				this.riqiindex = -1
				this.gettongji()
			},
			// 点击跳转到提现
			btntx(){
				uni.navigateTo({
					url:'/page_shanghu/gongzuotai/AccountDetails'
				})
			},
			// 点击切换日期
			btnriqi(num){
				this.riqiindex = num
				this.getCurrentDate(this.riqiindex)
				this.gettongji()
			},
			// 点击切换tab
			btntab(num){
				this.index = num
			},
			showTimePicker(type) {
				if(type === 'start') {
					this.oneshow = true
				} else {
					this.twoshow = true
				}
			}
		}
	}
</script>

<style lang="scss">
	.ordertj{
		width: 696rpx;
		max-height: 300rpx;
		background-color: #fff;
		border-radius: 30rpx;
		margin: auto;
		margin-top: 30rpx;
		padding: 30rpx 34rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		.one{
			text-align: center;
			.two{
				font-weight: 600;
				font-size: 28rpx;
			}
			.thr{
				margin-top: 10rpx;
				color: #808080;
				font-size: 24rpx;
			}
		}
	}
	page {
		background: #F7F7F7;
	}
	.actives{
		color: #fff !important;
		background: linear-gradient( 45deg, #2C8AF0 0%, #C4DAFF 100%) !important;
	}
	.clzb{
		width: 696rpx;
		height: 496rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: auto;
		margin-top: 20rpx;
		padding: 44rpx 34rpx;
		box-sizing: border-box;
		.name{
			font-weight: 600;
			font-size: 32rpx;
			color: #3D3D3D;
		}
		.ul{
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
		   .li{
		   	  width: 25%;
		   	  text-align: center;
			  margin-top: 28rpx;
			  .shu{
				  font-weight: 800;
				  font-size: 32rpx;
				  color: #4297F3;
			  }
			  .zi{
				  font-size: 28rpx;
				  color: #AFAFAF;
				  margin-top: 12rpx;
			  }
		   }	
		}
	}
	.cheliang{
		width: 696rpx;
		height: 254rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: auto;
		margin-top: 20rpx;
		padding: 30rpx 34rpx;
		box-sizing: border-box;
		.name{
			font-weight: 600;
			font-size: 28rpx;
			color: #3D3D3D;
		}
		.dabox{
			display: flex;
			justify-content: space-between;
			.li{
				margin-top: 46rpx;
				text-align: center;
				.bfb{
					font-weight: 800;
					font-size: 36rpx;
					color: #3D3D3D;
				}
				.cl{
					font-size: 28rpx;
					color: #AFAFAF;
					margin-top: 6rpx;
				}
			}
		}
	}
	.zupibox{
		width: 630rpx;
		max-height: 360rpx;
		background: #F5FAFF;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		margin: auto;
		margin-top: 24rpx;
		padding: 30rpx 20rpx;
		box-sizing: border-box;
		.zupi{
			display: flex;
			justify-content: space-between;
			justify-content: center;
			.one{
				width: 33%;
				text-align: center;
				.onewz{
					font-size: 28rpx;
					color: #4297F3;
					margin-top: 10rpx;
				}
				.twowz{
					font-size: 28rpx;
					color: #7C7C7C;
					margin-top: 10rpx;
				}
			}
		}
	}
	.yinshouqk{
		width: 696rpx;
		max-height: 768rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		padding: 30rpx 34rpx;
		box-sizing: border-box;
		margin: auto;
		margin-top: 20rpx;
		.zongfy{
			display: flex;
			justify-content: space-between;
			margin-top: 54rpx;
			padding: 0 18rpx;
			box-sizing: border-box;
			.top{
				text-align: center;
				.topwz{
					font-weight: 800;
					font-size: 36rpx;
					color: #3D3D3D;
				}
				.botwz{
					font-size: 28rpx;
					color: #AFAFAF;
				}
			}
			image{
				width: 78rpx;
				height: 78rpx;
			}
		}
		.name{
			font-weight: 600;
			font-size: 28rpx;
			color: #3D3D3D;
		}
	}
	.riqi{
		view{
			width: 164rpx;
			height: 54rpx;
			line-height: 54rpx;
			background: #FFFFFF;
			border-radius: 36rpx 36rpx 36rpx 36rpx;
			font-size: 28rpx;
			color: #2C8AF0;
			text-align: center;
			border: 1px solid #fff;
		}
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		padding: 0 28rpx;
		box-sizing: border-box;
	}
	.time{
		width: 696rpx;
		height: 96rpx;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		margin: auto;
		margin-top: 16rpx;
		display: flex;
		justify-content: space-between;
		box-sizing: border-box;
		padding-left: 20rpx;
		align-items: center;
		.timewz{
			font-weight: 400;
			font-size: 28rpx;
			color: #2C8AF0;
		}
		.inptime{
			display: flex;
			align-items: center;
			color: #fff;
			background-color: #2C8AF0;
			border-radius: 30rpx;
			width: 500rpx;
			justify-content: space-between;
			padding: 0 22rpx;
			view{
				margin-left: 10rpx;
				margin-right: 10rpx;
				// width: 196rpx;
				height: 52rpx;
				border-radius: 6rpx 6rpx 6rpx 6rpx;
				text-align: center;
				line-height: 52rpx;
				font-size: 28rpx;
				color: #fff;
			}
		}
	}
	.leiji{
		width: 696rpx;
		height: 178rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		display: flex;
		justify-content: space-between;
		padding: 38rpx 44rpx;
		box-sizing: border-box;
		margin: auto;
		margin-top: 34rpx;
		.li{
			text-align: center;
			.top{
				font-weight: 800;
				font-size: 32rpx;
				color: #4297F3;
				margin-top: 12rpx;
			}
			.bot{
				margin-top: 12rpx;
				font-weight: 400;
				font-size: 28rpx;
				color: #AFAFAF;
			}
		}
	}
	.yinshoubox{
		display: flex;
		justify-content: space-between;
		padding: 0 56rpx;
		box-sizing: border-box;
		margin-top: 22rpx;
		background-color: #2C8AF0;
		.rt{
			.tx{
				width: 162rpx;
				height: 58rpx;
				background: #FFFFFF;
				box-shadow: 4rpx 4rpx 2rpx 0rpx rgba(0,0,0,0.3);
				border-radius: 36rpx 36rpx 36rpx 36rpx;
				text-align: center;
				line-height: 58rpx;
				font-weight: 600;
				font-size: 32rpx;
				color: #4297F3;
				margin-top: 50rpx;
			}
			.txjl{
				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
				margin-top: 44rpx;
				text-align: right;
			}
		}
		.lt{
			.zhye{
				font-weight: 600;
				font-size: 28rpx;
				color: rgba(255,255,255,0.6);
			}
			.price{
				font-weight: 600;
				font-size: 50rpx;
				color: #FFFFFF;
				margin-top: 8rpx;
			}
			.ljtx{
				margin-top: 40rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: rgba(255,255,255,0.6);
			}
		}
	}
	.active{
		color: #fff !important;
		text{
			display: block;
			width: 54rpx;
			height: 8rpx;
			background: #FFFFFF;
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			margin: auto;
			margin-top: 8rpx;
		}
	}
	.tabs{
		display: flex;
		padding-top: 108rpx;
		padding-left: 56rpx;
		box-sizing: border-box;
		view{
			margin-right: 72rpx;
			font-weight: 600;
			font-size: 36rpx;
			color: rgba(255,255,255,0.6);
		}
	}
    .bj{
		width: 750rpx;
		height: 454rpx;
		background: #4297F3;
		border-radius: 0 0 50rpx 50rpx;
		position: fixed;
		top: 0;
		left: 0;
		z-index: -1;
	}
</style>