<template>
	<view class="">
	<uni-popup ref="popup" type="top" background-color="#fff">
		<scroll-view scroll-y class="scrollbox" style="height:600rpx;background:#fff;" >
			<!--筛选模块  -->
			<view class="screen_content"  @tap.stop.prevent>
				<view class="fir_li">
					<view class="li_label">关联合同</view>
					<view class="li_box" @click="toSelectContract">
						<view class="form_right" style="text-align: center;">
							<view :class="contractObj ? 'valueActive' : ''">
								{{contractObj ? contractObj.name : '点击选择'}}
							</view>
							<view class="iconfont icon-arrows_right"></view>
						</view>
					</view>
				</view>
				<view class="fir_li">
					<view class="li_label">回款状态</view>
					<picker @change="changeTab" :value="check_status" :range="statusList">
						<view class="li_box" >
							<view class="form_right" style="text-align: center;">
								<view :class="statusList[check_status] ? 'valueActive' : ''">
									{{statusList[check_status] ? statusList[check_status] : '点击选择'}}
								</view>
								<view class="iconfont icon-arrows_right"></view>
							</view>
						</view>
					</picker>
				</view>
				<view class="fir_li">
					<view class="li_label">回款时间</view>
					<view class="li_box" style="display: flex;">
						<picker @change="changeStartTime" mode="date" :end="end_time"
							style="width:50%;border-right:1rpx solid #CCCCCC">
							<view class="form_right">
								<view style="flex:1;text-align: center;"
									:class="start_time ? 'valueactive' : '' ">
									{{start_time ? start_time : '开始时间'}}</view>
							</view>
						</picker>
						<picker @change="changeEndTime" mode="date" :start="start_time" style="width:50%">
							<view class="form_right">
								<view style="flex:1;text-align: center;"
									:class="end_time ? 'valueactive' : '' ">{{end_time ? end_time : '结束时间'}}
								</view>
							</view>
						</picker>
					</view>
				</view>
				<search-item v-for="(item,index) in searchForm" :key="index" :objInfo="item" @changeSearchData="changeSearchData"></search-item>
			</view>
		</scroll-view>
		<view class="button_bottom">
			<view @tap.stop="reset">重置</view>
			<view @tap.stop="sureQuery">确定</view>
		</view>
	</uni-popup>
	
	<select-contract ref="contractChild" @contractInfo="contractInfo"></select-contract>
	</view>
</template>

<script>
	import selectContract from '@/components/selectContract.vue'
	import searchItem from '@/components/search/searchitem.vue'
	
	export default{
		components:{
			selectContract,
			searchItem
		},
		props:{
			searchForm:{
				type:Array,
				default:[]
			}
		},
		data() {
			return{
				statusList:['待审核','审核通过','审核拒绝'],
				check_status:null,
				contractObj:null,
				start_time:'',
				end_time:'',
				showIndex:1,
			}
		},
		methods:{
			init(arr) {
				this.$refs.popup.open()
				if(arr && arr.length !=0 && this.showIndex == 1){
					this.start_time = arr[0]
					this.end_time = arr[1]
				}
				
			},
			close() {
				this.$refs.popup.close()
			},
			changeTab(e) {
				this.check_status = e.detail.value
			},
			toSelectContract() {
				this.$refs.contractChild.init()
			},
			contractInfo(obj) {
				this.contractObj = obj
			},
			changeStartTime(e) {
				this.showIndex = 2
				this.start_time = e.detail.value
				if(!this.end_time){
					this.end_time = e.detail.value
				}
			},
			changeEndTime(e) {
				this.showIndex = 2
				this.end_time = e.detail.value
				if(!this.start_time){
					this.start_time = e.detail.value
				}
			},
			changeSearchData(type,key,value){
				this.$emit('changeSearchData',type,key,value)
			},
			reset() {
				this.check_status = null
				this.contractObj = null
				this.end_time = ''
				this.start_time = ''
				this.$emit('resetForm')
			},
			sureQuery() {
				let params = {
					times:(this.start_time && this.end_time) ? (this.start_time + ',' + this.end_time) : '',
					check_status:this.check_status,
					contract_id: this.contractObj ? this.contractObj.id : '',
				}
				this.close()
				this.$emit('sureParams',params)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.screen_content {
		width:702rpx;
		z-index: 2;
		border-top:1rpx solid #CCCCCC;
		background-color: #fff;
		padding:24rpx;
		.fir_li{
			margin-bottom:20rpx;
			.li_label{
				font-size:28rpx;
				color:#333333;
				margin-bottom:15rpx;
			}
			.li_box{
				border-radius: 15rpx;
				border:1rpx solid #CCCCCC;
				height:60rpx;
				padding:0 35rpx;
				line-height: 60rpx;
			}
			.form_right {
				display: flex;
				color: #999;
				justify-content: space-between;
				image {
					width: 40rpx;
					height: 40rpx;
					margin: 28rpx 5rpx 0 0;
				}
				.rightinput{
					height:60rpx;
					line-height: 60rpx;
					width:100%;
				}
			}
		}
	}
	.button_bottom {
		display: flex;
		width: 100%;
		height: 90rpx;
		background-color: #fff;
		line-height: 90rpx;
		text-align: center;
		font-size: 32rpx;
		:first-child {
			flex: 1;
			color: $uni-text-color;
			border-top:1rpx solid #CCCCCC;
		}
		:last-child {
			flex: 1;
			background-color: $uni-text-color;
			color: #fff;
		}
	}
</style>