<template>
	<view class="container">
		<u-modal cancel-text="重置" cancel-color="#000000" @cancel="filterReset" :show-cancel-button="true"  @confirm="filterConfirm" title="筛选" :mask-close-able="true" v-model="filterShow" >
			<view class="slot-content" style="margin: 20rpx;">
				<u-form label-width="150"  ref="uForm">
					<u-form-item label="主键id" v-if="!$isEmpty(params.id)"><u-input v-model="params.id" disabled /></u-form-item>
					<u-form-item label="访客姓名"><u-input v-model="params.guestName" /></u-form-item>
					<u-form-item :border-bottom="false" label="手机号"><u-input v-model="params.guestTel" type="number"  /></u-form-item>
				</u-form>
			</view>
		</u-modal>
		<view class="tabs flex flex-direction">
			<view class="flex">
				<scroll-view scroll-x class="bg-white nav" >
					<view class="flex text-center">
						<view class="cu-item flex-sub" :class="index==current?'text-blue text-xl text-bold ':'text-lg'" v-for="(item,index) in tabs" :key="index" @tap="tabChange(index)" >
							<text>{{item.name}}</text>
						</view>
					</view>
				</scroll-view>
				<view class="flex justify-center align-center padding-right-20" style="flex: 10%;"  @click="show">
					<text class="cuIcon-filter "  style="font-size: 40rpx;"></text>
					<u-badge size="mini" type="error" :count="filterCount"></u-badge>
				</view>
			</view>
		</view>
		<view style="height: 100%;">
			<swiper style="height: 100%;" :current="current"  @change="swiperChange"
				@animationfinish="animationfinish">
				<swiper-item  v-for="(item, index) in tabs" :key="index">
					<scroll-view scroll-y style="height: 100%;">
						<item @showDetail="showDetail" ref="mescrollItem" :params="params" :i="index" :item="item" :type="current"></item>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>
<script>
	import item from "./item.vue"
	export default {
		components: {
			item
		},
		data() {
			return {
				
				filterCount:0,
				filterShow:false,
				params:{},
				
				current: 0,
				swiperCurrent:0,
				tabs: [
					{
						name: '全部',
						value:-1
					},
					{
						name: '待审核',
						value:0,
					},
					{
						name: '已通过',
						value:1
					},
					{
						name:'未通过',
						value:2
					}
				],
			}
		},
		onShow(){
			
		},
		onLoad(options) {
			this.params.id=options.id
			this.getFilterCount()
		},
		methods:{
			/**
			 * 审核不通过时显示弹出框
			 * @param {Object} item
			 */
			fail(item){
				
			},
			/**
			 * 显示筛选弹窗
			 */
			show(){
				this.filterShow=true
			},
			/**
			 * 筛选
			 */
			filterConfirm(){
				this.$nextTick(() => {
					this.refreshMescroll()
				})
				this.getFilterCount()
				
			},
			/**
			 * 计算筛选的数量
			 */
			getFilterCount(){
				let n=0
				if (!this.$isEmpty(this.params.id)) {
					n++
				}
				if (!this.$isEmpty(this.params.guestName)) {
					n++
				}
				if (!this.$isEmpty(this.params.guestTel)) {
					n++
				}
				this.filterCount=n
			},
			/**
			 * 重置筛选项
			 */
			filterReset(){
				this.filterCount=0
				this.params={}
				this.$nextTick(() => {
					this.refreshMescroll()
				})
			},
			/**
			 * 刷新列表
			 */
			refreshMescroll(){
				let curMescroll = this.getMescroll(this.current)
				curMescroll && curMescroll.resetUpScroll()
			},
			/**
			 * 获取Mescroll对象
			 * @param {Object} i
			 */
			getMescroll(i){
				let mescrollItems = this.$refs.mescrollItem;
				if(mescrollItems){
					let item = mescrollItems[i]
					if(item) return item.mescroll
				}
				return null
			},
			
			tabChange(index) {
				this.current = index
			},
			swiperChange(e) {
			  uni.pageScrollTo({
			      scrollTop: 0,
			      duration: 0
			  });
			  this.current = e.detail.current
			},
			animationfinish({detail: { current }}) {
				this.swiperCurrent = current;
				this.current = current;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.text-xl{
		font-size: 34rpx;
	}
	.container {
	  height: calc(100vh);
	  background-color: #F6F6F6;
	  padding: 78rpx 0rpx 0rpx;
	 .tabs {
	    position: fixed;
	    top: -2rpx;
		left: 0;
		width: 100%;
		background-color: #FFFFFF;
		box-sizing: border-box;
		z-index: 3;
	  }
}
</style>