<template>
	<view>
		<u-navbar :is-back="false">
			<view class="navbar">
				<view class="navbar-tit"  >分润记录</view>
				<view class="navbar-screen" @click="popupShow = true"><span>筛选</span><u-icon name="filter-2-fill" custom-prefix="custom-icon" color="#b0b8c8" size="32"></u-icon></view>
			</view>
		</u-navbar>
		<u-popup v-model="popupShow" mode="top" height="80%">
			<view class="popup-screen">
				<view class="screen">
					<view class="screen-item">
						<view class="screen-head">查询日期</view>
						<view class="screen-main2">
							
							<u-calendar v-model="showdate" mode="date" @change="changedate"></u-calendar>
							
							<u-input :value="queryDate?queryDate:'选择时间筛选'" :type="type" :border="border" @click="showdate = true" />
						<!-- 	
							<u-action-sheet :list="actionSheetList" v-model="show" @click="actionSheetCallback"></u-action-sheet>
						 --></view>
					</view>
					<view class="screen-item">
						<view class="screen-head">充电桩类型</view>
						<view class="screen-main">
							<view 
							:class="{
								active:selecttype==''
							}" @click="selecttype=''"
							class="screen-entry ">全部</view>
							<view 
							:class="{
								active:selecttype=='0'
							}" @click="selecttype='0'"
							
							class="screen-entry type1">自行车充电</view>
							<view 
							:class="{
								active:selecttype=='2'
							}" @click="selecttype='2'"
							class="screen-entry type3">交流慢充</view>
							<view 
							:class="{
								active:selecttype=='1'
							}" @click="selecttype='1'"
							class="screen-entry type2">直流快充</view>
						</view>
					</view>
					<view class="screen-item">
						<view class="screen-head">站点</view>
						<view class="screen-main">
							<view class="screen-entry  "
							:class="{
								active:selectstationId==''
							}"
							 @click="selectstationId=''"
							>全部</view>
							<view 
							v-for="(item,i) in stationList" :key="i"
							:class="{
								active:selectstationId==item.id
							}"
							 @click="selectstationId=item.id,selectdeviceNo=''"
							class="screen-entry" >{{item.name}}</view>
						
						</view>
					</view>
					<view 
				
					class="screen-item">
						<view class="screen-head">桩号</view>
						<view class="screen-main">
							 
							<view class="screen-entry  "
							:class="{
								active:selectdeviceNo==''
							}"
							 @click="selectdeviceNo=''"
							>全部</view>
							<view 
							v-for="(item,i) in stationListSon" :key="i"
							v-show="selectstationId?(selectstationId==item.stationId):true"
							:class="{
								active:selectdeviceNo==item.deviceNo
							}"
							
							 @click="selectdeviceNo=item.deviceNo"
							class="screen-entry" >{{item.name}}</view>
						</view>
					</view>
				</view>
				<view class="screen-foot">
					<view class="screen-btn-l"
					 @click="resetBtn" >重置</view>
					<view class="screen-btn-r" @click="okbtn" >确定</view>
				</view>
			</view>
		</u-popup>
		<view class="detailed">
				<view style="text-align: center;margin-top: 100px" v-if="!list.length">
					<img src="@/assets/img/blankpage.png">
					<view>查询为空</view>
				</view>
				
				<view class="detailed-list" v-for="(item ,index) in list"
				@click="gotoUrl('pagesFinance/share/details?id='+item.id)"
				:key="index">
			 
					<view class="detailed-time"    v-if="item.show">
						<p>{{item.showtime}}</p>
						<p  >共收入 {{showMap.get(item.showtime)}}元</p>
					</view>
					<view class="detailed-item">
						<view class="detailed-item-name">
							<h2>{{item.flowNo?item.flowNo:'无充电单号'}}</h2>
							<p>{{item.stationName}}/{{item.deviceName}}</p>
						</view>
						<view class="detailed-item-name"  style="
								width: 80px;
							">
							
							<h2 style="   text-align: end;">{{item.shareProfitAmount}}元</h2>
							<p style="   text-align: end;" >{{item.createTime?item.createTime.slice(10):''}}</p>
						</view>
					</view>
				</view>
			<u-divider v-if="list.length&&list.length == recordsTotal" color="#B6BDC3" style="margin-top:20px;" bg-color="#f4f0f0">已经到底了</u-divider>
			
			 
		</view>
		<Tabbar  ref="tabbarMain" :current="2"></Tabbar>
 	</view>
</template>

<script>
	import Tabbar from '@/components/TabbarFinance.vue'
	import * as API from '@/apis/finance.js'
	import {
		
		currentTimeStamp,
		parseUnixTime
	} from '@/utils'
	
	export default {
		data() {
			return {
				showdate: false,
				startTime: "",
				queryDate:"",		
				endTime: "",
				selecttype:"",
				selectstationId:"",
				selectdeviceNo:"",
				title:"",
				year:"",
				startyear:"",
				endyear:"",
				params: {
			 					year: true,
			 					month: false,
			 					day: false,
			 					hour: false,
			 					minute: false,
			 					second: false,
								// timestamp: true,
			 	},
				form:{
					
				},
				 
				pageIndex: 1,
				recordsTotal: 0,
				list: [],
				popupShow: false,
				tabbarList: [{
						iconPath: "bar-chart-box-fill",
						selectedIconPath: "bar-chart-box-fill",
						text: '统计',
						count: 0,
						isDot: true,
						customIcon: true,
					},
					{
						iconPath: "article-fill",
						selectedIconPath: "article-fill",
						text: '明细',
						midButton: true,
						customIcon: true,
					},
					{
						iconPath: "account-pin-box-fill",
						selectedIconPath: "account-pin-box-fill",
						text: '我的',
						count: 0,
						isDot: false,
						customIcon: true,
					},
				],
				showMap:null,
				current: 0,
				value: '',
				type: 'select',
				show: false,
				border: true,
				stationList:[],
				stationListSon:[],
				actionSheetList: [
					{
						text: '男'
					},
					{
						text: '女'
					},
					{
						text: '保密'
					}
				],
			}
		},
		components: {
			Tabbar
		},
		onShow(){
			if(this.$refs.tabbarMain){
				this.$refs.tabbarMain.setcount(2);
			}
		},
		onReachBottom() {
			if (this.list.length < this.recordsTotal) {
				this.myLoadmore();
			}
		},
		onLoad() {
			// this.queryDate=parseUnixTime(new Date(),"{y}-{m}-{d}")
			 
			this.startyear=new Date().getFullYear()
			console.log(this.startyear)
			this.endyear=this.startyear-3
			console.log(this.endyear)
		},
		onReady() {
			
			this.getList()
			this.getStation()
			
		},
		methods: {
			showDateMoth(date){
				
				var back=date;
				if(date){
					var k=	date.slice(5,6)
					console.log(k)
					if(k=='0'){
						back=	date.slice(6,7)
					}else{
						back=	date.slice(5,7)
					}
					
					
				}
				return back;
			},
			changedate(e) {
				console.log(e)
				this.queryDate=e.result
				
				
			},
			resetBtn(){
			//	this.queryDate=parseUnixTime(new Date(),"{y}-{m}-{d}")
				
				this.year=""
				 this.startTime=""
				 this.endTime=""
				this.selecttype=""
				this.selectstationId=""
				this.selectdeviceNo=""
				this.pageIndex = 1;
				this.form = {
					queryDate:"",
				 
					pageIndex: this.pageIndex,
					type:this.selecttype,
					stationId:this.selectstationId,
					deviceNo:this.selectdeviceNo,
				};
				this.popupShow=false;
				this.list = [];
				this.getList()
				
			},
			okbtn(){
				this.popupShow=false;
				this.pageIndex = 1;
				
				this.form = {
					queryDate:this.queryDate,
					
					pageIndex: this.pageIndex,
					type:this.selecttype,
					stationId:this.selectstationId,
					deviceNo:this.selectdeviceNo,
				};
				this.list = [];
				this.getList()
			},
			getList() {
				
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				this.form.pageIndex=this.pageIndex
				this.form.pageSize=20
				
				API.recordData(this.form).then((res) => {
					
					this.list = [
						...this.list,
						...res.data.data
					];
					
					var showMap=new Map()
					this.list.forEach(item=>{
						var ktime=item.createTime.split(" ")[0]
						if(showMap.has(ktime)){
							item.show=false;
						
							
						}else{
							var Amount=item.todaySPAmount 
							
							showMap.set(ktime,Amount)
							
							item.show=true;
							item.showtime=ktime;
						}
					})
					
					this.showMap=showMap;
					
					this.recordsTotal = res.data.recordsTotal
					uni.hideLoading()
					
				}).catch(error => {
					uni.showToast({
					
						title: error
					})
				})
			},
		
			getStation(bl) {
				
				API.stationList().then((res) => {
					
					this.stationList = res.data.stationList
					this.stationListSon=res.data.deviceList	
				}).catch(error => {
					uni.showToast({
					
						title: error
					})
				})
			},
			myLoadmore() {
					
				this.pageIndex += 1;
				this.getList()
				
			},
			// 点击actionSheet回调
			actionSheetCallback(index) {
				this.value = this.actionSheetList[index].text;
			}
		}
	}
</script>
<style>
	page{
		background-color: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.popup-screen{
		padding: 20px;
		position: relative;
		.screen{
			padding-bottom: 30px;
		}
		.screen-item{
			margin-bottom: 20px;
			.screen-head{
				margin-bottom: 8px;
				font-size: 16px;
			}
			.screen-main{
				 // display: -webkit-box;
				display: flex;
				flex-wrap: wrap;
			}
			.screen-entry{
				width: 29%;
				padding:6px 0;
				display: flex;
				align-items: center;
				justify-content: center;
				background-color: #F2F5FA ;
				text-align: center;
				margin-bottom: 10px;
				border-radius: 3px;
				margin-right: 6px;
			}
			.screen-entry.active{
				background-color: #185AC6;
				color:#fff;
			}
		}
		.screen-foot{
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			display: flex;
			height:50px;
			border-top: 1px solid #ededed;
			.screen-btn-l{
				background-color: #fff;
				flex: 0.2;
				text-align: center;
				line-height: 50px;
			}
			.screen-btn-r{
				flex: 0.8;
				text-align: center;
				line-height: 50px;
				background-color: #185AC6;
				color:#fff;
			}
		}
	}
	.navbar{
		display: flex;
		justify-content: space-between;
		flex: 1;
		padding: 0 15px;
	}
	.navbar-tit{
		font-size: 20px;
	}
	.navbar-screen{
		display: flex;
		align-items: center;
		span{
			margin-right: 2px;
			color:#999;
		}
	}
	.detailed-time{
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px 20px;
		p{
			color:#666;
		}
	}
	.detailed-item{
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		padding: 10px 20px;
		border-bottom: 1px solid #ededed;
		.detailed-item-name{
			h4{
				font-weight: normal;
			}
			p{
				font-size: 12px;
				margin-top: 4px;
				color:#A2A9B5;
			}
		}
		.detailed-item-num{
			display: flex;
			align-items: center;
			h2{
				margin-right: 4px;
			}
		}
	}
</style>
