<template>
	<view class="quanzi-info">
		<image v-if="detail.image" :src="detail.image" class="quanzi-top" mode="aspectFill"></image>
		<image v-else src="static/quanzi-top.png" class="quanzi-top" mode=""></image>
		<u-navbar :fixed="false" bgColor='rgba(0,0,0,0)' placeholder :safeAreaInsetTop="true"></u-navbar>
		<view class="quanzi-header u-flex-col u-row-center">
			<view class="header-top u-flex">
				<image src="static/quanzi-img.png" mode=""></image>
				<text class="u-flex-1 u-line-1">#{{detail.title || ''}}</text>
			</view>
			<view class="header-down u-flex u-row-between">
				<view class="u-flex">
					<text class="text1">{{detail.article_count || 0}}</text>
					<text class="text2">条帖子</text>
					<text class="text3"></text>
					<text class="text1">{{detail.follow_count || 0}}</text>
					<text class="text2">关注</text>
				</view>
				<view v-if="detail.is_follow" @click="guanzhuquanzi" class="down-guanzhu1 u-flex u-row-center">
					已关注
				</view>
				<view v-else @click="guanzhuquanzi" class="down-guanzhu u-flex u-row-center">
					<image src="static/plus.png" mode=""></image>
					<text>关注圈子</text>
				</view>
			</view>
		</view>
		<view class="quanzi-title u-flex u-row-between">
			<text class="text">动态</text>
			<view class="subsection" style="width: 182rpx;">
				<u-subsection style="border: 0 solid #fff;" mode="button"  fontSize="12" :list="tabslist" bgColor="#ECECEC"
					:current="current" @change="changetabs"></u-subsection>
			</view>

		</view>
		<view v-for="(item,index) in list" :key="index" @click="toinfo(item)">
			<view class="luntan-item">
				<view class="luntan-user u-flex u-row-between">
					<image class="user-head" @click.stop="touser(item)" :src="item.userinfo.avatar" mode=""></image>
					<view class="user-center u-flex-1 u-flex-col">
						<text>{{item.userinfo.name}}</text>
						<text>{{item.userinfo.company_name.name}}</text>
					</view>
					<text class="guanzhu-btn" @click.stop="guanzhu(item)">{{item.is_follow ? '已关注' : '关注'}}</text>
				</view>
				<zhao-text :text="item.content"></zhao-text>
				<view class="luntan-img u-flex u-flex-wrap u-row-between" v-if="item.images">
					<image :src="a" v-for="(a,b) in item.images.split(',')" :key="b"
						@click.stop="openimg(item.images.split(','),b)" mode="aspectFill"></image>
					<view style="width: 210rpx;"></view>
				</view>
				<view class="item-down u-flex u-row-between">
					<view class="u-flex u-row-center down-item" @click.stop="dianzan(item)">
						<image v-if="item.is_like" src="../static/images/dianzan1.png" mode=""></image>
						<image v-else src="../static/images/dianzan.png" mode=""></image>
						<text class="text1">{{item.like_count}}</text>
					</view>
					<view class="u-flex u-row-center down-item">
						<image src="../static/images/pinglun.png" mode=""></image>
						<text class="text1">{{item.comment_count}}</text>
					</view>
					<view class="u-flex u-row-center down-item">
						<image src="../static/images/liulan.png" mode=""></image>
						<text class="text1">{{item.read}}</text>
					</view>
				</view>
			</view>
			<u-gap height="20" bg-color="#F6F6F6"></u-gap>
		</view>
		<view style="height: 150rpx;"></view>
		<view class="safe-area-inset-bottom"></view>
		<view class="quanzi-down">
			<view class="down-btn u-flex u-row-center" @click="toadd">
				<image src="static/add.png" mode=""></image>
				<text>发布帖子</text>
			</view>
			<view class="safe-area-inset-bottom"></view>
		</view>
	</view>
</template>

<script>
	import {
		articlelike,
		follow,
		group_details_user,
		group_details_article
	} from "@/units/inquire.js"
	export default {
		data() {
			return {
				tabslist: [{
					name: '最热',
					id: 2
				}, {
					name: '最新',
					id: 1
				}],
				current: 0,
				id: '',
				detail: {},
				page: 1,
				list: [],
				total: 0,
				isshow: false,
				follow:""
			}
		},
		onLoad(option) {
			this.id = option.id
		},
		onShow() {
			if (this.isshow) {
				this.isshow = false
			} else {
				this.getdetail()
				this.page = 1
				this.list = []
				this.getlist()
			}
		},
		onReachBottom() {
			if (this.total != this.list.length) {
				this.page++
				this.getlist()
			}
		},
		methods: {
			touser(item) {
				uni.navigateTo({
					url: "/pagesC/my-luntan?id=" + item.uid
				})
			},
			changetabs(e) {
				this.current = e
				this.page = 1
				this.list = []
				this.getlist()
			},
			dianzan(item) {
				uni.showLoading({
					mask: true,
					title: "请稍后"
				})
				articlelike({
					id: item.id,
				}).then(res => {
					if (res.code == 1) {
						item.is_like = item.is_like ? null : {}
						if (item.is_like) {
							item.like_count++
						} else {
							item.like_count--
						}
					} else {
						this.$u.toast(res.msg)
					}
				})
			},
			openimg(urls, index) {
				this.isshow = true
				this.$openimage(urls, index)
			},
			toadd() {
				uni.navigateTo({
					url: "/pagesC/add-luntan?quanzi=" + JSON.stringify({
						id: this.id,
						title: this.detail.title
					})
				})
			},
			getdetail() {
				group_details_user({
					id: this.id
				}).then(res => {
					this.detail = res.data
					this.follow = res.data.is_follow
				})
			},
			getlist() {
				group_details_article({
					type: this.tabslist[this.current].id,
					page: this.page,
					id: this.id
				}).then(res => {
					this.total = res.data.total
					this.list = this.list.concat(res.data.data)
				})
			},
			guanzhu(item) {
				uni.showLoading({
					mask: true,
					title: "请稍后"
				})
				follow({
					type: 1,
					id: item.uid
				}).then(res => {
					this.$u.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							this.page = 1
							this.list = []
							this.getlist()
						}, 800)
					}
				})
			},
			guanzhuquanzi() {
				uni.showLoading({
					mask: true,
					title: "请稍后"
				})
				follow({
					type: 2,
					id: this.id
				}).then(res => {
					this.$u.toast(res.msg)
					if (res.code == 1) {
						this.detail.is_follow = this.detail.is_follow ? null : {}
						if (this.detail.is_follow) {
							this.detail.follow_count++
						} else {
							this.detail.follow_count--
						}
					}
				})
			},
			toinfo(item) {
				uni.navigateTo({
					url: "/pagesC/luntan-info?id=" + item.id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.quanzi-info {
		position: relative;

		// z-index: 1;
		.quanzi-down {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750rpx;
			z-index: 99;
			background-color: #fff;
			padding: 20rpx 32rpx 0 32rpx;
			box-sizing: border-box;

			.down-btn {
				height: 92rpx;
				background: #0C66C2;
				border-radius: 12rpx;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-right: 12rpx;
				}

				text {
					font-size: 32rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}
			}
		}

		.luntan-item {

			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 0 32rpx;

			.item-down {
				height: 84rpx;

				.down-item {
					width: 214rpx;

					image {
						width: 33rpx;
						height: 33rpx;
					}

					.text1 {
						font-size: 26rpx;
						font-family: ArialMT;
						color: #777777;
						margin-left: 12rpx;
					}
				}
			}

			.luntan-img {
				margin-top: 20rpx;
				width: 100%;

				image {
					width: 210rpx;
					height: 210rpx;
					border-radius: 10rpx;
					// margin-right: 10rpx;
					margin-bottom: 10rpx;
				}
			}

			.luntan-img::after {
				width: 210rpx;
			}

			.luntan-user {
				height: 130rpx;

				.guanzhu-btn {
					width: 112rpx;
					line-height: 48rpx;
					border-radius: 24rpx;
					border: 1rpx solid #0C66C2;
					text-align: center;
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #0C66C2;
				}

				.user-center {
					margin: 0 16rpx;
					min-width: 1rpx;

					text:first-child {
						font-size: 28rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
						margin-bottom: 4rpx;
					}

					text:last-child {
						font-size: 20rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #818389;
					}
				}

				.user-head {
					width: 72rpx;
					height: 72rpx;
					border-radius: 100rpx;
				}
			}
		}

		.quanzi-title {
			height: 116rpx;
			padding: 0 32rpx;
			border-bottom: 2rpx solid #F4F4F4;
			background-color: #fff;
			border-radius: 28rpx 28rpx 0 0;
			box-sizing: border-box;
		}

		.quanzi-header {
			height: 180rpx;
			padding: 0 32rpx;
			box-sizing: border-box;

			.header-down {
				.down-guanzhu1 {
					width: 144rpx;
					line-height: 60rpx;
					background: rgba(193, 224, 255, 0.4);
					border-radius: 30rpx;
					text-align: center;
					font-size: 24rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}

				.down-guanzhu {
					width: 164rpx;
					height: 60rpx;
					background: #FFFFFF;
					border-radius: 30rpx;

					image {
						width: 28rpx;
						height: 28rpx;
						margin-right: 6rpx;
					}

					text {
						font-size: 24rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #0C66C2;
					}
				}

				.text1 {
					font-size: 36rpx;
					font-family: SFPro-Bold, SFPro;
					font-weight: bold;
					color: #FFFFFF;
				}

				.text2 {
					font-size: 22rpx;
					font-family: SFPro-Bold, SFPro;
					color: #FFFFFF;
					margin-left: 4rpx;
				}

				.text3 {
					height: 30rpx;
					border-right: 2rpx solid #fff;
					margin: 0 30rpx;
				}
			}

			.header-top {
				margin-bottom: 20rpx;

				image {
					width: 40rpx;
					height: 40rpx;
					margin-right: 16rpx;
				}

				text {
					font-size: 38rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}
			}
		}

		.quanzi-top {
			position: absolute;
			top: 0;
			left: 0;
			height: 392rpx;
			width: 750rpx;
			z-index: -1;
		}
	}

	::v-deep .u-subsection--button {
		height: 60rpx !important;
		border-radius: 30rpx !important;
	}
	
	::v-deep .u-subsection__item {
		border: 0 solid #fff !important;

	}
	::v-deep .u-subsection--button__bar {
		border-radius: 30rpx !important;
	}

</style>