<template>
	<view class="pageBg">
		<view class="topBg">
			<topNavbar title="找教练"></topNavbar>
			
			<view class="searchCon pad">
				<searchRow placeholder="搜索教练名称" @searchFn="searchFn" ></searchRow>
			</view>
		</view>
		<view class="pad">
			<view class="ul">
				<view class="li" v-for="(item,index) in listData" :key="index" >
					<coachItem :item="item"  @click.native="goPage(item)"/>
				</view>
			</view>
		</view>
		<view style="padding-bottom: 20rpx;" v-if="listData.length">
			<u-loadmore :status="status" />
		</view>
		<nodata v-if="!listData.length&&status=='nomore'"></nodata>
	</view>
</template>

<script>
	import coachItem from './comp/coachItem.vue'
	import { coachPage } from '@/config/api.js'
	export default {
		components: { coachItem },
		data() {
			return {
				currentTab: 0,
				tabData: [{
						text: '全部',
						id: 1
					},
					{
						text: 'C1',
						id: 2
					},
					{
						text: 'C2',
						id: 3
					},
				],
				params: {
					pageNo: 1,
					pageSize: 20,
					name: ''
				},
				total: 20,
				listData: [],
				status: 'loading'
			}
		},
		onLoad() {
			// let vuex_cityInfo = this.$store.state.user.vuex_cityInfo
			// if(!vuex_cityInfo.lat) {
			// 	this.$store.dispatch('getCity')
			// }else {
			// 	this.params.lat = vuex_cityInfo.lat
			// 	this.params.lng = vuex_cityInfo.lng
			// }
			this.coachPageFn()
			uni.$on('screenConfirm',(obj)=>{
				this.params = Object.assign(this.params, obj)
				this.listInit()
			})
		},
		onPullDownRefresh() {
			this.listInit()
		},
		onReachBottom() {
			if(this.total>this.listData.length) {
				this.coachPageFn()
			}
		},
		methods: {
			searchFn(val) {
				this.params.name = val
				this.listInit()
			},
			goPage(item) {
				let objStr = encodeURIComponent(JSON.stringify(item))
				this.$goPage('/pages/indexEntry/findShcool/coachComment/coachComment?item='+ objStr)
			},
			tabClick(item) {
				this.params.sercheType = item.id
				this.params.businessScope = ''
				this.params.district = ''
				this.listInit()
			},
			async listInit() {
				this.listData = []
				this.params.pageNo = 1
				await this.coachPageFn()
				uni.stopPullDownRefresh()
			},
			// 获取驾校列表
			async coachPageFn() {
				let obj = {}
				for(let key in this.params) {
					if(this.params[key]) {
						obj[key] = this.params[key]
					}
				}
				const {data: res} = await coachPage(obj)
				this.params.pageNo ++
				this.listData.push(...res.list)
				this.total = res.total
				if(this.listData.length>=this.total) this.status = 'nomore'
				console.log(res)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pageBg {
		width: 100%;
		.navBox {
			display: flex;
			// justify-content: space-between;
			padding: 20rpx 0;
			.tab {
				font-size: 28rpx;
				color: #999;
				line-height: 50rpx;
				border-radius: 10rpx;
				background: #fff;
				text-align: center;
				height: 50rpx;
				width: 126rpx;
				margin-right: 30rpx;
				&.active {
					background: $themC;
					color: #fff;
				}

			}

			.screen {
				width: 150rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				position: relative;
				background: #fff;
				color: #999;
				border-radius: 10rpx;
				&.active {
					background: $themC;
					color: #fff;
				}
				.txt {
					font-size: 28rpx;
					margin-right: 10rpx;
				}

				.screenIcon {
					width: 18rpx;
					height: 12rpx;
				}
			}
		}

		.ul {
			width: 100%;
			.li {
				
				
			}
		}
	}
	.topBg {
		padding-bottom: 20rpx;
	}
</style>