<template>
	<view>

		<block v-for="(item,index) in plist" :key="index">
			
			<view class="cu-card article no-card solid-bottom">
				<view class="cu-item shadow">
					<view class="title" @click="goDetail(item.article.id)"><view class="text-cut">{{item.article.title}}</view></view>
					<view class="content">
						<image :src="item.article.tilpic" mode="aspectFill" @click="goDetail(item.article.id)"></image>
						<view class="desc">
							<view class="text-content" @click="goDetail(item.article.id)">{{item.article.summary}}</view>
							<view class="flex justify-between">
								<view class="text-gray text-sm">收藏于：{{item.createtime}}</view>
								<view class="cu-tag bg-red light sm round" @click="delCollect(index)">删除</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</block>

		
		<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 {
				userinfo: {},
				
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function(){
			_this = this;
			_this.userinfo = _this.checkLogin("/pages/my/collect");
			_this.getMore();
		},
		onPullDownRefresh: function() {
			_this.ppage = 1;
			_this.pstatus = 'more';
			_this.plist = [];
			_this.getMore();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			getMore: function() {
				_this.$req.ajax({
					path: "my/listcollect",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						userid: _this.userinfo.id
					}
				}).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(articleid) {
				uni.navigateTo({
					url: '/pages/article/detail?articleid=' + articleid
				});
			},
			delCollect: function(index) {
				console.log("_this.plist[index].id: " + JSON.stringify(_this.plist[index].id));
				_this.$req.ajax({
					path: "my/delcollect",
					data: {
						id:  _this.plist[index].id,
						userid: _this.userinfo.id
					}
				}).then((data) => {
					uni.showModal({
						title: '信息提示',
						content: '收藏移除成功',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								_this.plist.splice(index, 1);
							}
						}
					});
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			}
		}
	}
</script>

<style>
</style>
