<template>
	<view>
		<u-navbar :title="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="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 proxyList" :key="i"
				  @click="gotoUrl('')" 
				 
				 class="statistics-item">
					<view class="content">
						
						<view class="item-icon">
							
							<image class="img" v-if="item.name.indexOf('水')>-1" src="@/assets/img/deadline2.png" mode=""></image>
								<image class="img"  v-else-if="item.name.indexOf('房')>-1||item.name.indexOf('租')>-1" src="@/assets/img/deadline1.png" mode=""></image>
								<image class="img"  v-else-if="item.name.indexOf('保洁')>-1" src="@/assets/img/deadline4.png" mode=""></image>
								<image class="img" v-else-if="item.name.indexOf('物业')>-1"  src="@/assets/img/deadline3.png" mode=""></image>
								
							<image class="img" v-else src="@/assets/img/deadline3.png" mode=""></image>
							
						</view>
						<!-- 收入 -->
						<view class="income">
							<view class="income-title">
								{{item.name}}
							</view>
							<view class="income-number" v-if="item.prepaidEndTime">
								已缴费至 <text class="state">{{item.prepaidEndTime}}</text>
							</view>
							<view class="income-number" v-else>
								 <text class="state">{{item.paymentMethodN}}</text>
							</view>
						</view>
						
					</view>
					<!-- 电量 -->
					<view class="electric-quantity">
						{{item.proxyFee.toFixed(2)}}元
					</view>
				</view>
				<u-divider :isnone="proxyList.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:"",
				monthQuery:0,
				tabsFrom: {
					show1: false,
					show1Index: 0,
					show2Index: '',
					show2: false,
					show1Text: "全部类型",
					show2Text: "",
					
				},
				proxyList:[],
				list: [{
						name: '上月',
						value: "2"
					},
					{
						name: '当月',
						value: "1"
					},
					{
						name: '今日',
						value: "4"
					}, {
						name: '当年',
				
						value: "3"
					}, {
						name: '合计',
				
						value: "0"
					},
					{
						name: '指定时间',
						value: "10"
					}
				],
				sp:0,
				tenantId:"",
				endYear: '',
				params: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false
				},
				
			}
		},
		onLoad(op) {
			this.tenantId=op.id
			this.title=op.name
			this.queryDate = parseUnixTime(new Date(), '{y}-{m}-{d}');
			this.endYear = new Date().getFullYear();
			if(op.type!=5){
				this.homePageManageType=op.type
			}
			this.getList()
		},
		computed:{
			 
		},
		methods: {
			getList(){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				var type=this.list[this.homePageManageType].value
				
				API.proxyPaymentDetails({
						queryDate:this.queryDate,
					tenantId:this.tenantId,
						type:type
				}).then((response) => {
					uni.hideLoading();
					this.proxyList=response.data.itemList
					this.monthQuery=response.data.proxyFee
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			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();
			},
			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)
				}
			},
			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-5{
		.u-item-text{
			font-size: 26rpx !important;
		}
	}
	/deep/.u-item-bg{
		height: 2px !important;
		
	}
	/deep/.u-back-wrap{
		background-color: #fff;
	}

	// 统计
	.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);
				
				.electric-quantity {
					
					font-size: 40rpx;
					color: rgb(16,16,16);
					width: 200rpx;
					text-align: end;
				}
				.content {
					.item-icon {
						width: 80rpx;
						height: 80rpx;
						margin-right: 12rpx;
						.img {
							width: 100%;
							height: 100%;
							vertical-align: middle;
						}
					}
					
					flex: 0.99;

					display: flex;
					align-items: center;
					
					.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);


						}
					}

					

				}
			}

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