<template>
	<view class="">
		<uni-popup ref="leadPopup" type="top" background-color="#fff">
			<scroll-view scroll-y class="scrollbox" style="height:800rpx;background:#fff;">
				<!--筛选模块  -->
				<view class="screen_content">
					<view class="fir_li">
						<view class="li_label">归属人</view>
						<view class="li_box" @click="toSelectStaff">
							<view class="form_right">
								<view :class="staffObj ? 'valueactive' : '' ">
									{{staffObj ? staffObj.name : '点击选择'}}</view>
								<view class="iconfont icon-arrows_right"></view>
							</view>
						</view>
					</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-staff ref="staffChild" @sureStaff="sureStaff"></select-staff>
	</view>
</template>

<script>
	import selectStaff from '@/components/selectStaff.vue'
	import searchItem from '@/components/search/searchitem.vue'
	
	export default{
		components:{
			selectStaff,
			searchItem
		},
		props:{
			searchForm:{
				type:Array,
				default:[]
			}
		},
		data() {
			return{
				staffObj:null,
				start_time: '',
				end_time: '',
			}
		},
		methods:{
			init(obj) {
				this.start_time = obj.start_time
				this.end_time = obj.end_time
				this.$refs.leadPopup.open()
			},
			changeSearchData(type,key,value){
				this.$emit('changeSearchData',type,key,value)
			},
			//选择归属人
			toSelectStaff() {
				this.$refs.staffChild.init()
			},
			sureStaff(obj) {
				this.staffObj = obj
			},
			//线索创建  开始时间
			changeStartTime(e) {
				this.start_time = e.detail.value
				if(!this.end_time){
					this.end_time = e.detail.value
				}
			},
			//线索 创建  结束时间
			changeEndTime(e) {
				this.end_time = e.detail.value
				if(!this.start_time){
					this.start_time = e.detail.value
				}
			},
			//重置
			reset() {
				this.start_time = ''
				this.end_time = ''
				this.staffObj = null
				this.$emit('resetForm')
			},
			sureQuery() {
				let params = {
					createtime: (this.start_time && this.end_time) ? (this.start_time + ',' + this.end_time) : '',
					staff_id: this.staffObj?this.staffObj.id:'',
				}
				this.$refs.leadPopup.close()
				this.$emit('sureParams',params)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.screen_content {
		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;
				}
	
			}
		}
	}
	.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>