<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 :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view style="padding: 30rpx;">
				<view style="background-color: #ffffff;padding: 35rpx;border-radius: 20rpx;">
					<view @click="tn('/pages/packageA/user/my_card_holder')"
						class="tn-flex tn-flex-center  tn-flex-col-center">
						<view style="width: 110rpx;height: 110rpx;position: relative;">
							<image src="/static/msg1.png" style="width: 110rpx;height: 110rpx;border-radius:50%;">
							</image>
							<view
								style="right: -4rpx;top: -5rpx;position: absolute;color: #ffffff;line-height: 40rpx;text-align: center;width: 40rpx;height: 40rpx;border-radius: 50%;border: 1px #ffffff solid;background-color: red;">
								5
							</view>
						</view>
						<view style="margin-left: 20rpx;">
							<view>
								<text style="font-size: 32rpx;font-weight: bold;vertical-align: middle;">好友验证</text>
							</view>
							<view class="tn-text-ellipsis-2" style="font-size: 28rpx;margin-top: 10rpx;color: #666666;">
								<text>您有好友验证消息</text>
							</view>
						</view>
					</view>
					<view style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 40rpx 0rpx;"></view>
					<view class="tn-flex tn-flex-center  tn-flex-col-center" @click="hdModel= true">
						<view style="width: 110rpx;height: 110rpx">
							<image src="/static/msg2.png" style="width: 110rpx;height: 110rpx;border-radius:50%;">
							</image>
						</view>
						<view style="margin-left: 20rpx;">
							<view>
								<text style="font-size: 32rpx;font-weight: bold;vertical-align: middle;">互动消息</text>
							</view>
							<view class="tn-text-ellipsis-2" style="font-size: 28rpx;margin-top: 10rpx;color: #666666;">
								<text>有用户对您发布的圈子进行了点赞</text>
							</view>
						</view>
					</view>
					<view style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 40rpx 0rpx;"></view>
					<view class="tn-flex tn-flex-center  tn-flex-col-center" @click="xtModel = true">
						<view style="width: 110rpx;height: 110rpx">
							<image src="/static/msg3.png" style="width: 110rpx;height: 110rpx;border-radius:50%;">
							</image>
						</view>
						<view style="margin-left: 20rpx;">
							<view>
								<text style="font-size: 32rpx;font-weight: bold;vertical-align: middle;">系统通知</text>
							</view>
							<view class="tn-text-ellipsis-2" style="font-size: 28rpx;margin-top: 10rpx;color: #666666;">
								<text>管理员审核了你发布的动态</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<tn-popup v-model="hdModel" mode="right" :safeAreaInsetBottom="false" width="100%">
			<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="hdModel = false">
						<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 :style="{paddingTop: vuex_custom_bar_height+'px'}"
				style="background-color: #F1F2F8;min-height: 100vh;">
				<view class="text" style="padding:30rpx;">
					<view style="background-color: #FFF;padding: 30rpx;border-radius: 20rpx;">
						<view v-for="item in 5">
							<view class="tn-flex tn-flex-center  tn-flex-col-center">
								<view style="width: 110rpx;height: 110rpx">
									<image src="/static/def.png"
										style="width: 110rpx;height: 110rpx;border-radius:50%;">
									</image>
								</view>
								<view style="margin-left: 20rpx;">
									<view>
										<text
											style="font-size: 32rpx;font-weight: bold;vertical-align: middle;">李杨</text>
									</view>
									<view class="tn-text-ellipsis-2"
										style="font-size: 28rpx;margin-top: 10rpx;color: #666666;">
										<text class="tn-icon-praise-fill"
											style="color: #3056D3;font-size: 30rpx;"></text>
										<text>《省青企协团信阳市委新县人民政府 助力大别山干部学院举行》</text>
									</view>
								</view>
							</view>
							<view style="font-size: 24rpx;color: #AAAAAA;padding-left: 120rpx;margin-top: 20rpx;">
								2024-07-18
								09:45</view>
							<view style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 30rpx 0rpx;"></view>
						</view>
					</view>
				</view>
			</view>
		</tn-popup>
		<tn-popup v-model="xtModel" mode="right" :safeAreaInsetBottom="false" width="100%">
			<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="xtModel = false">
						<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 :style="{paddingTop: vuex_custom_bar_height+'px'}"
				style="background-color: #F1F2F8;min-height: 100vh;">
				<view class="text" style="padding:30rpx;">
					<view style="background-color: #FFF;border-radius: 20rpx;padding:30rpx;margin-bottom: 30rpx;">
						<view style="font-size: 32rpx;font-weight: bold;">
							管理员<text style="color: green;">审核通过</text>了你发布的动态:
						</view>
						<view style="font-size: 28rpx;color: #666666;margin-top: 20rpx;">
							《省青企协团信阳市委新县人民政府
							助力大别山干部学院举行》
						</view>
						<view style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">2024-07-18 09:45</view>
						<view style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 30rpx 0rpx;"></view>
						<view style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">拒绝理由: 图片信息不足,请完善图片内容</view>
					</view>
					<view style="background-color: #FFF;border-radius: 20rpx;padding:30rpx;margin-bottom: 30rpx;">
						<view style="font-size: 32rpx;font-weight: bold;">
							管理员<text style="color: green;">审核通过</text>了你的发票申请
						</view>
						<view style="font-size: 28rpx;color: #666666;margin-top: 20rpx;">
							<view>好想你健康食品股份有限公司</view>
							<view style="margin:10rpx 0rpx;">上官绪波 / 2024.07.10</view>
							<view>发票金额: ¥680</view>
						</view>
						<view style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">2024-07-18 09:45</view>
						<view style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 30rpx 0rpx;"></view>
						<view style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">拒绝理由: 图片信息不足,请完善图片内容</view>
					</view>
				</view>
			</view>
		</tn-popup>
	</view>
</template>

<script>
	import {
		MaillogIndex,
		MaillogUpdate,
		MaillogUpdateState
	} from "@/util/api";
	import store from "@/store";
	export default {
		name: 'Message',
		data() {
			return {
				hdModel: false,
				xtModel: false,
				loadingIn: 'loading',
				uid: 0,
				page: 1,
				size: 10,
				list: [],
				id: 0,
				if_tongyi: 0,
				showMode: {
					content: '',
					title: '',
					show: false,
					key: 1,
					button: [{
							text: '取消',
							backgroundColor: '#E6E6E6',
							fontColor: '#FFFFFF',
						},
						{
							text: '确定',
							backgroundColor: 'tn-bg-indigo',
							fontColor: '#FFFFFF'
						}
					]
				}

			}
		},
		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>