<template>
	<view class="step2">
		<searchBox placeholder="搜索教练姓名或手机号"  @searchFn="searchFn"></searchBox>
		<view class="card" v-for="(item,index) in list" :key="index" :class="{active: curData.coachId==item.coachId}" @click="chooseCoach(item)">
			<view class="icon">
				<image src="@/static/images/index/radio_cli.png" mode="" v-if="curData.coachId==item.coachId"></image>
				<image src="@/static/images/index/radio_nor.png" mode="" v-else></image>
			</view>
			<view class="name">
				{{item.name}} <text>{{item.mobile}}</text>
			</view>
		</view>
		<view class="poz_btn">
			<view class="btn_row" >
				<view class="border btn" @click="changeStep(0)">返回上一步</view>
				<view class="btn"  @click="changeStep(1)">下一步</view>
			</view>
		</view>
	</view>
</template>

<script>
	import searchBox from './searchBox'
	import { coachPage } from '@/config/api.js'
	export default {
		props: ['FormData'],
		components: { searchBox },
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 20,
					schoolId: '',
					name: '',
					teachType: '4',//准教类型（1：理论，2：模拟，4：实操，
					employStatus: 0,
					otherCoach: true
					
				},
				status: 'loading',
				list: [],
				total: 20,
				curData:{}
			}
		},
		created() {
			this.params.schoolId = this.vuex_userInfo.schoolId
			this.coachPageFn()
		},
		methods: {
			changeStep(val) {
				if(val) {
					this.$emit('updatedForm', Object.assign({}, this.FormData, this.curData))
				}
				this.$emit('changeStep', 1)
			},
			addCoachPage() {
				if(this.total>this.list.length) {
					this.coachPageFn()
				}
			},
			// 获取教练
			async coachPageFn() {
				const {data:res} = await coachPage(this.params)
				this.list.push(...res.list)
				this.params.pageNo ++
				this.total = res.total
				if(this.list.length>=this.total) {
					this.status = 'nomore'
				}
				console.log('获取教练')
				console.log(this.list)
			},
			searchFn(val) {
				this.params.name = val
				this.list = []
				this.params.pageNo = 1
				this.coachPageFn()
			},
			chooseCoach(item) {
				console.log(item)
				this.curData = {
					coachId: item.coachId,
					coachName: item.name,
					photoPath: item.photoPath
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.poz_btn {
		position: fixed;
		bottom: 0;
		left: 0;
		padding: 12rpx 32rpx;
		width: 100%;
		background: #F6F6F6;
	}
	.step2 {
		width: 100%;
		padding-bottom: 120rpx;
		.card {
			padding: 28rpx 36rpx;
			display: flex;
			align-items: center;
			margin-bottom: 20rpx;
			height: 100rpx;
			.name {
				font-size: 26rpx;
				color: #333;
				margin-left: 16rpx;
				text {
					margin-left: 10rpx;
				}
			}
			.icon {
				width: 30rpx;
				height: 30rpx;
			}
		}
	}
	.btn_row {
		display: flex;
		justify-content: space-between;
		padding-bottom: 20rpx;
		.btn {
			width: 47%;
			height: 72rpx;
			background: #1989FA;
			border-radius: 8rpx;
			font-size: 28rpx;
			color: #fff;
			text-align: center;
			line-height: 72rpx;
	
			&.border {
				background: rgba(25, 137, 250, 0.1);
				border: 2rpx solid $themC;
				color: $themC;
			}
		}
	}
</style>