<template>
	<view class="center">
		<view v-for="(item,index) in problemList" :key="index">
			<view class="title">{{item.title}}</view>
			<view class="content">{{item.content}}</view>
			<view class="reply">{{item.reply}}</view>
		</view>
		<view class="buttom" @click="nav('/pages/problem/problemAdd')">
			新增问题
		</view>
	</view>
</template>

<script>
import { getProblem } from '@/api/problem.js' 
export default {
	data(){
		return{
			page: 1,
			limit: 10,
			loadingType: 'more',
			problemList:[]
		}
	},
	onLoad() {
		this.loadData()
	},
	//下拉刷新
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	//监听页面是否滚动到底部加载更多
	onReachBottom() {
		this.loadData();
	},
	methods: {
		async loadData(type = 'add', loading){
			let obj = this;
			if (type === 'add') {
				if (obj.loadingType === 'nomore') {
					return;
				}
				obj.loadingType = 'loading';
			} else {
				obj.loadingType = 'more';
			}
			if (type === 'refresh') {
				// 清空数组
				obj.courseList = [];
				obj.page = 1
			}
			//获取反馈列表
			getProblem({
				page: obj.page,
				limit: obj.limit
			}).then(e => {
				obj.problemList = obj.problemList.concat(e.data.data);
				console.log(obj.problemList);
				//判断是否还有下一页，有是more  没有是nomore
				if (obj.limit==e.data.length) {
					obj.page++
					obj.loadingType='more'
				} else{
					obj.loadingType='nomore'
				}
				if (type === 'refresh') {
					if (loading == 1) {
						uni.hideLoading();
					} else {
						uni.stopPullDownRefresh();
					}
				}
			})
		},
		nav(url) {
			uni.navigateTo({
				url: url
			})
		}
	}
}
</script>

<style>
</style>
