<template>
	<view>

		<scroll-view scroll-x class="bg-white nav text-center echo-fixed-top">
			<view class="cu-item" :class="item.id==cateid?'text-green cur':''" v-for="(item, index) in allcate" :key="item.id" @tap="tabSelect" :data-id="item.id">
				{{item.title}}
			</view>
		</scroll-view>
		<view class="echo-fixed-top-empty"></view>
		
		<view class="uni-list echo-media-list">
			<block v-for="(item,index) in plist" :key="index">
				<view class="uni-list-cell" hover-class="uni-list-cell-hover" @click="goDetail(item.id)">
					<view class="uni-media-list">
						<view class="uni-media-list-body">
							<view class="uni-media-list-text-top text-cut">{{item.title}}</view>
							<view class="uni-media-list-text-bottom flex justify-between">
								<text>{{item.createtime_text}}</text>
								<text class="text-red" v-if="item.priority>0">置顶</text>
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		
		<uni-load-more :status="pstatus"></uni-load-more>
		
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				cateid: 0,
				allcate: [],
				
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function(option){
			_this = this;
			_this.cateid = option.cateid || 0;
			_this.$req.ajax({
				path: "question/allcate"
			}).then((data) => {
				_this.allcate = data.allcate;
				_this.getMore();
			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false
				});
			});
		},
		onShareAppMessage: function(res) {
		    return {
				title: "常见问题",
				path: "/pages/question/question"
		    }
		},
		onPullDownRefresh: function() {
			_this.ppage = 1;
			_this.pstatus = 'more';
			_this.plist = [];
			_this.getMore();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			tabSelect: function(e) {
				_this.cateid = e.currentTarget.dataset.id;
				_this.pageRefresh();
			},
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			getMore: function() {
				_this.$req.ajax({
					path: "question/listquestion",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						cateid: _this.cateid
					}
				}).then((data) => {
					_this.pstatus = data.pstatus;
					_this.plist = _this.plist.concat(data.plist);
					_this.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			goDetail: function(questionid) {
				uni.navigateTo({
					url: '/pages/question/detail?questionid=' + questionid
				});
			}
		}
	}
</script>

<style>
</style>
