<template>
	<view class="pageBg">
		<view class="infoBox pad">
			<info :showSign="true" :coachList="coachList"></info>
		</view>
		<comments :list="list" @changeNav="changeNav"></comments>
		<view style="padding-bottom: 20rpx;" v-if="list.length">
			<u-loadmore :status="status" />
		</view>
		<nodata v-if="!list.length&&status=='nomore'"></nodata>
	</view>
</template>

<script>
	import comments from '../comments/comments.vue'
	import info from '../shcoolDetail/comp/tab3.vue'
	import { getListCoachComment } from '@/config/api.js'
	export default {
		components: { comments, info},
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 20,
					coachId: '',
					condition: 0
				},
				total: 20,
				list: [],
				coachList: [],
				status: 'loading'
			}
		},
		onLoad(options) {
			if(!options.item) return
			let coachInfo = JSON.parse(decodeURIComponent(options.item))
			console.log(coachInfo)
			this.coachList = [coachInfo]
			this.params.coachId = coachInfo.coachId
			this.getListCoachCommentFn()
		},
		methods: {
			changeNav(val) {
				this.params.condition = val
				this.initList()
			},
			initList() {
				this.params.pageNo = 1
				this.status = 'loading'
				this.list = []
				this.getListCoachCommentFn()
			},
			async getListCoachCommentFn() {
				const {data: res} = await getListCoachComment(this.params)
				this.params.pageNo ++
				this.total = res.total
				let arr = res.list.map(item=>{
					if(item.images) {
						item.images = item.images.split(',')
					}
					return item
				})
				this.list.push(...arr)
				if(this.list.length>=this.list.length) this.status = 'nomore'
			}
		}
	}
</script>

<style lang="scss" scoped>
	.infoBox {
		background: #F6F6F6;
		overflow: hidden;
	}
</style>