<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;">
					<template v-for="item in typeList">
						<view v-if="item.type==0" class="tn-flex tn-flex-center  tn-flex-col-center"
							@click="openMode(item)">
							<view style="width: 110rpx;height: 110rpx;position: relative;">
								<image src="/static/msg3.png" style="width: 110rpx;height: 110rpx;border-radius:50%;">
								</image>
								<view v-if="item.state_zero_count>0"
									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;">
									{{item.state_zero_count>99?'99+':item.state_zero_count}}
								</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 v-if="item.type==0"
							style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 40rpx 0rpx;"></view>
						<view v-if="item.type==1" @click="openMode(item)"
							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 v-if="item.state_zero_count>0"
									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;">
									{{item.state_zero_count>99?'99+':item.state_zero_count}}
								</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 v-if="item.type==1"
							style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 40rpx 0rpx;"></view>
						<view v-if="item.type==3" class="tn-flex tn-flex-center  tn-flex-col-center"
							@click="openMode(item)">
							<view style="width: 110rpx;height: 110rpx;position: relative;">
								<image src="/static/msg2.png" style="width: 110rpx;height: 110rpx;border-radius:50%;">
								</image>
								<view v-if="item.state_zero_count>0"
									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;">
									{{item.state_zero_count>99?'99+':item.state_zero_count}}
								</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>


					</template>
				</view>
			</view>
		</view>
		<tn-popup v-model="hdModel" mode="right" :safeAreaInsetBottom="false" width="100%">
			<tn-nav-bar :isBack="false" backTitle="" :bottomShadow="false" 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;'}">
				<!-- <view style="text-align: right;padding: 20rpx;">
					<tn-button size="sm" backgroundColor="#3056D3" fontColor="#ffffff" height="60rpx">清理消息</tn-button>
				</view> -->
			</view>
			<scroll-view scroll-y @scrolltolower="hdTolower" style="background-color: #F1F2F8;height: 100vh;">
				<view class="text" style="padding:30rpx;">
					<view style="background-color: #FFF;padding: 30rpx;border-radius: 20rpx;">
						<view v-for="(item,index) in contentList"
							@click="tn('/pages/packageB/paper/paper_info?id='+item.be_related_to_id)">
							<view class="tn-flex tn-flex-center  tn-flex-col-center">
								<view style="width: 110rpx;height: 110rpx">
									<image v-if="item.member.photo_image==null||item.member.photo_image==''"
										src="/static/def.png" style="width: 110rpx;height: 110rpx;border-radius:50%;">
									</image>
									<image v-if="item.member.photo_image!=null&&item.member.photo_image!=''"
										:src="apiImgUrl+item.member.photo_image"
										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;">{{item.member.nikename}}</text>
									</view>
									<view class="tn-text-ellipsis-2"
										style="font-size: 28rpx;margin-top: 10rpx;color: #666666;">
										<text v-if="item.type==1" class="tn-icon-praise-fill"
											style="color: #3056D3;font-size: 30rpx;"></text>
										<text v-if="item.type==2" class="tn-icon-star-fill"
											style="color: #3056D3;font-size: 30rpx;"></text>
										<text v-if="item.type==4" class="tn-icon-comment-fill"
											style="color: #3056D3;font-size: 30rpx;"></text>
										<text style="margin-left: 10rpx;">{{item.tweet.title}}</text>
									</view>
									<view style="margin-top: 10rpx;font-size: 24rpx;color: #999999;">{{item.content}}
									</view>
								</view>
							</view>
							<view style="font-size: 24rpx;color: #AAAAAA;padding-left: 120rpx;margin-top: 20rpx;">
								{{item.createtime}}
							</view>
							<view v-if="index<contentList.length-1"
								style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 30rpx 0rpx;"></view>
						</view>
					</view>
				</view>
			</scroll-view>
		</tn-popup>
		<tn-popup v-model="xtModel" mode="right" :safeAreaInsetBottom="false" width="100%">
			<tn-nav-bar :isBack="false" backTitle="" :bottomShadow="false" 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;'}">
				<!-- 	<view style="text-align: right;padding: 20rpx;">
					<tn-button size="sm" backgroundColor="#3056D3" fontColor="#ffffff" height="60rpx">清理消息</tn-button>
				</view> -->
			</view>
			<scroll-view scroll-y @scrolltolower="xtTolower" style="background-color: #F1F2F8;height: 100vh;">
				<view v-for="(item,index) in contentList" class="text" style="padding:30rpx;">
					<view v-if="item.system_notification_type==1" @click="set_tn(item)"
						style="background-color: #FFF;border-radius: 20rpx;padding:30rpx;margin-bottom: 30rpx;">
						<view style="font-size: 32rpx;font-weight: bold;">
							<text>管理员</text>
							<text v-if="item.neirong.status==2" style="color: green;">审核通过</text>
							<text v-if="item.neirong.status==3" style="color: red;">拒绝</text>
							<text>了你发布的动态:</text>
						</view>
						<view style="font-size: 28rpx;color: #666666;margin-top: 20rpx;">
							{{item.neirong.title}}
						</view>
						<view style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">{{item.mail_time}}</view>
						<view v-if="item.neirong.status==3"
							style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 30rpx 0rpx;"></view>
						<view v-if="item.neirong.status==3" style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">
							拒绝理由: {{item.neirong.remark}}</view>
					</view>
					<view v-if="item.system_notification_type==2" @click="tn('/pages/packageA/user/my_invoice')"
						style="background-color: #FFF;border-radius: 20rpx;padding:30rpx;margin-bottom: 30rpx;">
						<view style="font-size: 32rpx;font-weight: bold;">
							<text>管理员</text>
							<text v-if="item.neirong.if_ssue==1" style="color: green;">审核通过</text>
							<text v-if="item.neirong.if_ssue==2" style="color: red;">拒绝</text>
							<text>了你的发票申请</text>
						</view>
						<view style="font-size: 28rpx;color: #666666;margin-top: 20rpx;">
							<view>{{item.neirong.unit}}</view>
							<view style="margin:10rpx 0rpx;">{{item.neirong.name}} / {{item.neirong.createtime}}</view>
							<view>发票金额: ¥{{item.neirong.money}}</view>
						</view>
						<view style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">{{item.mail_time}}</view>
						<view v-if="item.neirong.if_ssue==2"
							style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 30rpx 0rpx;"></view>
						<view v-if="item.neirong.if_ssue==2" style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">
							拒绝理由: {{item.reason}}</view>
					</view>
					<view v-if="item.system_notification_type==3" @click="tn('/pages/packageA/user/apply_in')"
						style="background-color: #FFF;border-radius: 20rpx;padding:30rpx;margin-bottom: 30rpx;">
						<view style="font-size: 32rpx;font-weight: bold;">
							<text>管理员</text>
							<text v-if="item.content==''" style="color: green;">审核通过</text>
							<text v-if="item.content!=''" style="color: red;">拒绝</text>
							<text>了你的入会申请</text>
						</view>
						<view style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">{{item.mail_time}}</view>
						<view v-if="item.content!=''"
							style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 30rpx 0rpx;"></view>
						<view v-if="item.content!=''" style="font-size: 24rpx;color: #AAAAAA;margin-top: 30rpx;">
							拒绝理由: {{item.content}}</view>
					</view>
				</view>
			</scroll-view>

		</tn-popup>
		<tn-popup v-model="hyModel" mode="right" :safeAreaInsetBottom="false" width="100%">
			<tn-nav-bar :isBack="false" backTitle="" :bottomShadow="false" backgroundColor="#FFFFFF">
				<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
					<view style="padding-left: 15rpx;" @click="hyModel = 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;'}">
				<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-center" style="padding: 30rpx;">
					<view class="tab_info" @click="getHyList(0)">
						<view :style="current==0?'font-weight:600;color:#3056D3':''">我申请的</view>
						<view v-if="current==0"
							style="position: absolute;width: 50%;height: 8rpx;background-color: #3056D3;left: 0;right: 0;margin: 0 auto;bottom: -15rpx">
						</view>
					</view>
					<view class="tab_info" style="margin-left: 60rpx;" @click="getHyList(1)">
						<view :style="current==1?'font-weight:600;color:#3056D3':''">我收到的</view>
						<view v-if="current==1"
							style="position: absolute;width: 50%;height: 8rpx;background-color: #3056D3;left: 0;right: 0;margin: 0 auto;bottom: -15rpx">
						</view>
					</view>
				</view>
			</view>
			<scroll-view scroll-y @scrolltolower="xtTolower" style="background-color: #F1F2F8;height: 100vh;">
				<view class="text" style="padding:30rpx;">
					<view style="background-color: #FFF;border-radius: 20rpx;padding:30rpx;margin-bottom: 30rpx;">
						<view v-for="(item,index) in contentList">
							<view class="tn-flex tn-flex-center  tn-flex-col-center tn-flex-row-between">
								<view class="tn-flex tn-flex-center tn-flex-col-center">
									<view
										@click="tn('/pages/packageA/user/my_card?id='+(current==0?item.member_id:item.member_q_id))">
										<image v-if="item.member_b_photo_image==null||item.member_b_photo_image==''"
											src="/static/def.png"
											style="width: 110rpx;height: 110rpx;border-radius:50%;">
										</image>
										<image v-if="item.member_b_photo_image!=null&&item.member_b_photo_image!=''"
											:src="apiImgUrl+item.member_b_photo_image"
											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;">{{current==1?item.member_q_id_name:item.member_nikename}}</text>
										</view>
										<view style="margin-top: 10rpx;font-size: 24rpx;color: #999999;">
											{{current==1?item.member_q_work_unit:item.member_work_unit}}
										</view>
									</view>
								</view>
								<view>
									<tn-button v-if="item.if_tongyi==0" size="sm" shape="round"
										backgroundColor="#3056D3" fontColor="#ffffff">已同意</tn-button>
									<tn-button v-if="item.if_tongyi==1" size="sm" shape="round"
										backgroundColor="#F1F2F8" fontColor="#888888">被拒绝</tn-button>
									<tn-button @click="sqMode = true;sqInfo=item" v-if="item.if_tongyi==2" size="sm"
										shape="round" backgroundColor="#FF7043" fontColor="#ffffff">操作</tn-button>
								</view>
							</view>
							<view v-if="index<contentList.length-1"
								style="height: 1rpx;border-top: #BABDC7 1rpx dashed;margin: 30rpx 0rpx;"></view>
						</view>
					</view>
				</view>
			</scroll-view>
		</tn-popup>
		<tn-modal v-model="sqMode" :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: 20rpx;">
					<view class="tn-flex tn-flex-center tn-flex-row-between" style="margin-top: 40rpx;">
						<view>
							<tn-button @click="updateType(1,sqInfo.mail_id)" width="250rpx" :plain="true" shape="round"
								size="lg" backgroundColor="#BABDC7" fontColor="#999999">拒绝
							</tn-button>
						</view>
						<view>
							<tn-button @click="updateType(0,sqInfo.mail_id)" 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 {
		msgTypeList,
		interactionlIndex,
		MaillogIndex,
		mailMyMemberPost,
		MaillogUpdate
	} from "@/util/api";
	import store from "@/store";
	export default {
		name: 'Message',
		data() {
			return {
				hdModel: false,
				xtModel: false,
				hyModel: false,
				sqMode: false,
				apiImgUrl: this.$store.state.imgUrl,
				page: 1,
				size: 10,
				current: 0,
				tab_list: [{
					name: '理事会'
				}, {
					name: '监事会'
				}],
				typeList: [],
				contentList: [],
				sqInfo: {}
			}
		},
		onLoad() {
			var uid = uni.getStorageSync('uid');
			this.uid = uid;
			this.getMsgTypeList();
		},
		onReachBottom() {
			this.page = this.page + 1;
			//this.getMaillogIndex();
		},
		methods: {
			updateType(key, this_id) {
				MaillogUpdate({
						id: this_id,
						if_tongyi: key,
						state: 1, //已读
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							uni.showToast({
								title: '操作成功！',
								icon: 'none',
								duration: 2000
							});
							this.getMaillogIndex(1);
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			getHyList(d) {
				this.page = 1;
				this.contentList = [];
				this.current = d;
				if (d == 0) {
					this.geTmailMyMemberPost();
				} else {
					this.getMaillogIndex(1);
				}
			},
			geTmailMyMemberPost() {
				mailMyMemberPost({
						page: this.page,
						size: 10,
					})
					.then(res => {
						this.contentList.push(...res.data);
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			openMode(item) {
				console.log(item);
				this.page = 1;
				this.contentList = [];
				if (item.type == 3) {
					this.getInteractionlIndex();
				} else {
					if (item.type == 0) {
						this.xtModel = true;
						this.getMaillogIndex(item.type);
					} else {
						this.hyModel = true;
						this.geTmailMyMemberPost();
					}
				}
			},
			getMaillogIndex(type) {
				MaillogIndex({
						page: this.page,
						size: 10,
						type: type,
					})
					.then(res => {

						this.contentList.push(...res.data);
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			getInteractionlIndex() {
				interactionlIndex({
						page: this.page,
						size: 10
					})
					.then(res => {
						this.hdModel = true;
						this.contentList.push(...res.data.data);
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			hdTolower() {
				console.log(1);
				this.page += 1;
				this.getInteractionlIndex();
			},
			getMsgTypeList() {
				msgTypeList()
					.then(res => {
						console.log(res);
						this.typeList = res.data;
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
			set_tn(item) {
				if (item.neirong.status != 3) {
					uni.navigateTo({
						url: '/pages/packageB/paper/paper_info?id=' + item.be_related_to_id,
					});
				}
			},
			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;
	}

	.tab_info {
		font-size: 32rpx;
		position: relative;
		color: #999999;
	}
</style>