<template>
	<view class="my-luntan">
		<image  src="./static/weitu.png" class="my-luntan-bg" mode="aspectFill"></image>
		<!-- <u-navbar  :background="{background:'rgba(0,0,0,0)'}" :isFixed="false" :border-bottom="false"></u-navbar> -->
		<u-navbar leftIconColor="#fff" :fixed="false" bgColor='rgba(0,0,0,0)' placeholder :safeAreaInsetTop="true" @leftClick="return1"></u-navbar>
		<view class="my-luntan-header">
			<view class="u-flex u-col-bottom u-row-between" style="position: relative;top: -24rpx;">
				<image :src="userinfo.userinfo.avatar" class="header-img" mode="aspectFill"></image>
				<view class="header-right u-flex u-flex-1 u-row-right">
					<view class="u-flex-col u-col-center right-item">
						<text>{{userinfo.host_follow_count || 0}}</text>
						<text>{{user_id == userinfo.id ? '我的关注' : 'Ta的关注'}}</text>
					</view>
					<view class="u-flex-col u-col-center right-item">
						<text>{{userinfo.quilt_follow_count || 0}}</text>
						<text>{{user_id == userinfo.id ? '关注我的' : '关注Ta的'}}</text>
					</view>
				</view>
			</view>
			<view class="user-zhiye u-flex u-row-between">
				<view class="u-flex-col">
					<text class="text1">{{userinfo.userinfo.name || ''}}</text>
					<text class="text2">{{userinfo.userinfo.job || ''}}</text>
				</view>
				<text class="text3" v-if="user_id == userinfo.id" @click="touser">编辑资料</text>
			</view>
		</view>
		<u-gap height="20" bg-color="#F6F6F6"></u-gap>
		<view class="luntan-list">
			<view class="list-header u-flex">
				<text :class="{text:current == 1}" @click="changecurrent(1)">动态·{{total}}</text>
				<text :class="{text:current == 2}" @click="changecurrent(2)">圈子</text>
			</view>
			<view v-if="current == 1">
				<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" :src="userinfo.userinfo.avatar" mode=""></image>
							<view class="user-center u-flex-1 u-flex-col">
								<text>{{userinfo.userinfo.name}}</text>
								<text>{{userinfo.userinfo.job}}</text>
							</view>
							<view @click.stop="open(item)" v-if="user_id == userinfo.id">
								<u-icon name="more-dot-fill" size="36"></u-icon>
							</view>
						</view>
						<zhao-text :text="item.content"></zhao-text>
						<view v-if="item.images" class="luntan-img u-flex u-flex-wrap u-row-between">
							<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 || 0}}</text>
							</view>
						</view>
					</view>
					<u-gap height="20" bg-color="#F6F6F6"></u-gap>
				</view>
			</view>
			<view v-if="current == 2" style="padding: 0 32rpx;">
				<view class="quanzi-type u-flex">
					<text :class="{text:type == 1}" @click="changetype(1)">{{user_id == userinfo.id ? '我的' : 'Ta的'}}关注</text>
					<text :class="{text:type == 2}" @click="changetype(2)">{{user_id == userinfo.id ? '我的' : 'Ta的'}}创建</text>
				</view>
				<view v-if="type == 1">
					<view class="quanzi-item u-flex u-row-between" v-for="(item,index) in list1" :key="index" @click="toquanzi({id:item.group.id})">
						<image :src="item.group.image" class="item-img" mode="aspectFill"></image>
						<view class="quanzi-center u-flex-1 u-flex-col">
							<view class="u-flex">
								<text class="text1">{{item.group.title}}</text>
							</view>
							<text class="text2">{{item.article_count}}条内容｜{{item.group.follow_count}}人关注</text>
						</view>
						<u-icon name="arrow-right" color="rgba(76, 76, 76, 0.4)"></u-icon>
					</view>
				</view>
				<view v-else>
					<view class="quanzi-item u-flex u-row-between" v-for="(item,index) in list1" :key="index" @click="toquanzi({id:item.id})">
						<image :src="item.image" class="item-img" mode="aspectFill"></image>
						<view class="quanzi-center u-flex-1 u-flex-col">
							<view class="u-flex">
								<text class="text1">{{item.title}}</text>
								<!-- <image class="img" v-if="user_id == userinfo.id" src="static/quanzi-edit.png" mode=""></image> -->
							</view>
							<text class="text2">{{item.article_count}}条内容｜{{item.follow_count}}人关注</text>
						</view>
						<u-icon name="arrow-right" color="rgba(76, 76, 76, 0.4)"></u-icon>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {articlelike,homepagearticle,followgrouplist,usergrouplist,others_homepage,del_article} from "@/units/inquire.js"
	export default {
		data() {
			return {
				id: '',
				current: 1,
				type: 1,
				userinfo: {
					userinfo: {
						company_name: {}
					}
				},
				page: 1,
				list: [],
				total: 0,
				user_id: '',
				page1: 1,
				list1: [],
				total1: 0,
				isshow: false
			}
		},
		onLoad(option) {
			this.id = option.id
			this.user_id = uni.getStorageSync("user_id")
		},
		onShow() {
			this.getuser()
			if (this.isshow) {
				this.isshow = false
			} else {
				if (this.current == 1) {
					this.page = 1
					this.list = []
				} else {
					this.page1 = 1
					this.list1 = []
				}
				this.getlist()
			}
		},
		onReachBottom() {
			if (this.current == 1) {
				if (this.total != this.list.length) {
					this.page++
					this.getlist()
				}
			} else {
				if (this.total1 != this.list1.length) {
					this.page1++
					this.getlist()
				}
			}
		},
		methods: {
			return1(){
				uni.navigateBack()
			},
			toquanzi(item) {
				uni.navigateTo({
					url: "/pagesC/quanzi-info?id=" + item.id
				})
			},
			openimg(urls, index) {
				this.isshow = true
				this.$openimage(urls, index)
			},
			changetype(type) {
				this.type = type
				this.page1 = 1
				this.list1 = []
				this.getlist()
			},
			changecurrent(current) {
				this.current = current
				if (this.current == 1) {
					this.page = 1
					this.list = []
				} else {
					this.page1 = 1
					this.list1 = []
				}
				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)
					}
				})
			},
			touser() {
				uni.navigateTo({
					url: "/pagesD/userinfo"
				})
			},
			getlist() {
				if (this.current == 1) {
					homepagearticle({
						id: this.id,
						page: this.page
					}).then(res => {
						this.total = res.data.total
						this.list = this.list.concat(res.data.data)
					})
				} else {
					if (this.type == 1) {
						followgrouplist({
							page: this.page1,
							id: this.id
						}).then(res => {
							this.total1 = res.data.total
							this.list1 = this.list1.concat(res.data.data)
						})
					} else {
						usergrouplist({
							page: this.page1,
							id: this.id
						}).then(res => {
							this.total1 = res.data.total
							this.list1 = this.list1.concat(res.data.data)
						})
					}
				}
			},
			getuser() {
				others_homepage({
					id: this.id,
					page:this.page,
					page_num:20
				}).then(res => {
					this.userinfo = res.data
				})
			},
			open(item) {
				uni.showActionSheet({
					itemList: ['删除'],
					success: (e) => {
						if (e.tapIndex == 0) {
							del_article({
								id: item.id
							}).then(res => {
								this.$u.toast(res.msg)
								if (res.code == 1) {
									setTimeout(() => {
										this.page = 1
										this.list = []
										this.getlist()
									}, 800)
								}
							})
						}

					}
				})
			},
			toinfo(item) {
				uni.navigateTo({
					url: "/pagesC/luntan-info?id=" + item.id
				})
			},
		}
	}
</script>

<style lang="scss">
	.my-luntan {
		position: relative;

		.luntan-list {
			.quanzi-item {
				padding: 32rpx 0;
				border-bottom: 2rpx solid #F4F4F4;

				.item-img {
					width: 84rpx;
					height: 84rpx;
					border-radius: 10rpx;
				}

				.quanzi-center {
					margin: 0 20rpx;

					.text1 {
						font-size: 32rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}

					.img {
						width: 24rpx;
						height: 24rpx;
						margin-left: 12rpx;
					}

					.text2 {
						margin-top: 8rpx;
						font-size: 22rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #777777;
					}
				}
			}

			.quanzi-type {
				padding: 30rpx 0 8rpx 0;

				text {
					width: 156rpx;
					line-height: 64rpx;
					background: #F0F0F0;
					border-radius: 32rpx;
					text-align: center;
					margin-right: 44rpx;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #444444;
				}

				.text {
					background-color: #0C66C2;
					color: #fff;
				}
			}

			.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;
					}
				}
			}

			.list-header {
				padding: 0 32rpx;
				height: 108rpx;
				border-bottom: 2rpx solid #F4F4F4;

				text {
					font-size: 32rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #666666;
					margin-right: 88rpx;
				}

				.text {
					color: #222222;
				}
			}
		}

		.my-luntan-header {
			padding: 0 32rpx;
			width: 750rpx;
			height: 288rpx;
			background: #FFFFFF;
			border-radius: 32rpx 32rpx 0rpx 0rpx;
			margin-top: 88rpx;
			box-sizing: border-box;

			.user-zhiye {
				.text3 {
					width: 172rpx;
					line-height: 56rpx;
					border-radius: 32rpx;
					border: 1rpx solid #0C66C2;
					text-align: center;
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #0C66C2;
				}

				.text1 {
					font-size: 44rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
					margin-bottom: 12rpx;
				}

				.text2 {
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
				}
			}

			.header-right {
				.right-item {
					margin-left: 84rpx;

					text:first-child {
						font-size: 40rpx;
						font-family: DINAlternate-Bold, DINAlternate;
						font-weight: bold;
						color: #333333;
						margin-bottom: 8rpx;
					}

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

			.header-img {
				width: 136rpx;
				height: 136rpx;
				border-radius: 100%;
				border: 4rpx solid #FFFFFF;
			}
		}

		.my-luntan-bg {
			position: absolute;
			top: 0;
			left: 0;
			width: 750rpx;
			height: 396rpx;
			z-index: -1;
		}
	}
</style>