<template>
	<view class="list">
		<template v-if="cid == 11">
			<view class="order-item" @click="ToDetail(1)">
				<view class="list-cell">
					<image class="image" src="../../static/img/personal.jpg"></image>
					<view class="list-tpl">个人会员报名</view>
				</view>
			</view>
			<view class="order-item" @click="ToDetail(2)">
				<view class="list-cell">
					<image class="image" src="../../static/img/group.jpg"></image>
					<view class="list-tpl">团队会员报名</view>
				</view>
			</view>
		</template>
		<template v-if="cid == 12">
			<view class="order-item" @click="ToDetail(3)">
				<view class="list-cell">
					<image class="image" src="../../static/img/zffw.jpg"></image>
					<view class="list-tpl">志愿服务报名</view>
				</view>
			</view>
		</template>
		<template v-if="cid != 11 && cid != 12">
			<empty v-if="loaded && list.length==0"></empty>
		</template>
		<view class="list-item" v-for="item in list" @click="navTo('/pages/article/detail?id=' + item.id)">
			<view class="article-tit">{{item.title}}</view>
			<view class="article-time">{{item.release_time}}</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
	
</template>

<script>
	import empty from '../../components/empty.vue'
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import { getArticleList } from '../../api/index.js'
	export default {
		components: {
			uniLoadMore,
			empty
		},
		data() {
			return {
				cid: '',
				list: [],
				page: 1,
				limit: 10,
				loadingType: 'more',
				loaded: false
			}
		},
		onLoad(opt) {
			if(opt.cid) {
				this.cid = opt.cid
			}
			this.getList()
		},
		methods: {
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			getList() {
				let obj =this
				if(obj.loadingType == 'loading' || obj.loadingType == 'noMore') {
					return 
				}
				obj.loadingType = 'loading'
				getArticleList({
					page: obj.page,
					limit: obj.limit
				},obj.cid).then( ({data}) => {
					console.log(data)
					obj.list = obj.list.concat(data.list)
					obj.page++
					if(data.length == obj.limit) {
						obj.loadingType = 'more'
					}else {
						obj.loadingType = 'noMore'
					}
					obj.$set(obj,'loaded',true)
				})
			},
			//跳转到详情
			ToDetail(index) {
				if(index == 1) {
					uni.navigateTo({
						url: '/pages/cart/personal'
					})
				}
				if(index == 2) {
					uni.navigateTo({
						url: '/pages/cart/group'
					})
				}
				if(index == 3) {
					uni.navigateTo({
						url: '/pages/form/tovolApply'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list-item {
		border-bottom: 1px solid #ccc;
		border-top: 1px solid #ccc;
		padding:20rpx 35rpx;
		line-height: 1.5;
		.article-tit {
			font-size: 34rpx;
			color: #000000;
			font-weight: 500;
			letter-spacing: 3rpx;
		}
		.article-time {
			font-size: 28rpx;
			color: #888;
			font-weight: 500;
		}
	}
	.order-item {
		width: 100%;
		padding: 0rpx 25rpx;
		padding-top: 25rpx !important;
		.list-cell {
			background-color: #ffffff;
			border-radius: 20rpx;
			width: 100%;
			box-shadow: 0px 0px 40px 0px rgba(0, 0, 0, 0.06);
			.image {
				width: 100%;
				height: 300rpx;
				border-top-left-radius: 25rpx;
				border-top-right-radius: 25rpx;
			}
			.list-tpl {
				padding: 25rpx 25rpx;
				padding-bottom: 35rpx !important;
				font-size: 34rpx;
				color: #222222;
				font-weight:500;
			}
		}
	}
</style>
