<template>
	<view>
		<u-navbar title="代缴费记录" title-color="#101010"></u-navbar>
		
		<u-picker-select title="日期选择" :maskCloseAble="true" v-model="tabsFrom.show2" :defaultTime="tabsFrom.show2Index" :endYear="endYear"
			mode="time" :params="params"  @confirm="selector2confirm" @cancel="selector2cancel"
			@reset="selector2reset">
		</u-picker-select>
		
		<view>
			<view class="head-head" >
				<u-search placeholder="搜索租户" :show-action="false"		 v-model="keyword"></u-search>
				
			</view>
			<view class="u-subsection" style="margin: 8rpx 0;border-bottom: 1px solid rgba(232,232,232,1);">
				<u-subsection :list="list" bgColor="#fff" activeColor="#1684FC"  buttonColor="#1684FC"
				 :current="homePageManageType" @change="sectionChange"
					font-size="32"></u-subsection>
					<view style="margin-top: 18rpx;    text-align: end;" v-if="homePageManageType==5&&tabsFrom.show2Text">
						指定时间：{{tabsFrom.show2Text}}
					</view>
			</view>
		</view>
		<!-- 统计 -->
		<view class="statistics">
			<view class="statistics-total">
				<view class="total-title">
					合计代缴费收入
				</view>
				<view class="total-number">
					{{monthQuery}}元
				</view>
			</view>
		
			<view class="statistics-group">
			
				
				<view  v-for="(item,i) in proxyListQuery" :key="i"
				  @click="gotoUrl('/pages/proxy/proxyInfo?id='+item.id+'&name='+item.name+'&type='+homePageManageType)" 
				
				 class="statistics-item">
					<view class="content">
						<!-- 收入 -->
						<view class="income">
							<view class="income-title">
								{{item.name}}
							</view>
							<view class="income-number">
								{{item.remark}}
							</view>
						</view>
						<!-- 电量 -->
						<view class="electric-quantity">
							{{item.proxyFee}}
						</view>
					</view>
					<view class="icon">
						<u-icon name="arrow-right" color="#acacac" size="24"></u-icon>
					</view>
				</view>
				
				<u-divider :isnone="proxyListQuery.length==0"  nonetext="没有找到相关内容"
					border-color="#CFD2D5">已经到底了</u-divider>
			</view>
		
		</view>
		
	</view>
</template>

<script>
	import * as API from '@/apis/pagejs/proxy.js'
	
	import {
		parseUnixTime
	} from '@/apis/utils'
	export default {
		data() {
			return {
				title:"",
				value: '2',
				clickType: -1,
				homePageManageType:2,
				queryDate:"",
				tenantName:"",
				tabsFrom: {
					show1: false,
					show1Index: 0,
					show2Index: '',
					show2: false,
					show1Text: "全部类型",
					show2Text: "",
				},
				keyword:"",
				proxyList:[],
				list: [{
						name: '上月',
						value: "2"
					},
					{
						name: '当月',
						value: "1"
					},
					{
						name: '今日',
						value: "4"
					}, {
						name: '当年',
				
						value: "3"
					}, {
						name: '合计',
				
						value: "0"
					},
					{
						name: '指定时间',
						value: "10"
					}
				],
				sp:0,
				companyId:"",
				
				endYear: '',
				params: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false
				},
				
			}
		},
		onLoad(op) {
			this.queryDate = parseUnixTime(new Date(), '{y}-{m}-{d}');
			this.companyId=op.companyId
			if(op.type!=5){
				this.homePageManageType=op.type
			}
			this.queryParent=(op.sp==1?1:0)
			this.endYear = new Date().getFullYear();
			this.getList()
		},
		computed:{
			monthQuery(){
				var list=0
				this.proxyList.forEach(item=>{
					list+=item.proxyFee
				})
				return list.toFixed(2)
			},
			proxyListQuery(){
				var list=[]
				this.proxyList.forEach(item=>{
					if( this.keyword==''||(item.name&&item.name.indexOf(this.keyword)!=-1)){
						list.push(item)
					}
				})
				return list
			}
		},
		methods: {
			getList(){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				var type=this.list[this.homePageManageType].value
				
				API.proxyPaymentList({
					queryDate:this.queryDate,
					queryParent:this.queryParent,
					companyId:this.companyId,
					type:type
				}).then((response) => {
					uni.hideLoading();
					this.proxyList=response.data.tenantInfoList
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			selector2confirm(e) {
				this.tabsFrom.show2Text = e.year + "年" + e.month + "月"
			
				this.tabsFrom.show2Index = e.year + "-" + e.month
				if (e.day) {
					this.tabsFrom.show2Text += e.day + "日"
					this.tabsFrom.show2Index += '-' + e.day
			
					this.queryDateMethod(this.tabsFrom.show2Index, true)
				} else {
					this.queryDateMethod(this.tabsFrom.show2Index, false)
				}
			},
			selector2reset(e) {
				//console.log(e)
				this.tabsFrom.show2Text = '全部时间'
				this.tabsFrom.show2Index = '';
			
				if (e.day) {
					this.queryDate = parseUnixTime(new Date(), '{y}-{m}-{d}');
					
					this.getList();
				} else {
				
					this.homePageManageType = this.clickType;
					if (this.homePageManageType != 5) {
						this.list[5].name = '指定时间';
					}
					this.getList();
				}
			},
			selector2cancel() {
				if(this.clickType != -1) {
					
				}
				this.homePageManageType = this.clickType;
			},
			queryDateMethod(queryTime, day) {
				this.homePageManageType = "5";
				
				if (day) {
					this.queryDate = queryTime;
					this.list[5].value = '9';
				} else {
			
					this.queryDate = queryTime + "-01";
					
					
					this.list[5].value = '10';
				}
				//this.list[5].name = queryTime;
				this.getList();
			},
			sectionChange(index) {
				this.clickType = this.homePageManageType ;
				this.homePageManageType = index;
				if (index == 5) {
					this.tabsFrom.show2 = true;
					//this.params.day = false;
				} else {
					this.list[5].name = '指定时间'
					this.getList();
				}
				
				
			},
		}
	}
</script>

<style>
	page {
	
		background-color: #fff;
	}
</style>

<style  lang="scss" scoped >
	/deep/.u-item-bg{
		height: 2px !important;
		
	}
	/deep/.u-item-5{
		.u-item-text{
			font-size: 26rpx !important;
		}
	}

	// 统计
	.statistics {
		.statistics-total {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 36rpx 32rpx;
			//background-color: rgba(22, 119, 255, 1);
			background: linear-gradient(88.25deg, rgba(31,85,255,1) 0.65%,rgba(39,171,255,1) 99.34%);
			color: rgba(255, 255, 255, 1);
			font-size: 40rpx;
			font-weight: bold;
		}

		.statistics-group {
			.statistics-item {
				padding: 24rpx 32rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1px solid rgba(245, 245, 245, 1);

				.content {
					flex: 0.99;

					display: flex;
					align-items: center;
					justify-content: space-between;
					.income {
					
						
						

						.income-title {
							font-weight: bold;
							font-size: 32rpx;
							color: rgba(51, 51, 51, 1);

						}

						.income-number {
							font-size: 28rpx;
							color: rgba(119,119,119,1);


						}
					}

					// 电量
					.electric-quantity {
						
						font-size: 40rpx;
						color: rgb(16,16,16);
						width: 200rpx;
						text-align: end;
					}

				}
			}

		}
	}
	.head-head{
		// box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.15);
		background: #fff;
		padding:24rpx;
	
	}
</style>
