<template>
	<view class="main">
		<comments :list="list" @changeNav="changeNav"></comments>
		<view style="padding-bottom: 20rpx;">
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	import comments from '../comments/comments.vue'
	import { getSchoolListComment } from '@/config/api.js'
	export default {
		components: { comments },
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 20,
					schoolId: '',
					condition: 0
				},
				total: 20,
				list: [],
				status: 'loading'
			}
		},
		onLoad(options) {
			this.params.schoolId = options.id
			this.getSchoolListCommentFn()
		},
		onPullDownRefresh() {
			this.getSchoolListCommentFn().then(()=>{
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			if(this.list.length>this.total) this.getSchoolListCommentFn()
		},
		methods: {
			changeNav(val) {
				this.params.condition = val
				this.initList()
			},
			initList() {
				this.params.pageNo = 1
				this.status = 'loading'
				this.list = []
			},
			async getSchoolListCommentFn() {
				const {data: res} = await getSchoolListComment(this.params)
				this.params.pageNo ++
				let arr = res.list.map(item=>{
					if(item.images) {
						item.images = item.images.split(',')
					}
					return item
				})
				this.list.push(...arr)
				this.total = res.total
				if(this.list.length>=this.total) this.status = 'nomore'
			}
		}
	}
</script>

<style>
</style>