<template>
	<view class="">
		<view class="tab_list" style="margin-top:0;">
			<view class="tabli" :class="type == 0 ? 'tabliactive' : ''" @click="changeFirTab(0)">全部</view>
			<view class="tabli" :class="type == 1 ? 'tabliactive' : ''" @click="changeFirTab(1)">我负责的</view>
			<view class="tabli" :class="type == 2 ? 'tabliactive' : ''" @click="changeFirTab(2)">下属负责的</view>
		</view>
		
		<!-- 筛选 -->
		<view class="searchbox">
			<view class="searchtext" @click="toQuery">筛选<view class="iconfont icon-shaixuan"></view></view>
		</view>
		
		<scroll-view scroll-y class="scrollbox" @scrolltolower="loodMore">
			<view class="payList">
				<pay-item :list="list"></pay-item>
			</view>
		</scroll-view>
		
		<view style="height: 200rpx;"></view>
		<view class="bot_total" @click="lookTotal">总金额合计> </view>
		<uni-popup ref="popup" type="bottom" background-color="#fff" @touchmove.stop.prevent>
			<view class="botwarp">
				<view class="wa_li">
					<view class="wa_label">总金额</view>
					<view class="wa_money"> <text>{{moneyInfo.allmoney?moneyInfo.allmoney:'0'}}</text>元 </view>
				</view>
				<view class="wa_li">
					<view class="wa_label">审核通过总金额</view>
					<view class="wa_money"> <text>{{moneyInfo.remoney?moneyInfo.remoney:'0'}}</text>元 </view>
				</view>
				<view class="wa_li">
					<view class="wa_label">审核中总金额</view>
					<view class="wa_money"> <text>{{moneyInfo.inmoney?moneyInfo.inmoney:'0'}}</text>元 </view>
				</view>
				<view class="wa_li">
					<view class="wa_label">审核未通过总金额</view>
					<view class="wa_money"> <text>{{moneyInfo.nomoney?moneyInfo.nomoney:'0'}}</text>元 </view>
				</view>
				<view class="wa_btn" @click="removeTotal">取消</view>
			</view>
		</uni-popup>
		
		<view class="icon_creat" @click="toAddpayment">
			<image :src="BASE_IMG_URL+'1.png'" mode="scaleToFill"></image>
		</view>
		
		<screen-pop 
			ref="screenChild" 
			@sureParams="surePa"
			@resetForm="resetForm"
			@changeSearchData="changeSearchData"
			:searchForm="searchForm"
		></screen-pop>
	</view>
</template>

<script>
	import { netPaymentList } from '@/api/kehu.js'
	import payItem from './item.vue'
	import screenPop from './screen.vue'
	import { BASE_IMG_URL } from '@/util/api.js'
	
	export default{
		components:{
			screenPop,
			payItem
		},
		data() {
			return{
				BASE_IMG_URL:BASE_IMG_URL,
				type:0,
				page:1,
				totalPage:1,
				queryParams:{},
				list:[],
				timeArr:[],
				moneyInfo:{},
				searchForm:[]
			}
		},
		onLoad(options) {
			if(options.stime){
				this.type = options.status
				this.timeArr = [options.stime,options.etime]
			}
			this.handleSearchForm('examine',(data)=>{
				this.searchForm = data
			})
		},
		onShow() {
			this.ini()
		},
		methods:{
			changeSearchData(type,key,value){
				let arr = this.searchForm
				arr.forEach((ele,index)=>{
					if(ele.field == type){
						ele[key] = value
						this.$set(this.searchForm, index, ele)
					}
				})
			},
			resetForm() {
				this.searchForm = this.handleResetSearch(this.searchForm)
			},
			//查看总金额合计
			lookTotal() {
				this.$refs.popup.open()
			},
			removeTotal() {
				this.$refs.popup.close()
			},
			changeFirTab(type) {
				this.type = type
				this.ini()
			},
			toQuery() {
				this.$refs.screenChild.init(this.timeArr)
			},
			surePa(params) {
				this.queryParams = params
				this.ini()
			},
			ini() {
				this.page = 1
				this.list = []
				setTimeout(()=>{
					this.getList()
				},200)
			},
			loodMore() {
				if(this.page < this.totalPage){
					this.page++
					this.getList()
				}
			},
			getList() {
				let params = {
					type:this.type,
					page:this.page,
					times:this.timeArr.length > 0 ? (this.timeArr[0] + ',' + this.timeArr[1]) : '',
					...this.queryParams,
					...this.handleSureSearch(this.searchForm)
				}
				netPaymentList(params).then(res=>{
					this.list = this.list.concat(res.data.data)
					this.totalPage = res.data.last_page
					this.moneyInfo = res.data.moneyinfo
				})
			},
			//新增回款
			toAddpayment() {
				uni.navigateTo({
					url:'/pagesB/contract/addPayment'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.bot_total{
		position: fixed;
		left:0;
		bottom:0;
		width:750rpx;
		height:calc(80rpx + env(safe-area-inset-bottom) / 2);
		background:#fff;
		font-size:24rpx;
		color:#333;
		text-align: center;
		line-height: 80rpx;
		color:$uni-text-color;
		border-top:1rpx solid #f5f5f5;
		padding-bottom:calc(env(safe-area-inset-bottom) / 2);
	}
	.botwarp{
		background:#fff;
		padding:0 24rpx;
		.wa_li{
			padding:24rpx 35rpx;
			border-bottom:1rpx solid #f5f5f5;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.wa_label{
				font-size:24rpx;
				color:#333;
			}
			.wa_money{
				font-size:24rpx;
				color:#666;
				text{
					color:$uni-text-color;
				}
			}
		}
		.wa_btn{
			width:100%;
			height:100rpx;
			font-size:24rpx;
			color:$uni-text-color;
			text-align: center;
			line-height: 100rpx;
		}
	}
	.tab_list{
		width:750rpx;
		height:80rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		background:#fff;
		margin-top:15rpx;
		.tabli{
			font-size:24rpx;
			color:#333;
			line-height: 75rpx;
			text-align: center;
			border-bottom:4rpx solid #fff;
		}
		.tabliactive{
			border-bottom:4rpx solid $uni-text-color;
		}
	}
	.searchbox{
		display: flex;
		justify-content: flex-end;
		margin:24rpx;
		.searchtext{
			display: flex;
			justify-content: center;
			align-items: center;
			font-size:24rpx;
			color:$uni-text-color;
			padding:8rpx 28rpx;
			background:#fff;
			border-radius: 5rpx;
			box-shadow: 2rpx 2rpx 50rpx rgba(0,0,0,0.1);
			.icon-shaixuan{
				color:$uni-text-color;
			}
		}
	}
	.scrollbox{
		width:750rpx;
		height:calc(100vh - 180rpx);
	}
</style>