<template>
	<view class="xiaoxi-list">
		<view class="xiaoxi-header u-flex u-row-between u-col-bottom">
			<view class="header-tabs u-flex-col u-col-center" :class="{tabsactive:current == index}"
				@click="changetabs(index)" v-for="(item,index) in tabslist" :key="index">
				<text>{{item}}</text>
				<text></text>
			</view>
		</view>
		<!-- <view class="list-box1" v-if="current == 0">
			<view class="list-item u-flex u-row-between" v-for="(item,index) in 5" :key="index">
				<image src="https://dummyimage.com/80x80" class="xiaoxi-left" mode=""></image>
				<view class="xiaoxi-right u-flex-1">
					<view class="top u-flex u-row-between">
						<text>内核招聘官方</text>
						<text>7月8日</text>
					</view>
					<view class="down u-line-1">
						每日新发现：你觉得设计师是不是有点太卷了，很多…
					</view>
				</view>
			</view>
		</view> -->
		<view class="list-box2" v-if="current == 0">
			<view class="list-item" v-for="(item,index) in list" :key="index">
				<view class="list-user u-flex u-row-between" @click="touser(item)">
					<image :src="item.send_id.avatar" class="user-left" mode="aspectFill"></image>
					<view class="user-center u-flex-1 u-flex-col">
						<text>{{item.send_id.name}}</text>
						<text>{{item.createtime}}</text>
					</view>
					<view class="huifu-btn" @click.stop="openhuifu(item)">回复</view>
				</view>
				<view class="pinglun-text">
					{{item.content}}
				</view>
				<view class="pinglun-yuan u-line-1" @click="toinfo(item)">
					{{item.article_id.content}}
				</view>
			</view>
		</view>
		<view class="list-box2" v-if="current == 1">
			<view class="list-item" v-for="(item,index) in list" :key="index">
				<view class="list-user u-flex u-row-between" @click="touser(item)">
					<image :src="item.send_id.avatar" class="user-left" mode="aspectFill"></image>
					<view class="user-center u-flex-1 u-flex-col">
						<text>{{item.send_id.name}}</text>
						<text>{{item.createtime}}</text>
					</view>
				</view>
				<view class="pinglun-text">
					点赞了你的动态
				</view>
				<view class="pinglun-yuan u-line-1" @click="toinfo(item)">
					{{item.article_id.content}}
				</view>
			</view>
		</view>
		<view class="list-box3" v-if="current == 2">
			<view class="list-item" v-for="(item,index) in list" :key="index">
				<view class="list-user u-flex u-row-between" @click.stop="touser(item)">
					<image :src="item.send_id.avatar" class="user-left" mode=""></image>
					<view class="user-center u-flex-1 u-flex-col">
						<view class="u-flex center-name">
							<text>{{item.send_id.name}}</text>
							<text>关注了你</text>
						</view>
						<text class="center-time">{{item.createtime}}</text>
					</view>
					<view class="huifu-btn u-flex u-row-center" @click.stop="guan(item)">

						<text v-if="msg=='关注成功'">已关注</text>
						<view v-else class="">
							<image src="../static/images/plus.png" mode=""></image>
							<text>
								关注</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="height: 70vh;display: flex;align-items: center;justify-content: center;" v-if="list.length == 0">
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view>
		<view class="huifu-input u-flex-col u-row-right" v-if="showinput" @click="showinput = false">
			<input @click.stop type="text" :focus="showinput" v-model="content" @confirm="huifu"
				:adjust-position="false" placeholder="回复" confirm-type="send" :confirm-hold="true">
			<view :style="{height:inputheight + 'px'}"></view>
		</view>
	</view>
</template>

<script>
	import {
		articlecomment,
		message,
		follow
	} from "@/units/inquire.js"
	export default {
		data() {
			return {
				showinput: false,
				inputheight: 0,
				content: '',
				xiaoxidetail: {},

				tabslist: ['回复', '点赞', '粉丝'],
				current: 0,
				page: 1,
				total: 0,
				list: [],
				msg: ''
			}
		},
		onLoad() {
			this.getlist()
			uni.onKeyboardHeightChange(e => {
				this.inputheight = e.height
				if (e.height == 0) {
					this.showinput = false
				}
			})
		},
		onReachBottom() {
			if (this.total != this.list.length) {
				this.page++
				this.getlist()
			}
		},
		methods: {
			guan(item) {
				follow({
					id: item.id,
					type: 1
				}).then((res) => {
					this.$u.toast(res.msg)
					this.msg = res.msg
				})
			},
			openhuifu(item) {
				this.xiaoxidetail = item
				this.showinput = true
			},
			huifu() {
				if (!this.content) {
					this.$u.toast("请输入内容")
					return
				}
				uni.showLoading({
					mask: true,
					title: "请稍后"
				})
				articlecomment({
					id: this.xiaoxidetail.article_id.id,
					content: this.content,
					comment_id: ''
				}).then(res => {
					this.$u.toast(res.msg)
					if (res.code == 1) {
						this.xiaoxidetail = {}
						this.content = ''
						this.showinput = false
					}
				})
			},
			touser(item) {
				uni.navigateTo({
					url: "/pagesC/my-luntan?id=" + item.user_group.id
				})
			},
			toinfo(item) {
				uni.navigateTo({
					url: "/pagesC/luntan-info?id=" + item.article_id.id
				})
			},
			changetabs(index) {
				console.log(111);
				this.current = index
				this.page = 1
				this.total = 0
				this.list = []
				this.getlist()
			},
			getlist() {
				message({
					type: {
						0: 1,
						1: 2,
						2: 3
					} [this.current],
					page: this.page,
				}).then(res => {
					this.list = this.list.concat(res.data.data)
					this.total = res.data.total
				})
			}
		}
	}
</script>

<style lang="scss">
	.xiaoxi-list {
		.huifu-input {
			position: fixed;
			top: 0;
			left: 0;
			width: 750rpx;
			height: 100vh;
			z-index: 999;
			background-color: rgba(0, 0, 0, 0.5);

			input {
				width: 750rpx;
				box-sizing: border-box;
				height: 124rpx;
				padding: 0 32rpx;
				font-size: 30rpx;
				border-radius: 28rpx 28rpx 0 0;
				background-color: #fff;
			}
		}

		.list-box3 {
			padding: 0 32rpx;
			background-color: #fff;

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

				.list-user {
					.huifu-btn {
						width: 116rpx;
						height: 52rpx;
						background: #0C66C2;
						border-radius: 30rpx;

						image {
							width: 24rpx;
							height: 24rpx;
							margin-right: 4rpx;
						}

						text {
							font-size: 22rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #FFFFFF;
						}
					}

					.user-center {
						margin: 0 20rpx;

						.center-name {
							margin-bottom: 16rpx;

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

							text:nth-child(2) {
								font-size: 24rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #777777;
							}
						}


						.center-time {
							font-size: 22rpx;
							font-family: ArialMT;
							color: #999999;
						}
					}

					.user-left {
						width: 80rpx;
						height: 80rpx;
						border-radius: 100rpx;
					}
				}
			}
		}

		.list-box2 {
			padding: 0 32rpx;
			background-color: #fff;

			.pinglun-yuan {
				background: #F6F6F6;
				border-radius: 12rpx;
				padding: 20rpx;
				font-size: 26rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #444444;
			}

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

				.pinglun-text {
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					margin-bottom: 24rpx;
				}

				.list-user {
					margin-bottom: 24rpx;

					.huifu-btn {
						width: 116rpx;
						line-height: 52rpx;
						border-radius: 28rpx;
						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 20rpx;

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

						text:last-child {
							font-size: 22rpx;
							font-family: ArialMT;
							color: #999999;
						}
					}

					.user-left {
						width: 80rpx;
						height: 80rpx;
						border-radius: 100rpx;
					}
				}
			}
		}

		.list-box1 {
			padding: 0 32rpx;
			background-color: #fff;

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

				.xiaoxi-right {
					.down {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #555555;
					}

					.top {
						margin-bottom: 6rpx;

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

						text:last-child {
							font-size: 20rpx;
							font-family: ArialMT;
							color: #555555;
						}
					}
				}

				.xiaoxi-left {
					width: 80rpx;
					height: 80rpx;
					border-radius: 100rpx;
					margin-right: 20rpx;
				}
			}
		}

		.xiaoxi-header {
			height: 90rpx;
			position: sticky;
			top: 0;
			left: 0;
			z-index: 99;
			background-color: #fff;
			width: 750rpx;
			padding: 0 80rpx;
			box-sizing: border-box;

			.header-tabs {
				text:first-child {
					font-size: 28rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #888888;
					margin-bottom: 16rpx;
				}

				text:last-child {
					width: 20rpx;
					height: 6rpx;
					border-radius: 8rpx;
				}
			}

			.tabsactive {
				text:first-child {
					color: #222222;
				}

				text:last-child {
					background-color: #0C66C2;
				}
			}
		}
	}

	page {
		background-color: #F6F6F6;
	}
</style>