<template>
	<view class="car">
		<view class="cartop">
			<view class="topa flexc">
				<image :src="reset" class="resetimg" @click="getReset"></image>
				<picker mode="date"  fields="year"  @change='bindDateChangea'>
					<view class="chekt flexc">
						<view>{{year+'年度'|| "选择年度"}}</view>
						<image :src="up"></image>
					</view>
				</picker>
				<view class="search flexc">
					<image :src="search"></image>
					<!-- confirm-type="search" @confirm="getConfirm" -->
					<input placeholder="请输入房号进行搜索"  v-model="text"/>
					<view class="btn" @click="getConfirm">搜索</view>
				</view>
			</view>
			<view class="mcont">
				<image :src="contbg" class="contbg"></image>
				<view class="mconta">
					<view class="mcontb">
						<view class="w50">
							<view class="mctit">已缴物业费 /元</view>
							<view class="mctxt over">{{infoCount.yjwyf}}</view>
						</view>
						<view class="w50">
							<view class="mctit">未缴物业费 /元</view>
							<view class="mctxt over">{{infoCount.wjwyf}}</view>
						</view>
					</view>
					<view class="mcontc">
						<view class="w50">
							<view class="mctit mb10">车位费 /元</view>
							<view class="mctxta">已缴费：<text>{{infoCount.yjcwf}}</text></view>
							<view class="mctxta">未缴费：<text>{{infoCount.wjcwf}}</text></view>
						</view>
						<view class="w50">
							<view class="mctit mb10">能耗费 /元</view>
							<view class="mctxta">已缴费：<text>{{infoCount.yjnhf}}</text></view>
							<view class="mctxta">未缴费：<text>{{infoCount.wjnhf}}</text></view>
						</view>
					</view>
				</view>
			</view>
			<view class="tabtop flexc">
				<view class="tabt" :class="tabval==ite.val?'act':''" v-for="(ite,idx) in tablist" :key="idx" @click="getTabFn(ite.val)">{{ite.tit}}</view>
				<view class="flex1"></view>
				<picker range-key='dictLabel' 	:range="fylblist"    @change='bindDateChangeb'>
					<view class="chekt flexc">
						<view class="over">{{fylb|| "选择类别"}}</view>
						<image :src="up"></image>
					</view>
				</picker>
			</view>
		</view>
		<!-- 列表 -->
		<view class="carlists">
			<car-list :datainfo="list" :wtdt="wtdt" type='money' @getDetail="getDetail"></car-list>
		</view>
		<block v-if="checkPermi(['wuYe:fee:callPaymentAll'])">
			<view style="height: 100rpx;"></view>
			<view class="rfbtn" @click="getcallPayFn">一键催缴</view>
		</block>
		<loading></loading>
	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import carList from "@/work/components/car/list.vue"
	import {feeCount,feeList,feecallPaymentAll} from "@/api/work/manage.js"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	export default{
		components:{carList},
		data(){
			return{
				reset:require('@/car/static/car/reset.png'),
				contbg:require('@/work/static/manage/contbg.png'),
				search:require('@/car/static/car/search.png'),
				up:require('@/car/static/car/up.png'),
				year:"",
				text:'',
				list:[],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				tabval:'N',
				tablist:[{tit:'未缴费',val:'N'},{tit:'已缴费',val:'Y'},],
				fylb:'',
				fylblist:[{dictLabel:'物业费',dictValue:'1'},{dictLabel:'车位费',dictValue:'2'},],
				infoCount:'',
			}
		},
		onLoad: function() {
			var date = new Date();
			this.year=date.getFullYear();
			this.getfeeCount()
			this.getDataFn()
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			gettime(){
				var date = new Date();
				var y = date.getFullYear();
				this.year=date.getFullYear();
			},
			getDetail(id){
				this.$tab.navigateTo("/work/pages/manage/moneydetail?id="+id)
			},
			getConfirm(){
				this.getrefreshData()
			},
			getReset(){
				this.text='';
				this.getrefreshData()
			},
			getrefreshData(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn();
				this.getfeeCount()
			},
			getTabFn(val){
				this.tabval=val;
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn();
			},
			bindDateChangea(e){
				var val=e.detail.value;
				this.year=val;
				this.getrefreshData();
			},
			bindDateChangeb(e){
				var val=e.detail.value;
				this.fylb=this.fylblist[val].dictLabel;
			},
			getfeeCount(){
				var params={
					year:this.year
				}
				if(this.text){
					params.detailedAddress=this.text
				}
				feeCount(params).then(res=>{
					if(res.code==200){
						this.infoCount=res.data
					}
				})
			},
			getcallPayFn(){
				var params={
					year:this.year
				}
				feecallPaymentAll(params).then(res=>{
					if(res.code==200){
						this.$toast(res.msg)
					}
				})
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
					isExpense:this.tabval,
					year:this.year
				}
				if(this.text){
					params.detailedAddress=this.text
				}
				feeList(params).then(res=>{
					if(res.code==200){
						if (res.rows.length < this.pageSize) {
							this.reachflag = false
							this.wtdt = '到底了~';
						} else {
							var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
							if (num < res.total) {
								this.reachflag = true
								this.wtdt = ''
							} else {
								this.reachflag = false
								this.wtdt = '到底了~';
							}
						}
						if (this.pageNum == 1) {
							this.list = res.rows;
						} else {
							this.list = this.list.concat(res.rows)
						}
					}else{
						this.$toast(res.msg)
					}
				})
				
			},
		}
	}
</script>
<style>
	page{background: #F3F3F0;}
</style>
<style lang="scss" scoped>
.car{padding: 624rpx 0 10rpx;}
.cartop{position: fixed;left: 0;right: 0;top: 0;background-color: #ffffff;z-index: 2;
	.topa{padding: 20rpx ;
		.resetimg{width: 36rpx;height: 36rpx;margin-right: 24rpx;flex: 0 0 auto;}
		
		.search{flex: 1;margin-left: 16rpx;height: 64rpx;background: #EEEEEE;border-radius: 32rpx;border: 2rpx solid #E6E6E6;padding-left: 24rpx;box-sizing: border-box;
		image{width: 32rpx;height: 34rpx;margin-right: 22rpx;flex: 0 0 auto;}
		input{flex: 1;font-size: 26rpx;color: #272727;}
		.btn{width: 100rpx;height: 64rpx;background: #3565ED;border-radius: 32rpx;flex: 0 0 auto;font-weight: bold;text-align: center;line-height: 64rpx;
font-size: 26rpx;
color: #FFFFFF;}
		}
	}
	.tabtop{padding-bottom: 40rpx;
		.tabt{font-weight: 500;font-size: 32rpx;color: #666666;position: relative;line-height: 56rpx;padding: 0 40rpx;margin-right: 6rpx;
			&.act{font-weight: bold;font-size: 32rpx;color: #272727;
			&::after{content: '';width: 40rpx;height: 10rpx;background: #0156FE;border-radius: 6rpx;position: absolute;left: 50%;margin-left: -20rpx;bottom: -10rpx;}
			}
		}
	}
	.mcont{position: relative;margin-top: 12rpx;
		.contbg{width: 100%;height: 382rpx;}
		.mconta{position: absolute;left: 0;top: 0;width: 100%;height: 382rpx;box-sizing: border-box;padding: 28rpx 56rpx;
			.w50{width: 50%;}
			.mctit{font-weight: 500;font-size: 24rpx;color: #CFE1FF;}
			.mctxt{font-size: 46rpx;color: #FFFFFF;font-weight: bold;margin-top: 26rpx;}
			.mctxta{font-weight: bold;font-size: 26rpx;color: #FFFFFF;margin-bottom: 14rpx;
				text{font-size: 30rpx;}
			}
			.mcontb{height: 124rpx;display: flex;}
			.mcontc{display: flex;padding-top: 28rpx;}
		}
	}
}
.chekt{min-width: 180rpx;
		view{font-weight: 500;font-size: 26rpx;color: #272727;flex: 1;}
		image{width: 24rpx;height: 16rpx;margin-left: 18rpx;flex: 0 0 auto;}
}
.carlists{padding: 0 18rpx;}
</style>