<template>
	<view style="background: #F1F2F8;min-height: 100vh;" v-cloak>
		<tn-nav-bar :isBack="false" backTitle="" :bottomShadow="true" 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 class="" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view style="padding: 30rpx;">
				<view style="background-color: #ffffff;border-radius: 20rpx;padding-bottom: 20rpx;">
					<view style="font-size: 34rpx;font-weight: bold;padding:30rpx 0rpx 20rpx 30rpx;">近三天</view>
					<view v-for="(item,index) in list">
						<view class="tn-flex tn-flex-center  tn-flex-col-center" style="padding: 30rpx 20rpx;">
							<view style="width: 100rpx;height: 100rpx">
								<image src="/static/def.png" style="width: 100rpx;height: 100rpx;border-radius:50%;">
								</image>
							</view>
							<view style="margin-left: 20rpx;width: 100%;">
								<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between">
									<view style="font-size: 32rpx;color: #181818;font-weight: bold;">
										<text style="vertical-align: middle;margin-right: 10rpx;">石训</text>
									</view>
									<view>
										<tn-button @click="textModal= true" padding="20rpx 20rpx"
											backgroundColor="rgba(48,86,211,0.1)" size="sm" fontColor="#3056D3"
											shape="round">
											<text style="font-size: 24rpx;">查看</text>
										</tn-button>
									</view>
								</view>
								<view class="tn-text-ellipsis"
									style="font-size: 28rpx;margin-top: 10rpx;color: #666666;">
									<text>好想你健康食品股份有限公司</text>
								</view>
							</view>
						</view>
						<view v-if="index<list.length-1"
							style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 10rpx 40rpx;"></view>
					</view>
				</view>
			</view>
		</view>
		<view class="tn-tabbar-height"></view>
		<!-- 	<tn-modal v-model="showMode.show" :title="showMode.title" :content="showMode.content" :button="showMode.button"
			@click="modeClick"></tn-modal> -->
		<tn-modal v-model="textModal" :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: 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>
								<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 {
		MaillogIndex,
		MaillogUpdate,
		MaillogUpdateState
	} from "@/util/api";
	import store from "@/store";
	export default {
		name: 'Message',
		data() {
			return {
				textModal: false,
				uid: 0,
				page: 1,
				size: 10,
				list: [],
				id: 0,
				if_tongyi: 0,
			}
		},
		onLoad() {
			var uid = uni.getStorageSync('uid');
			this.uid = uid;
			this.getMaillogIndex();
		},
		onReachBottom() {
			this.page = this.page + 1;
			this.getMaillogIndex();
		},
		methods: {
			all_upadte_do() {
				MaillogUpdateState({
						member_b_id: this.uid
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							store.state.msgCount = 0;
							uni.showToast({
								title: '操作成功！',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						}
						this.showMode.show = false;
						this.page = 1;
						this.list = [];
						this.getMaillogIndex();
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			all_upadte() {
				this.showMode.show = true;
				this.showMode.content = '确定修改为全部已读吗？';
				this.showMode.title = '操作提示';
				this.showMode.key = 2;
			},
			updateType(type, id) {
				this.showMode.show = true;
				this.showMode.content = type == 0 ? '确定要通过申请吗？' : '确定要拒绝申请吗？';
				this.showMode.title = '操作提示';
				this.showMode.key = 1;
				this.id = id;
				this.if_tongyi = type;
			},
			setMaillogUpdate() {
				MaillogUpdate({
						id: this.id,
						if_tongyi: this.if_tongyi,
						state: 1, //已读
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							uni.showToast({
								title: '操作成功！',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						}
						this.showMode.show = false;
						this.page = 1;
						this.list = [];
						this.getMaillogIndex();
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			getMaillogIndex() {
				MaillogIndex({
						member_b_id: this.uid,
						page: this.page,
						size: this.size,

					})
					.then(res => {
						console.log(res.data.length);
						this.list.push(...res.data);
						if (res.data.length == 0 || this.list.length < 5) {
							this.loadingIn = 'nomore';
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			modeClick(i) {
				if (i.index == 0) {
					this.showMode.show = false;
				}
				if (this.showMode.key == 1 && i.index == 1) {
					this.setMaillogUpdate();
				}
				if (this.showMode.key == 2 && i.index == 1) {
					this.all_upadte_do();
				}
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
			goBack() {
				if (getCurrentPages().length > 1) {
					uni.navigateBack()
				} else {
					uni.redirectTo({
						url: '/pages/index/index'
					})

				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.message {
		max-height: 100vh;
	}

	/* 自定义导航栏内容 end */

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 20rpx;
		height: calc(40rpx + env(safe-area-inset-bottom) / 2);
		height: calc(40rpx + constant(safe-area-inset-bottom));
	}


	.tn-color-wallpaper {
		color: #1D2541;
	}

	/* 页面阴影 start*/
	.wallpaper-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}



	/* 图标容器15 start */
	.icon15 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 105rpx;
				height: 105rpx;
				font-size: 60rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;


				}
			}
		}
	}

	/* 用户头像 start */
	.logo-image {
		width: 100rpx;
		height: 100rpx;
		position: relative;
	}

	.logo-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border: 1rpx solid rgba(255, 255, 255, 0.05);
		box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.05);
		border-radius: 50%;
		overflow: hidden;
		// background-color: #FFFFFF;
	}
</style>