<template>
	<view style="background-color: #F1F2F8;">
		<tn-nav-bar :isBack="false" :bottomShadow="false" backgroundColor="#ffffff">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<view style="width: 100%;">
					<view
						style="text-align: center;font-size: 34rpx;color: #000000;letter-spacing: 1px;font-weight: bold;">
						<text>青企圈</text>
					</view>
				</view>
			</view>
		</tn-nav-bar>
		<view :style="{paddingTop: vuex_custom_bar_height + 'px'}" style="padding-bottom: 10rpx;">
			<view style="padding: 30rpx;" v-if="!none">
				<view style="background-color: #ffffff;border-radius: 20rpx;">
					<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between" style="padding: 30rpx;">
						<view style="font-size: 34rpx;font-weight: bold;">我发布的</view>
						<view>
							<tn-button @click="tn('/pages/packageB/paper/add')" padding="25rpx 30rpx"
								backgroundColor="rgba(48,86,211,0.1)" size="sm" fontColor="#3056D3" shape="round">
								<text class="tn-icon-add"></text>
								<text>发布</text>
							</tn-button>
						</view>
					</view>
					<scroll-view :scroll-x="true" style="padding:0rpx 30rpx;white-space: nowrap;width: 100%">
						<view v-for="(item,index) in my_list"
							style="width: 185rpx;;display: inline-block;text-align: center;background-color: #FFF;overflow: hidden;margin-right: 20rpx;">
							<view style="position: relative;">
								<image v-if="item.files.length>0" :src="apiImgUrl+item.files[0]" mode="aspectFill"
									style="border-radius: 20rpx;width: 185rpx;height: 185rpx;">
								</image>
								<view v-if="item.files.length==0&&index != 0"
									style="border-radius: 20rpx;width: 185rpx;height: 185rpx;background-color: rgba(24,24,24,0.3);display: inline-block;">
									<text style="color: #FFFFFF;line-height: 185rpx;">暂无图片</text>
								</view>
								<view @click="tn('/pages/packageA/user/my_add')" v-if="index == 0"
									style="border-radius: 20rpx;width: 185rpx;height: 185rpx;background: rgba(24,24,24,0.6);">
									<text style="color: #FFFFFF;line-height: 185rpx;">全部动态</text>
								</view>
							</view>
							<view style="padding:10rpx;font-weight: 400;min-height: 100rpx;">
								<view class="tn-text-ellipsis-2"
									style="font-weight: 500;text-align: left;font-size: 28rpx">
									<text>{{item.title}}</text>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
				<view style="background-color: #FFFFFF;margin-top: 20rpx;border-radius: 20rpx;">
					<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between" style="padding: 30rpx;">
						<view style="font-size: 34rpx;font-weight: bold;">圈子动态</view>
						<!-- <view style="color: #666666;">
							<text style="font-size: 28rpx;">全部资源</text>
							<text class="tn-icon-down-triangle"></text>
						</view> -->
					</view>
					<view v-for="(item,index) in list" style="padding:0rpx 30rpx;">
						<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between"
							style="width: 100%;">
							<view class="tn-flex tn-flex-center tn-flex-col-center" style="width: 100%;">
								<view @click="tn('/pages/packageA/user/my_card?id='+item.member.id)">
									<image v-if="item.member.photo_image==''||item.member.photo_image==null"
										src="/static/def.png" style="width: 100rpx;height: 100rpx;border-radius: 50%;">
									</image>
									<image v-if="item.member.photo_image!=''&&item.member.photo_image!=null"
										:src="apiImgUrl+item.member.photo_image"
										style="width: 100rpx;height: 100rpx;border-radius: 50%;"></image>
								</view>
								<view style="margin-left: 10rpx;width: 100%;">
									<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between">
										<view style="font-size: 30rpx;color: #181818;font-weight: bold;">
											<text
												style="vertical-align: middle;margin-right: 10rpx;">{{item.member.nikename}}</text>
											<!-- <tn-tag width="80rpx" shape="radius" size="sm" backgroundColor="#66B5FF"
												fontColor="#FFFFFF">供给
											</tn-tag> -->
										</view>
										<view>
											<tn-button @click="tn('/pages/packageA/user/my_card?id='+item.member.id)"
												padding="20rpx 20rpx" backgroundColor="rgba(48,86,211,0.1)" size="sm"
												fontColor="#3056D3" shape="round">
												<text style="font-size: 24rpx;">联系ta</text>
											</tn-button>
										</view>
									</view>
									<view class="tn-text-ellipsis"
										style="width: 380rpx;font-size: 26rpx;color: #666666;font-weight: 500;margin-top: 5rpx;">
										{{item.member.enterprise_name}}
									</view>
								</view>
							</view>

						</view>
						<view @click="tn('/pages/packageB/paper/paper_info?id='+item.id)" class="tn-text-ellipsis-2"
							style="font-size: 32rpx;font-weight: bold;margin-top: 20rpx;">
							{{item.title}}
						</view>
						<view @click="tn('/pages/packageB/paper/paper_info?id='+item.id)" class="tn-text-ellipsis-2"
							style="font-size: 28rpx;color: #666666;margin-top: 20rpx;">
							{{item.content}}
						</view>
						<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between"
							style="margin-top: 20rpx;">
							<view style="color: #AAAAAA;font-size: 24rpx;">
								发布于:{{item.createtime}}
							</view>
							<!-- <view style="color: #3056D3;font-size: 28rpx;font-weight: 500;">
								全文
							</view> -->
						</view>
						<view v-if="item.files.length>0" style="margin-top: 30rpx;">
							<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-wrap">
								<view class="tn-flex-basic-xs" v-for="(img,img_i) in item.files"
									style="text-align: center;">
									<view style="padding-right: 10rpx;">
										<image :src="apiImgUrl+img" @click="openImg(item,img_i)"
											style="width: 200rpx;height: 200rpx;border-radius:20rpx;">
										</image>
									</view>
								</view>
							</view>
						</view>
						<view style="margin-top: 20rpx;padding:30rpx;">
							<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between">
								<view style="text-align: center;font-size: 28rpx;">
									<button :data-item="item" hover-class="none" open-type="share">
										<text class="tn-icon-send" style="font-size: 32rpx;"></text>
										<text style="margin-left: 10rpx;">分享</text>
									</button>
								</view>
								<view style="text-align: center;font-size: 28rpx;" @click="like(index)">
									<text v-if="item.is_like==1" class="tn-icon-praise-fill tn-color-red"
										style="font-size: 32rpx;"></text>
									<text v-if="item.is_like==0" class="tn-icon-praise"
										style="font-size: 32rpx;"></text>
									<text style="margin-left: 10rpx;">{{item.like_num>0?item.like_num:'点赞'}}</text>
								</view>
								<view style="text-align: center;font-size: 28rpx;" @click="favs(index)">
									<text v-if="item.is_fav==1" class="tn-icon-star-fill tn-color-orangeyellow"
										style="font-size: 32rpx;"></text>
									<text v-if="item.is_fav==0" class="tn-icon-star" style="font-size: 32rpx;"></text>
									<text style="margin-left: 10rpx;">{{item.fav_num>0?item.fav_num:'收藏'}}</text>
								</view>
								<view style="text-align: center;font-size: 28rpx;">
									<text class="tn-icon-comment" style="font-size: 32rpx;"></text>
									<text
										style="margin-left: 10rpx;">{{item.comment_num>0?item.comment_num:'评论'}}</text>
								</view>
							</view>
						</view>
						<view v-if="index<list.length-1"
							style="height: 1px;border-top: #BABDC7 1px dashed;margin: 20rpx 0rpx;"></view>
					</view>
				</view>
			</view>
			<view style="padding: 30rpx;" v-if="none">
				<view
					style="background-color: #ffffff;border-radius: 20rpx;padding: 30rpx;text-align: center;font-size: 32rpx;font-weight: 600">
					请入会后查看！
				</view>
			</view>
		</view>
		<tn-modal v-model="sqMode" :custom="true">
			<view>
				<view style="text-align: center;color: #181818;font-size: 34rpx;font-weight: bold;">申请联系方式</view>
				<view style="color: #777777;font-size: 28rpx;margin-top: 20rpx;">
					点击确定按钮将发送联系方式的申请,等待对方同意后方可展示。且发送申请时,对方也将看到你的个人名片信息。
				</view>
				<view style="margin-top: 20rpx;">
					<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between" style="width: 100%;">
						<view class="tn-flex tn-flex-center tn-flex-col-center" style="width: 100%;">
							<view>
								<image src="/static/def.png" style="width: 100rpx;height: 100rpx;border-radius: 50%;">
								</image>
							</view>
							<view style="margin-left: 10rpx;width: 100%;">
								<view style="font-size: 32rpx;color: #181818;font-weight: bold;">
									<text style="vertical-align: middle;">石训</text>
									<tn-tag size="sm" padding="0px 5px" margin="0 0 0 10rpx" width="auto" shape="radius"
										backgroundColor="#F1F2F8" fontColor="#888888">135********
									</tn-tag>
								</view>
								<view class="tn-text-ellipsis"
									style="width: 380rpx;font-size: 26rpx;color: #666666;font-weight: 500;margin-top: 10rpx;">
									好想你健康食品股份有限公司
								</view>
							</view>
						</view>
					</view>
					<view class="tn-flex tn-flex-center tn-flex-row-between" style="margin-top: 40rpx;">
						<view>
							<tn-button @click="sqMode = false" width="250rpx" :plain="true" shape="round" size="lg"
								backgroundColor="#BABDC7" fontColor="#999999">取消
							</tn-button>
						</view>
						<view>
							<tn-button width="250rpx" shape="round" margin="0rpx 0 0 30rpx" size="lg"
								backgroundColor="#3056D3" fontColor="#ffffff">确定
							</tn-button>
						</view>
					</view>
				</view>
			</view>
		</tn-modal>
	</view>
</template>

<script>
	import {
		tweetsList,
		likeDo,
		favsDo,
		likeRevoke,
		favsRevoke
	} from '@/util/api.js';
	import store from '@/store/index.js'

	export default {
		data() {
			return {
				topCurrent: 0,
				list: [],
				apiImgUrl: this.$store.state.imgUrl,
				content: '',
				sqMode: false,
				page: 1,
				none: false,
				my_list: []
			}
		},
		mounted() {
			this.getTweetsList();
			this.getMyTweetsList();
		},
		methods: {
			getMyTweetsList() {
				tweetsList({
						me: 1,
						association_name: 1,
						page: this.page,
						state: 2,
						size: 10
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							this.my_list = res.data;
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			ReachBottom() {
				console.log('home');
				this.page = this.page + 1;
				this.getTweetsList();
			},
			openImg(item, index) {
				console.log(index);
				console.log(item.files);
				uni.previewImage({
					current: index,
					urls: item.files,
				});
			},
			switchTabbar(d) {
				console.log(d);
				store.commit('$tStore', {
					name: 'Gid',
					value: d.id
				})
				uni.setStorageSync('Gid', d.id);
				uni.$emit('getGid', {
					gid: d.id
				})
				uni.$emit('depId', {
					index: 0
				})
			},
			onsubmit() {
				this.page = 1;
				this.list = [];
				this.getAssociationIndex();
			},
			getTweetsList() {
				tweetsList({
						association_name: 1,
						page: this.page,
						size: 10
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							this.none = false;
							this.list.push(...res.data);
						} else {
							this.none = true;
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},

			like(index) {
				var uid = uni.getStorageSync('uid');
				if (!uid) {
					uni.showToast({
						title: '请先登录',
						icon: 'none',
						duration: 2000
					});
					return;
				}
				var info = this.list[index];
				if (info.is_like == 0) {
					likeDo({
							member_id: uid,
							related_id: info.id,
							related_type: 'tweets',
							member_b_id: info.member_id,
						})
						.then(res => {
							console.log(res);
							uni.showToast({
								title: '赞成功！',
								icon: 'none',
								duration: 2000
							});
							this.list[index].is_like = 1;
						})
						.catch(error => {
							uni.showToast({
								title: error,
								icon: 'none',
								duration: 2000
							});
						})
				} else {
					likeRevoke({
							member_id: uid,
							related_id: info.id,
							related_type: 'tweets',
							member_b_id: info.member_id,
						})
						.then(res => {
							console.log(res);
							uni.showToast({
								title: '取消成功！',
								icon: 'none',
								duration: 2000
							});
							this.list[index].is_like = 0;
						})
						.catch(error => {
							uni.showToast({
								title: error,
								icon: 'none',
								duration: 2000
							});
						})
				}

			},
			favs(index) {
				var uid = uni.getStorageSync('uid');
				if (!uid) {
					uni.showToast({
						title: '请先登录',
						icon: 'none',
						duration: 2000
					});
					return;
				}
				var info = this.list[index];
				console.log(info);
				if (info.is_fav == 0) {
					favsDo({
							member_id: uid,
							related_id: info.id,
							related_type: 'tweets',
							member_b_id: info.member_id,
						})
						.then(res => {
							console.log(res);
							uni.showToast({
								title: '收藏成功！',
								icon: 'none',
								duration: 2000
							});
							this.list[index].is_fav = 1;
						})
						.catch(error => {
							uni.showToast({
								title: error,
								icon: 'none',
								duration: 2000
							});
						})
				} else {
					favsRevoke({
							member_id: uid,
							related_id: info.id,
							related_type: 'tweets',
							member_b_id: info.member_id,
						})
						.then(res => {
							console.log(res);
							uni.showToast({
								title: '取消收藏成功！',
								icon: 'none',
								duration: 2000
							});
							this.list[index].is_fav = 0;
						})
						.catch(error => {
							uni.showToast({
								title: error,
								icon: 'none',
								duration: 2000
							});
						})
				}

			},
			tn(e) {
				uni.navigateTo({
					url: e
				})
			}
		}
	}
</script>

<style>
	.triangle {
		width: 0;
		height: 0;
		border-top: 20rpx solid #13C296;
		border-right: 20rpx solid transparent;
		border-left: 20rpx solid transparent;
		position: absolute;
		left: 0;
		right: 0;
		margin: 0 auto;
		bottom: -12rpx;
		z-index: 100;
	}

	button::after {
		border: none;
	}

	button {
		position: relative;
		display: block;
		margin-left: auto;
		margin-right: auto;
		padding-left: 0px;
		padding-right: 0px;
		box-sizing: border-box;
		text-align: center;
		text-decoration: none;
		line-height: 1.35;
		-webkit-tap-highlight-color: transparent;
		overflow: hidden;
		background-color: transparent;
		font-size: 28rpx;
		width: 100%;
		height: 100%;
	}
</style>