<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: "notice/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/notice/notice"
		    }
		},
		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: "notice/listnotice",
					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(noticeid) {
				uni.navigateTo({
					url: '/pages/notice/detail?noticeid=' + noticeid
				});
			}
		}
	}
</script>

<style>
</style>
