<template>
	<view class="main pageBg">
		<view class="topBg">
			<topNavbar title="考场信息"></topNavbar>
			<view class="pad">
				<view class="searchBox">
					<searchRow placeholder="搜索考场名称" @searchFn="searchFn"></searchRow>
				</view>
				<view class="tabs">
					<view class="tab" v-for="(item,index) in tabData" :key="index" :class="{active: params.siteType==item.id}" @click="changeTab(item)">{{ item.text }}</view>
				</view>
			</view>
		</view>
		<view class="pad" style="margin-top: 20rpx;">
			<view class="list">
				<view class="card" v-for="(item,index) in list" :key="index">
					<examinItem :item="item"/>
				</view>
			</view>
			<view style="padding-bottom: 20rpx;" v-if="list.length">
				<u-loadmore :status="status" />
			</view>
			<nodata v-if="!list.length&&status=='nomore'"></nodata>
		</view>
	</view>
</template>

<script>
	import examinItem from './comp/examinItem'
	import { businessSitePage } from '@/config/api.js'
	export default {
		components: { examinItem },
		data() {
			return {
				tabData: [
					{text: '全部', id: 0},
					{text: '理论', id: 1},
					{text: '科目二', id: 2},
					{text: '科目三', id: 3},
				],
				params: {
					pageSize: 20,
					pageNo: 1,
					schoolId: '',
					siteType: '',//1.理论 2.科目二 3.科目三 4.科目二/科目三
				},
				total: 20,
				list: [],
				status: 'loading'
			}
		},
		onLoad() {
			this.params.schoolId = this.vuex_schoolId
			this.businessSitePageFn()
		},
		onPullDownRefresh() {
			this.initList()
		},
		onReachBottom() {
			if(this.total>this.list.length) this.businessSitePageFn()
		},
		methods: {
			initList() {
				this.params.pageNo = 1
				this.list = []
				this.status = 'loading'
				this.businessSitePageFn()
			},
			async businessSitePageFn() {
				let obj = Object.assign({},this.params)
				const {data: res} = await businessSitePage(obj)
				this.params.pageNo ++
				this.list.push(...res.list)
				this.total = res.total
				if(this.list.length>=this.total) {
					this.status = 'nomore' 
				}
			},
			searchFn(val) {
				this.params.name = val
				this.initList()
			},
			changeTab(item) {
				this.params.siteType = item.id
				this.initList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.topBg {
		background: #1989fa;
	}
	.card {
		padding: 32rpx 36rpx 26rpx 24rpx;
		margin-bottom: 20rpx;
	}
	.searchBox {
		padding: 20rpx 0 0rpx 0;
	}
	.tabs {
		display: flex;
		justify-content: space-between;
		height: 120rpx;
		align-items: center;
		.tab {
			font-size: 28rpx;
			color: #fff;
			line-height: 110rpx;
			&.active {
				position: relative;
				&::before {
					content: '';
					width: 56rpx;
					height: 6rpx;
					background: #FFFFFF;
					border-radius: 3rpx;
					position: absolute;
					left: 50%;
					transform: translateX(-50%);
					bottom: 20rpx;
				}
			}
		}
	}
</style>