<template>
	<div style="" class="g_bg_f_5">
		<view class="" v-if="isLogin && is_use_im == 1">
			<scroll-view @scroll="getScrollInfo" :scroll-top="resetScroll" style="height: 100vh" :scroll-y="true">
				<view class="" v-if="is_use_im == 1">
					<div style="height: 10px"></div>
					<view class="" v-show="isLogin ? current == 0 : current == 1">
						<g-message-cell ref="AIList" @exportClickImage="openServer" v-if="isJm" />
						<view class="">
							<conversationList />
						</view>
					</view>
					<view class="g_bg_f" v-show="isLogin ? current == 1 : current == 0">
						<message :cmsIds="messageId" :update="update" />
					</view>
					<view class="g_bg_f" v-if="current == 2">
						<telPanel />
					</view>
				</view> 
				<view class="" v-if="is_use_im == 0">
					<!-- #ifdef MP-WEIXIN -->
					<div class="1" style="height: 10px" v-if="current == 1 || current == 2"></div>
					<!-- #endif -->
					<view class="g_bg_f">
						<message :cmsIds="messageId" :update="update" />
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="" v-if="!isLogin" style="height: 100vh">
			<rh-login-false-list />
		</view>
		<rh-serverpopup
			:show="showService"
			@updateShow="
				(e) => {
					showService = e;
				}
			"
		></rh-serverpopup>
	</div>
	<view v-show="firstLoad" style="position: fixed; width: 100%; height: 100vh; left: 0px; top: 0px; z-index: 9" class="u-skeleton">
		<view v-for="i in 10" :key="i" style="width: 100%; height: 72px; padding: 16px 12px" class="g_flex_row_between">
			<view class="u-skeleton-fillet g_w_48 g_h_48 g_mr_8"> </view>
			<view class="g_flex_1">
				<view class="u-skeleton-fillet g_w_all g_h_20"></view>
				<view class="u-skeleton-fillet g_w_all g_h_20 g_mt_4"></view>
			</view>
		</view>
		<!-- </template> -->
	</view>
	<u-skeleton :loading="firstLoad" :animation="true" el-color="#ededed" bg-color="#fff"></u-skeleton>
</template>

<script lang="ts" setup>
import { ref, onMounted, computed, getCurrentInstance } from "vue";
import { onShow, onLoad, onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
import message from "./components/message.vue";
import conversationList from "../../components/conversationList.vue";
import gMessageCell from "@/components/panel/messageCell.vue";

const G = getCurrentInstance().appContext.app.config.globalProperties.G;

onShareAppMessage(() => {
	let appInfo = uni.getStorageSync("miniApp-info");
	return {
		title: appInfo.slogan || "你想找的厂都有，立即查看",
		imageUrl: appInfo.sharePoster,
		path: "/pages/message/index",
	};
});

// 分享到朋友圈
onShareTimeline(() => {
	let appInfo = uni.getStorageSync("miniApp-info");
	return {
		title: appInfo.slogan || "你想找的厂都有，立即查看",
		imageUrl: appInfo.logo,
		query: "",
	};
});

let firstLoad = ref(false);
let showLoading = ref(true);
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 is_use_im = ref(uni.getStorageSync("is_use_im"));

const isLogin = ref(true);
// 回到顶部
const resetScroll = ref(0);
const tabbarHeight = ref(uni.getStorageSync("TABBAR_HEIGHT"));
const openTel2 = ref(null);
onMounted(() => {
	// const query = uni.createSelectorQuery();
	// query.select("#openTel2").exec(function (res) {
	// 	console.log("resresres", res);
	// });
	// setTimeout(() => {
	// 	console.log("openTel2.value", openTel2.value);
	// 	openTel2.value.handleClick();
	// }, 1000);
	setTimeout(() => {
		showLoading.value = false;
		firstLoad.value = false;
	}, 2000);
});
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({});
const isJm = ref(uni.getStorageSync("apply-userinfo") && uni.getStorageSync("apply-userinfo").agencyId && uni.getStorageSync("apply-userinfo").agencyId == '114827')
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);
		current.value = 0;
});

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;
};
</script>

<style lang="scss">
// @import "../NEUIKit/pages/styles/common.scss";

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