<template>
	<view style="background-color: #F1F2F8;letter-spacing: 1rpx;min-height: 100vh;">
		<tn-nav-bar :isBack="false" backTitle="" :bottomShadow="false" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<view style="padding-left: 15rpx;" @click="goBack()">
					<text class="tn-icon-left" style="font-size: 40rpx;"></text>
				</view>
				<view style="width: 83%;font-weight: bold;">
					<text>我的收藏</text>
				</view>
			</view>
		</tn-nav-bar>
		<view :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view style="background-color: #FFFFFF;">
				<tn-tabs :list="tab_list" :current="current" :isScroll="false" name="name" activeColor="#000000"
					inactiveColor="#999999" :barWidth="25" @change="change"></tn-tabs>
			</view>
			<view style="padding: 30rpx;">
				<view v-for="(item,index) in list"
					style="background-color: #FFF;border-radius: 20rpx;margin-bottom: 20rpx;">
					<view style="padding: 20rpx">
						<view>
							<view
								@click="openUrl(current==0?'/pages/packageB/event/event_info?id='+item.id:'/pages/packageB/paper/paper_info?id='+item.id)"
								style="background-color: #FFF;border-radius: 20rpx;">
								<view class="tn-flex" style="position: relative;">
									<view style="margin-left: 10rpx;" v-if="item.related_object.cover!=''">
										<image :src="apiImgUrl+item.related_object.cover" mode="aspectFill"
											style="width: 250rpx;height: 180rpx;border-radius: 10rpx;"></image>
									</view>
									<view style="margin-left: 20rpx;">
										<view class="tn-text-ellipsis-2" style="font-size: 32rpx;font-weight: bold;">
											{{item.related_object.title}}
										</view>
										<view class="tn-text-ellipsis-2" style="font-size: 24rpx;margin-top: 20rpx;">
											{{item.related_object.content}}
										</view>
										<view style="font-size: 24rpx;margin-top: 20rpx;color: #999999;">
											{{item.createtime}}
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		associationInfo,
		favsIndex,
	} from "@/util/api";
	import store from "@/store";

	export default {
		data() {
			return {
				current: 0,
				tab_list: [{
					type: 'article',
					name: '活动'
				}, {
					type: 'tweets',
					name: '动态'
				}],
				list: [],
				page: 1,
				apiImgUrl: this.$store.state.imgUrl
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			change(d) {
				this.page = 1;
				this.list = [];
				this.current = d;
				this.getList();
			},
			getList() {
				var uid = uni.getStorageSync('uid');
				var nw_type = this.tab_list[this.current].type;
				favsIndex({
						association_id: 1,
						page: this.page,
						size: 10,
						type: nw_type
					})
					.then(res => {
						console.log(res);
						this.list.push(...res.data.data);
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			openUrl(ulr) {
				uni.navigateTo({
					url: ulr
				})
			},
			goBack() {
				if (getCurrentPages().length > 1) {
					uni.navigateBack()
				} else {
					uni.redirectTo({
						url: '/pages/index/index'
					})

				}
			}
		}
	}
</script>

<style>

</style>