<template>
	<div style="" class="g_bg_f_5">
		<view class="">
			<scroll-view @scroll="getScrollInfo" :scroll-top="resetScroll" :style="{ height: `calc(100vh - 0px)` }" :scroll-y="true">
				<view class="">
					<message :cmsIds="messageId" :update="update" />
          <view class="g_h_32"></view>
				</view>
			</scroll-view>
		</view>
	</div>
	<!-- <g-tabbar class="tabbar" :isShow="tabbarShow"></g-tabbar> -->
</template>

<script lang="ts" setup>
import { ref, onMounted, computed, getCurrentInstance } from "vue";
// import ConversationList from "../NEUIKit/pages/Conversation/conversation-list/index.vue";
// import { trackInit } from "../NEUIKit/utils/reporter.ts";
import { onShow, onLoad } from "@dcloudio/uni-app";
// import telPanel from "../NEUIKit/pages/Contact/contact-list/index.vue";
import message from "./components/message.vue";
const instance = getCurrentInstance();
const G = instance.appContext.app.config.globalProperties.G;
onMounted(() => {
	// console.log("mountedmountedmountedmountedmountedmounted");
	const query = uni.createSelectorQuery().in(instance);
	// console.log("query", query);
	// 选择指定的 DOM 元素
	query
		.select(".tabbar")
		.boundingClientRect((res) => {
			tabbarHeight.value = res.height;
			uni.setStorageSync("TABBAR_HEIGHT", res.height);
		})
		.exec();
});
const globalData = ref(getApp().globalData);
const wyyxTabGroup = ref([]);
const corpUserFlag = ref(false);
const showService = ref(false);
const update = ref(1);
const contactList = ref(null);
const AIList = ref(null);
const cdnBaseImg = ref(G.store().cdnBaseImg);
const tabbarShow = ref(true);
const isLogin = ref(false);
// 回到顶部
const resetScroll = ref(0);
const tabbarHeight = ref(uni.getStorageSync("TABBAR_HEIGHT"));
const openTel2 = ref(null);
const sname = ref("");
const stel = ref("");

const typeGroup = ref([
	{
		name: "当前会话",
	},
	{
		name: "系统通知",
		count: "",
	},
	// {
	// 	name: "通讯录",
	// },
]);
const current = ref(0);
const count = ref(0); // 系统消息未读
const messageId = ref("");
const userInfo = ref({});

onShow(() => {
	isLogin.value = uni.getStorageSync("apply-token") ? true : false;
	// console.log("count.value", count.value);
	corpUserFlag.value = uni.getStorageSync("apply-userinfo").corpUserFlag;
	userInfo.value = uni.getStorageSync("apply-userinfo");
	// 单独刷新系统通知
	update.value++;
	setTimeout(() => {
		count.value = uni.getStorageSync("notice_info").count;
		// if (!isLogin.value) {
			typeGroup.value = [
				{
					name: "系统通知",
				},
			];
		// } else {
		// 	typeGroup.value = [
		// 		{
		// 			name: "当前会话",
		// 		},
		// 		{
		// 			name: "系统通知",
		// 			count: count.value,
		// 		},
		// 		// {
		// 		// 	name: "通讯录",
		// 		// },
		// 	];
		// }
	}, 200);

	// if (isLogin.value && uni && uni.$UIKitStore) {
	// 	// trackInit("ConversationUIKit");
	// 	// 重置选中会话
	// 	uni.$UIKitStore?.uiStore.selectConversation("");
	// 	setTimeout(() => {
	// 		const unread = uni.$UIKitNIM.V2NIMConversationService.getTotalUnreadCount();
	// 		if(uni.getStorageSync("miniApp-info").openAIDock == 0){
	// 			if (unread === 0) {
	// 				uni.hideTabBarRedDot({
	// 					//隐藏数字
	// 					index: 3, //tabbar下标
	// 				});
	// 			} else {
	// 				uni.showTabBarRedDot({
	// 					index: 3, //tabbar下标
	// 				});
	// 			}
	// 		}else{
	// 			if (unread === 0) {
	// 				uni.hideTabBarRedDot({
	// 					//隐藏数字
	// 					index: 3, //tabbar下标
	// 				});
	// 			} else {
	// 				uni.showTabBarRedDot({
	// 					index: 3, //tabbar下标
	// 				});
	// 			}
	// 		}
			
	// 	}, 1000);
	// 	current.value = 0;
	// 	messageId.value = globalData.value.messageId;
	// }
	if (isLogin.value) {
		current.value = 0;
		messageId.value = globalData.value.messageId;
	}
});
const goLogin = () => {
	uni.reLaunch({
		url: "/root/login/index",
	});
};
const goPage = ($path) => {
	if ($path) {
		uni.navigateTo({
			url: $path,
		});
	}
};
const openTel1 = ($tel) => {
	// console.log("openTel2", openTel2.value);
	uni.requestSubscribeMessage({
		tmplIds: ["UPYUMYWBtgWD3ZZHVEJC9qX04ahF81-yBPdsDzArp_4"],
		success(res) {},
	});
};

const openTel = ($tel) => {
	uni.makePhoneCall({
		phoneNumber: $tel || "0371-6611 3723",
	});
};

const simage = ref("");
const serverPop = ref({
	isShow: false,
});
const openServer = () => {
	let image = uni.getStorageSync("bc-server-image");
	if (image && !image.includes("https")) {
		image = image.replace("http", "https");
	}
	simage.value = image;
	serverPop.value.isShow = true;
};
let timeout = ref(null);

const getScrollInfo = (e) => {
	resetScroll.value = 0;
	if (!timeout.value) {
		timeout.value = setTimeout(() => {
			uni.$emit("pageScroll", e);
			timeout.value = null;
		}, 100);
	}
};

const updateType = (e) => {
	// console.log(e);
	resetScroll.value = 1;
	globalData.value.messageTab = e;
};

const getEmptyDom = (text = "暂无数据", subText = "") => {
	G.getEmptyDom(text, subText);
};
</script>

<style lang="scss">
page {
	background-color: #ededed;
}
.ok-btn {
	color: #fff;
	background-color: rgb(20, 146, 209);
	padding: 10px;
	font-size: 16px;
	text-align: center;
	position: fixed;
	bottom: 0;
	left: calc(50% - 25vw);
	width: 50vw;
	border-radius: 3px;
}

.ok-btn-mp {
	color: #fff;
	background-color: rgb(20, 146, 209);
	padding: 10px;
	font-size: 16px;
	text-align: center;
	position: fixed;
	bottom: 20px;
	left: calc(50% - 25vw);
	width: 50vw;
	border-radius: 3px;
}

.button-box,
.button-box-mp {
	display: flex;
	align-items: center;
	position: fixed;
	z-index: 100;
	bottom: 120px;
	right: 30px;
}

.button-box {
	display: flex;
	align-items: center;
	position: relative;
}
.button-box,
.button-box-mp .button-icon {
	width: 40px;
	height: 40px;
	margin-left: 20px;
}

.button-box {
	width: 40px;
	height: 40px;
	position: fixed;
	z-index: 100;
	bottom: 70px;
	right: 30px;
}
.g_bg_f_5 {
	background-color: #ededed;
}

.i-items {
	position: relative;
	&:not(:first-child):after {
		content: "";
		display: block;
		height: 1rpx;
		width: calc(100% - 80px);
		background: #eee;
		position: absolute;
		top: 0;
		right: 0;
	}
}
.sticky {
	position: sticky;
	top: 0px;
	left: 0;
	z-index: 100;
}
</style>
