<template>
	<div>
		<view
			class="mcell"
			:style="{
				'background-color': wyyxTabGroup && wyyxTabGroup.length == 0 ? '#ededed' : '#fff',
			}"
		>
			<view v-for="(item, index) in wyyxTabGroup" :key="index" class="g_flex_row_between i-items" @click="goPage(item)">
				<div class="g_flex_1 g_flex_row_start g_fs_16" style="padding: 12px 16px">
					<div class="g_flex_none g_mr_12">
						<image :src="item.avatar" style="width: 48px; height: 48px; border-radius: 50px"></image>
					</div>
					<div class="g_flex_1 g_flex_column_between">
						<view class="g_flex_row_start flex_center">
							<div class="g_c_3 g_fs_17 g_fw_600" style="line-height: 24px">
								{{ item.title }}
							</div>
							<view class="g_c_f g_fs_12 g_radius_6 g_ml_4" style="background: linear-gradient(135deg, #5c6cf7, #9963f9); line-height: 18px; padding: 0 4px; height: 18px">官方AI</view>
						</view>
						<div
							class="g_c_3 g_fs_14 g_ell_1"
							style="line-height: 20px"
							:style="{
								color: item.tip == 'khjl' ? '#333' : '#999',
							}"
						>
							{{ item.sub_title }}
						</div>
					</div>
				</div>
				<div class="g_flex_none g_flex_column_center">
					<div v-if="item.tip == 'khjl'" class="g_flex_column_center">
						<div class="g_flex_row_end">
							<div class="g_flex_column_center g_mr_8" @click.stop="openTel(item.tel)">
								<image src="https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/dailibaoming/blueTel.svg" style="width: 40px; height: 40px"></image>
							</div>
							<div class="g_flex_column_center" @click.stop="openServer">
								<image src="https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/dailibaoming/qiyeweixin.svg" style="width: 40px; height: 40px"></image>
							</div>
						</div>
					</div>
				</div>
			</view>
		</view>
	</div>
</template>

<script>
export default {
	data() {
		return {
			cdnBaseImg: this.G.store().cdnBaseImg,
			corpUserFlag: uni.getStorageSync("apply-userinfo").corpUserFlag,
			wyyxTabGroup: [],
			randomTime: this.generateRandomTime(), // 生成随机时间,
			appinfo:uni.getStorageSync("miniApp-info")
		};
	},
	mounted() {
		let that = this;
		this.getConfig().then((botArray) => {
			// console.log("ressasas", botArray);
			if (that.corpUserFlag) {
				that.wyyxTabGroup = botArray;
			}
		});
	},
	methods: {
		getConfig() {
			let that = this;
			return new Promise((resolve, reject) => {
				let botArray = [];
				let config = uni.getStorageSync("chat_config");
				botArray = [
					{
						title: that.appinfo.aiRobotName, //config.name,
						sub_title: that.appinfo.appName + "平台智能助理", //config.description,
						avatar: that.appinfo && that.appinfo.logo ? that.appinfo.logo : that.cdnBaseImg + "v3/add1.png", //config.icon_url,
						path: "/root/chat/index",
						tip: "rgpp",
						randomTime: that.generateRandomTime(), // 为机器人添加随机时间
					},
				];
				resolve(botArray);
			});
		},
		goPage($data) {
			let that = this;
			if ($data.tip == "rgpp") {
				uni.setStorageSync("robot_id", "7491244881596809243");
				uni.setStorageSync("isExecute", 1);
				uni.navigateTo({
					url: $data.path + "?cid=&form=viwdata",
				});
			} else {
				uni.navigateTo({
					url: $data.path,
				});
			}
		},
		openTel($tel) {
			if($tel){
				$tel = $tel.replace(/-/g, "");
			}
			uni.makePhoneCall({
				phoneNumber: $tel || "0371-6611 3723",
			});
		},
		openServer() {
			this.$emit("exportClickImage");
		},
		generateRandomTime() {
			return Math.floor(Math.random() * (18 - 8 + 1)) + 8; // 生成 8 到 18 之间的随机数
		},
	},
};
</script>

<style lang="scss">
	.mcell{
		border-radius: 8px;
		width: calc(100vw - 20px);
		margin: 0px auto 0;
		overflow: hidden;
	}
</style>
