<!-- 
[报名] 样式3 - 排名列表
http://localhost:5173/card/#/pages/bm/style3/rankList
https://oss-mbh5.colormaprun.com/card/#/pages/bm/style3/rankList
 -->
<template>
	<view class="body">
		<view class="content uni-column">
			<view class="uni-column" :class="cssTop">
				<my-topbar :mcName="mcName" :class="cssTopbarColor" :showMessage="popupMessageList.length > 0" 
					@btnBackClick="btnBack" @btnInfoClick="btnInfo" @btnMessageClick="btnMessage"></my-topbar>
				<!-- <view class="topbar uni-row" :class="cssTopbarColor">
					<uni-icons type="left" class="topbar-back" @click="btnBack"></uni-icons>
					<text class="mcName">{{mcName}}</text>
					<text class="topbar-rule" @click="btnInfo">规则</text>
				</view> -->
				
				<view class="topbtm uni-row">
					<!-- <view class="topbtm-null"></view> -->
					<view class="topbtm-egg" @click="btnMyEgg">蛋叔券</view>
					<text class="topbtm-name">{{nickName}}</text>
					<view class="topbtm-egg" @click="btnExchg">兑换地址</view>
				</view>
			</view>
			<view class="main uni-column">
				<view class="main-bar uni-row uni-jcse">
					<text>总里程：{{fmtDistanct(all_totalDistance)}}km</text>
					<text>总打点数：{{all_totalCp}}个</text>
					<text>总百味豆数：{{all_totalSysPoint}}个</text>
				</view>
				
				<uni-segmented-control class="main-tab" :current="tabCurrent" :values="tabItems"
					@clickItem="onClickTabItem" styleType="button" :activeColor="tabActiveColor"></uni-segmented-control>
				<view class="tab-view uni-column">
					<!-- 里程 -->
					<my-ranklist v-show="tabCurrent === 0" :rankRs="rankList.totalDistanceRs" rank-type="totalDistance"></my-ranklist>

					<!-- 打点数 -->
					<my-ranklist v-show="tabCurrent === 1" :rankRs="rankList.totalCpRs" rank-type="totalCp"></my-ranklist>
					
					<!-- 百味豆 -->
					<my-ranklist v-show="tabCurrent === 2" :rankRs="rankList.totalSysPointRs" rank-type="totalSysPoint"></my-ranklist>
					
					<!-- 配速 -->
					<my-ranklist v-show="tabCurrent === 3" :rankRs="rankList.fastPaceRs" rank-type="fastPace"></my-ranklist>
				</view>

				<button class="btnBack" @click="btnStartGame">我要比赛</button>
				<!-- <button class="btnBack" @click="btnBack">返回</button> -->
			</view>
			
			<my-popup ref="mypopup" :config="popupRuleConfig" :dataList="popupDataList" :acttime="acttime"></my-popup>
			<my-popup ref="mypopupExchg" :config="popupExchgConfig" :dataList="popupExchgList"></my-popup>
			<my-popup ref="mypopupMessage" :dataList="popupMessageList"></my-popup>
			
		</view>
	</view>
</template>

<script>
	import tools from '/common/tools';
	import { teamName, defaultPopUpDataList } from '/common/define';
	import {
		token,
		apiMatchRsDetailQuery,
		apiCardRankDetailQuery,
		apiCardConfigQuery,
		apiUserCurrentRankNumQuery,
		apiCompStatisticQuery,
		apiIsAllowMcSignUp,
		apiUnReadMessageQuery,
		apiReadMessage,
		checkResCode
	} from '/common/api';
	
	export default {
		data() {
			return {
				pageName: "rankList",
				firstEnterKey: 'firstEnter-bm-style3',
				rankKey: "rank-bm-style3",
				messageKey: "message-bm-style3",
				queryObj: {},
				queryString: "",
				token: "",
				ovtype: "",

				ecId: 0, // 卡片id
				mcId: 0, // 赛事id
				mcType: 0, // 赛事类型 1 普通活动 2 线下赛 3 线上赛
				mcName: "", // 赛事名称
				acttime: "", // 活动时间
				beginSecond: null, // 活动或赛事开始时间戳，单位秒
				endSecond: null, // 活动或赛事结束时间戳，单位秒
				ocaId: 0,	// 关联id，带入到App活动详情页面
				nickName: "", // 昵称
				totalNum: null, // 总场次
				totalDistanct: null, // 总距离,单位米
				totalDistanctRankNum: null, // 总距离排名
				totalCp: null, // 总打点数
				totalCpRankNum: null, // 总打点数排名
				totalSysPoint: null, // 总百味豆
				totalSysPointRankNum: null, // 总百味豆排名
				fastPace: null, // 个人最快配速
				fastPaceRankNum: null, // 个人最快配速排名
				// ocaRs: [], // 卡片对应活动集合
				
				all_totalDistance: 0, // 赛事所有人累计里程，单位米
				all_totalRightAnswerNum: 0, // 赛事所有人正确答题数（校园文化输出）
				all_totalAnswerNum: 0, // 赛事所有人答题数（校园文化输出）
				all_totalCp: 0, // 赛事中所有人打点数
				all_totalSysPoint: 0, // 赛事中所有人百味豆
				
				mcState: 0 ,	// 赛事/活动状态 0: 未开始  1: 进行中  2: 已结束
				allowMcSignUp: false,	// 是否允许重新分组
				countdown: "", // 倒计时
				rankList: { // 排名列表
					totalDistanceRs: [],
					totalCpRs: [],
					totalSysPointRs: [],
					fastPaceRs: []
				},
				interval: null,
				
				teamType: 0, // 队伍类型
				dispArrStr: "totalDistance,totalCp,totalSysPoint,fastPace", // 要显示的集合范围
				tabItems: ["里程", "打点数", "百味豆", "配速"],
				tabCurrent: 0,
				tabActiveColor: "#81cd00",
				
				cssTop: "",
				cssTopbarColor: "",
				popupRuleConfig: {}, // 规则弹窗配置
				popupExchgConfig: {}, // 兑换地址弹窗配置
				popupDataList: [],
				popupExchgList: [],
				popupMessageList: [],
				/* popupMessageList: [
					{
						type: 6,	// 6: 通知
						data: {
							mqType: 3,
							title: "赛事续期通知",
							message: `因为感受到了各位小伙伴的热情，结合即将来临的国庆假期，当然，小飞龙强力出击～“挟持”蛋叔继续赞助鸡蛋………
	
								1. 现决定，将本次小飞龙定向赛延期至<text style="color:red">10月8日</text>，希望各位在漫步秋日的同时，放松心情，好好享受定向运动的奇妙历程。
								
								2. 最后的领蛋截止日，顺延至<text style="color:red">10月20日</text>～
								
								最后总结一句：
								蛋叔！我们都爱你!
								everybody，加油！`
							}
					},
					{
						type: 6,	// 6: 通知
						data: {
							mqType: 2,
							title: "赛事续期通知",
							message: "/static/common/jiangli.png"
							}
					}
				], */
				// mqIdListStr: "", // 已读消息id列表 逗号分隔
			}
		},
		computed: {},
		onLoad(query) { // 类型非必填，可自动推导
			// console.log(query);
			this.queryObj = query;
			this.queryString = tools.objectToQueryString(this.queryObj);
			// console.log(queryString);
			this.token = query["token"] ?? token;
			this.ecId = query["id"] ?? 0;
			this.ovtype = query["ovtype"] ?? "";
			
			this.firstEnterKey += "-" + this.ecId;
			console.log("firstEnterKey:", this.firstEnterKey);

			this.rankKey += "-" + this.ecId;
			console.log("rankKey:", this.rankKey);
			
			this.messageKey += "-" + this.ecId;
			console.log("messageKey:", this.messageKey);
			
			tools.removeCssCode();
			
			this.getCardConfigQuery();
			this.dealOvtype();
		},
		// 页面初次渲染完成，此时组件已挂载完成，DOM 树($el)已可用
		onReady() {
			// this.dealFirstEnter();
			this.$refs.mypopupMessage.popupOpen();
		},
		onUnload() {
			this.clear();
		},
		methods: {
			dealOvtype() {
				if (this.ovtype == "totalDistance") {
					this.tabCurrent = 0;
				} else if (this.ovtype == "totalCp") {
					this.tabCurrent = 1;
				} else if (this.ovtype == "totalSysPoint") {
					this.tabCurrent = 2;
				} else if (this.ovtype == "fastPace") {
					this.tabCurrent = 3;
				}
				console.log(`dealOvtype: ${this.ovtype} tabCurrent: ${this.tabCurrent}`);
			},
			dealNotice(rank) {
				// console.log('[dealFirstEnter]');
				let that = this;
				uni.getStorage({
					key: that.rankKey,
					success: (res) => {
						console.log('[getStorage]', that.rankKey, res.data);
						const oldRank = res.data;
						if (oldRank != rank) {
							// that.notice = true;
							that.setRankValue(rank);
						}
					},
					fail: (e) => {
						console.log('[getStorage] fail', that.rankKey, e);
						// that.notice = false;
						that.setRankValue(rank);
					},
				})
			},
			setRankValue(data) {
				let that = this;
				uni.setStorage({
					key: that.rankKey,
					data: data,
					success: () => {
						console.log('[setStorage] success', that.rankKey, data);
					},
					fail: (e) => {
						console.log('[setStorage] fail', that.rankKey, e);
					},
				})
			},
			dealFirstEnter() {
				// console.log('[dealFirstEnter]');
				let that = this;
				uni.getStorage({
					key: that.firstEnterKey,
					success: (res) => {
						console.log('[getStorage]', that.firstEnterKey, res.data);
					},
					fail: (e) => {
						console.log('[getStorage] fail', that.firstEnterKey, e);
						that.btnInfo();
						that.setFirstEnterValue(true);
					},
				})
			},
			setFirstEnterValue(data) {
				let that = this;
				uni.setStorage({
					key: that.firstEnterKey,
					data: data,
					success: () => {
						console.log('[setStorage] success', that.firstEnterKey, data);
					},
					fail: (e) => {
						console.log('[setStorage] fail', that.firstEnterKey, e);
					},
				})
			},
			clear() {
				if (this.interval != null) {
					clearInterval(this.interval);
					this.interval = null;
				}
			},
			loadConfig(config) {
				// console.log("config", config);
				
				// 加载CSS样式
				const css = config.css;
				if (css != undefined && css.length > 0) {
					tools.loadCssCode(css);
					
					if (css.indexOf(".top{") >= 0) {
						this.cssTop = "top";
					}
					if (css.indexOf(".topbar-color{") >= 0) {
						this.cssTopbarColor = "topbar-color";
					}
				}
				
				if (this.cssTop == "") {
					this.cssTop = "top-default";
				}
				if (this.cssTopbarColor == "") {
					this.cssTopbarColor = "topbar-color-default";
				}
				console.log("[loadConfig] cssTop:", this.cssTop);
				console.log("[loadConfig] cssTopbarColor:", this.cssTopbarColor);
				
				const tabActiveColor = config.tabActiveColor;
				if (tabActiveColor != undefined && tabActiveColor.length > 0) {
					this.tabActiveColor = tabActiveColor;
				}
				
				// 加载规则弹窗配置
				const popupRuleConfig = config.popupRuleConfig;
				if (popupRuleConfig != undefined) {
					this.popupRuleConfig = popupRuleConfig;
				}
				// console.log("[loadConfig] popupRuleConfig:", this.popupRuleConfig);
				
				// 加载兑换地址弹窗配置
				const popupExchgConfig = config.popupExchgConfig;
				if (popupExchgConfig != undefined) {
					this.popupExchgConfig = popupExchgConfig;
				}
				// console.log("[loadConfig] popupExchgConfig:", this.popupExchgConfig);
				
				// 加载弹窗数据
				const popupDataList = config.popupDataList;
				// console.log("[loadConfig] popupDataList:", popupDataList);
				if (popupDataList != undefined && popupDataList.length > 0) {
					for (var i = 0; i < popupDataList.length; i++) {
						// console.log("[loadConfig] popupDataList", i, popupDataList[i]);
						if (popupDataList[i] == 'default') {
							for (var j = 0; j < defaultPopUpDataList.length; j++) {
								this.popupDataList.push(defaultPopUpDataList[j]);
							}
						} else {
							this.popupDataList.push(popupDataList[i]);
						}
					}
				} else {
					this.popupDataList = defaultPopUpDataList;
					console.log("[loadConfig] popupDataList 加载默认列表");
				}
				// console.log("[loadConfig] popupDataList:", this.popupDataList);
				
				// 加载弹窗(兑换地点)数据
				const popupExchgList = config.popupExchgList;
				if (popupExchgList != undefined && popupExchgList.length > 0) {
					for (var i = 0; i < popupExchgList.length; i++) {
						// console.log("[loadConfig] popupExchgList", i, popupExchgList[i]);
						this.popupExchgList.push(popupExchgList[i]);
					}
				}
				// console.log("[loadConfig] popupExchgList:", this.popupExchgList);
			},
			// 获取倒计时
			getCountdown() {
				// console.log(this.endSecond)
				if (this.endSecond > 0) {
					const now = Date.now() / 1000;
					const dif = this.endSecond - now;
					// const dif = 3600*24 - 60;
					if (dif > 0) {
						this.countdown = '距结束 ' + tools.convertSecondsToDHM(dif);
					} else {
						this.countdown = "活动已结束";
					}
					// this.countdown = tools.convertSecondsToHMS(dif);
				} else {
					this.countdown = "距结束 --天--小时";
				}
			},
			// 格式化 距离
			fmtDistanct(val) {
				return Math.round(val * 100 / 1000) / 100;
				/* if (val < 10000)
					return Math.round(val * 10 / 1000) / 10;
				else
					return Math.round(val / 1000); */
			},
			fmtMcTime(timestamp) {
				return tools.fmtMcTime(timestamp);
			},
			// 获取活动时间
			getActtime() {
				this.acttime = tools.getActtime(this.beginSecond, this.endSecond);
			},
			getTeamName(teamType, teamIndex) {
				return teamName[teamType][teamIndex];
			},
			getCardConfigQuery() {
				uni.request({
					url: apiCardConfigQuery,
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"token": this.token,
					},
					method: "POST",
					data: {
						ecId: this.ecId,
						pageName: this.pageName
					},
					success: (res) => {
						// console.log("getCardConfigQuery", res)
						const data = res.data.data;
						// console.log("configJson", data.configJson);
						const config = data.configJson != "" ? JSON.parse(data.configJson) : "";
						// console.log("configJson", data.configJson);
						/* const config = {
						"css": `
							.top{
								width: 100%;
								height: 170px;
								padding-top: 36px;
								justify-content: space-between;
								background-image: url('static/backgroud/top_bg_guoqing.png');
								background-repeat: no-repeat;
								background-position-y: 20%;
								background-size: cover;
							}
							.topbar-color{
								color: #ffffff;
							}
							.topbtm-name{
								background-color: #e68328 !important;
								color: #ffffff !important;
								opacity: 0.9;
							}
							.topbtm-egg{
								background-color: #e68328 !important;
								color: #ffffff !important;
								opacity: 0.9;
							}
							.btnBack{
								background-color: #ff0000 !important;
							}
							.main-bar{
								background-color: #ffd1d1 !important;
								color: #C40000 !important;
							}
							.swiper-item-button {
								background-color: #C40000 !important;
							}
							.uni-swiper-dot-active {
								background: #C40000 !important;
							}
						`,
						"tabActiveColor": "#ff0000",
						"popupDataList": [
							{
								"type": 2,
								"data": {
									"title": "基本图例",
									"img": "/static/common/jbtl.png"
								}
							}, {
								"type": 2,
								"data": {
									"title": "基本标识",
									"img": "/static/common/jbbs2.png"
								}
							},
							{
								"type": 7,
								"data": {
									"title": "活动规则",
									"content": "<li>赛期内随时参赛、不限完赛次数、起点任选、实时排名 <li>起点-各途经点-结束点完整打卡为1次有效完赛 <li>赛事如有疑问，请咨询微信客服",
									"imageList": [
										{
											"src": "/static/common/qrcode_wxkf.png",
											"width": "100px",
											"height": "100px"
										}
									]
								}
							},
							{
								"type": 7,
								"data": {
									"title": "活动奖励",
									"content": "<li>途经点打卡1次，获1个百味豆<br><li>每次正确答题，再获1个百味豆<br><li>20个百味豆兑换1个鸡蛋<br><li>上不封顶！随时兑换！<br><text style='font-size:12px;color:#999999;'>(限本次活动百味豆，兑换以“蛋叔券”为准)</text><br><li>健身又能“薅羊毛”~",
									"imageList": [
										{
											"src": "/static/common/jidanquan.png",
											"width": "80px",
											"height": "80px"
										}
									]
								}
							},
							{
								"type": 5,
								"data": {
									"title": "兑换地点",
									"img": "/static/common/wslgwcs.png",
									"point": {
										"longitude": 117.022194,
										"latitude": 36.661612,
										"name": "万盛隆购物超市"
									}
								}
							}
						],
						"popupExchgList": [
							{
								"type": 5,
								"data": {
									"title": "兑换地点",
									"img": "/static/common/wslgwcs.png",
									"point": {
										"longitude": 117.022194,
										"latitude": 36.661612,
										"name": "万盛隆购物超市"
									}
								}
							}
						]
						}; */
						
						this.loadConfig(config);
						this.getUnReadMessageQuery();
						this.matchRsDetailQuery();
						
						setTimeout(this.dealFirstEnter, 500);
					},
					fail: (err) => {
						console.log("getCardConfigQuery err", err)
					},
				});
			},
			// 卡片对应活动或赛事详情查询
			// getCardDetailQuery() {
			// 	uni.request({
			// 		url: apiCardDetailQuery,
			// 		header: {
			// 			"Content-Type": "application/x-www-form-urlencoded",
			// 			"token": this.token,
			// 		},
			// 		method: "POST",
			// 		data: {
			// 			ecId: this.ecId
			// 		},
			// 		success: (res) => {
			// 			// console.log("getCardDetailQuery", res)
			// 			const data = res.data.data;
			// 			this.mcType = data.mcType;
			// 			this.mcId = data.mcId;
			// 			this.mcName = data.mcName;
			// 			this.beginSecond = data.beginSecond;
			// 			this.endSecond = data.endSecond;
			// 			this.coiName = data.coiName;
			// 			this.teamNum = data.teamNum;
						
			// 			this.mcState = tools.checkMcState(this.beginSecond, this.endSecond);
						
			// 			this.getCountdown();
			// 			this.getActtime();
			// 			this.getCardRankDetailQuery();

			// 			this.clear();
			// 			this.interval = setInterval(this.getCountdown, 60000);
			// 		},
			// 		fail: (err) => {
			// 			console.log("getCardDetailQuery err", err)
			// 		},
			// 	});
			// },
			// 卡片对应线上赛多个活动查询
			matchRsDetailQuery() {
				uni.request({
					url: apiMatchRsDetailQuery,
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"token": this.token,
					},
					method: "POST",
					data: {
						ecId: this.ecId
					},
					success: (res) => {
						// console.log("matchRsDetailQuery", res);
						if (checkResCode(res)) {
							const data = res.data.data;
							this.mcType = data.mcType;
							this.mcId = data.mcId;
							this.mcName = data.mcName;
							this.beginSecond = data.beginSecond;
							this.endSecond = data.endSecond;
							this.nickName = data.nickName;
							this.totalNum = data.totalNum;
							this.totalDistanct = data.totalDistanct;
							this.totalDistanctRankNum = data.totalDistanctRankNum;
							this.totalCp = data.totalCp;
							this.totalCpRankNum = data.totalCpRankNum;
							this.totalSysPoint = data.totalSysPoint;
							this.totalSysPointRankNum = data.totalSysPointRankNum;
							this.fastPace = data.fastPace;
							this.fastPaceRankNum = data.fastPaceRankNum;
							// this.ocaRs = data.ocaRs;
				
							this.mcState = tools.checkMcState(this.beginSecond, this.endSecond);
				
							this.getCountdown();
							this.getActtime();
							this.compStatisticQuery();
							this.getCardRankDetailQuery();
				
							this.clear();
							this.interval = setInterval(this.getCountdown, 60000);
						}
					},
					fail: (err) => {
						console.log("matchRsDetailQuery err", err)
					},
				});
			},
			// 排名查询
			getCardRankDetailQuery() {
				uni.request({
					url: apiCardRankDetailQuery,
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"token": this.token,
					},
					method: "POST",
					data: {
						mcIdListStr: this.mcId,
						mcType: this.mcType,
						dispArrStr: this.dispArrStr
					},
					success: (res) => {
						// console.log("getCardRankDetailQuery", res);
						const rankdata = res.data.data;
						this.rankList.totalDistanceRs = rankdata.totalDistanceRs;
						this.rankList.totalCpRs = rankdata.totalCpRs;
						this.rankList.totalSysPointRs = rankdata.totalSysPointRs;
						this.rankList.fastPaceRs = rankdata.fastPaceRs;
					},
					fail: (err) => {
						console.log("getCardRankDetailQuery err", err);
					},
				});
			},
			// 赛事总成绩统计查询
			compStatisticQuery() {
				uni.request({
					url: apiCompStatisticQuery,
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"token": this.token,
					},
					method: "POST",
					data: {
						mcId: this.mcId
					},
					success: (res) => {
						// console.log("compStatisticQuery", res);
						if (res.data.code == 0) {
							const data = res.data.data;
							this.all_totalDistance = data.totalDistance;
							this.all_totalRightAnswerNum = data.totalRightAnswerNum;
							this.all_totalAnswerNum = data.totalAnswerNum;
							this.all_totalCp = data.totalCp;
							this.all_totalSysPoint = data.totalSysPoint;
						}
					},
					fail: (err) => {
						console.log("compStatisticQuery err", err);
					},
				});
			},
			// 卡片用户当前排名查询
			// getUserCurrentRankNumQuery() {
			// 	uni.request({
			// 		url: apiUserCurrentRankNumQuery,
			// 		header: {
			// 			"Content-Type": "application/x-www-form-urlencoded",
			// 			"token": this.token,
			// 		},
			// 		method: "POST",
			// 		data: {
			// 			ecId: this.ecId
			// 		},
			// 		success: (res) => {
			// 			// console.log("getUserCurrentRankNumQuery", res)
			// 			if (res.data.code == 0) {
			// 				const data = res.data.data;
			// 				const rankNum = data.rankNum;
			// 				this.dealNotice(rankNum);
			// 			}
			// 		},
			// 		fail: (err) => {
			// 			console.log("getUserCurrentRankNumQuery err", err)
			// 		},
			// 	});
			// },
			// 是否允许重新分组（报名）
			isAllowMcSignUp() {
				uni.request({
					url: apiIsAllowMcSignUp,
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"token": this.token,
					},
					method: "POST",
					data: {
						ecId: this.ecId
					},
					success: (res) => {
						// console.log("isAllowMcSignUp", res)
						if (res.data.code == 0) {
							const data = res.data.data;
							this.allowMcSignUp = data.allowSignUp;
						}
					},
					fail: (err) => {
						console.log("isAllowMcSignUp err", err)
					},
				});
			},
			// 未读消息列表查询
			getUnReadMessageQuery() {
				uni.request({
					url: apiUnReadMessageQuery,
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"token": this.token,
					},
					method: "POST",
					data: {
						relationType: 2,	// 类型 1 成就 2 卡片
						relationId: this.ecId
					},
					success: (res) => {
						// console.log("getUnReadMessageQuery", res);
						if (checkResCode(res)) {
							const unReadMessageRs = res.data.data;
							this.popupMessageList.length = 0;
							this.mqIdListStr = "";
							for (var i = 0; i < unReadMessageRs.length; i++) {
								let popupData = {
									type: 6,	// 6: 通知
									data: {}
								};
								this.messageKey += "-" + unReadMessageRs[i].mqId;
								popupData.data.mqType = unReadMessageRs[i].mqType;
								popupData.data.title = unReadMessageRs[i].mqTitle;
								popupData.data.message = unReadMessageRs[i].mqMessage;
								this.popupMessageList.push(popupData);
			
								// this.mqIdListStr += this.unReadMessageRs[i].mqId;
								// if (i < this.unReadMessageRs.length - 1) {
								// 	this.mqIdListStr += ",";
								// }
							}
			
							if (this.popupMessageList.length > 0) {
								const messageValue = uni.getStorageSync(this.messageKey);
								console.log("messageValue:", messageValue);
								if (!messageValue) {
									this.$refs.mypopupMessage.popupOpen();
									uni.setStorageSync(this.messageKey, true);
								}
							}
						}
					},
					fail: (err) => {
						console.log("getUnReadMessageQuery err", err);
					},
				});
			},
			// 标记消息已读
			readMessage() {
				uni.request({
					url: apiReadMessage,
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"token": this.token,
					},
					method: "POST",
					data: {
						"mqIdListStr": this.mqIdListStr
					},
					success: (res) => {
						// console.log("readMessage", res);
					},
					fail: (err) => {
						console.log("readMessage err", err);
					},
				});
			},
			btnBack() {
				// window.history.back();
				/* uni.navigateTo({
					url: "/pages/bm/style3/rankOverview?" + this.queryString
				}); */
				
				const url = `action://to_home/`;
				tools.appAction(url);
			},
			btnStartGame() {
				// uni.navigateTo({
				// 	url: "/pages/bm/style3/rankOverview?" + this.queryString
				// });
				const url = "/pages/bm/style3/rankOverview?" + this.queryString;
				tools.appAction(url, "uni.navigateTo");
			},
			btnInfo() {
				// console.log(this.$refs.mypopup);
				this.$refs.mypopup.popupOpen();
			},
			btnMessage() {
				// console.log(this.$refs.mypopup);
				this.$refs.mypopupMessage.popupOpen();
			},
			btnMyEgg() {
				// uni.navigateTo({
				// 	url: "/pages/achievement/index2?tabCurrent=2&" + this.queryString
				// });
				const url = "/pages/achievement/index2?tabCurrent=2&" + this.queryString;
				tools.appAction(url, "uni.navigateTo");
			},
			btnExchg() {
				this.$refs.mypopupExchg.popupOpen();
			},
			onClickTabItem(e) {
				if (this.tabCurrent != e.currentIndex) {
					this.tabCurrent = e.currentIndex;
				}
			}
		}
	}
</script>

<style scoped>
	.content {
		width: 100vw;
		height: 100vh;
	}

	.top-default {
		width: 100%;
		height: 170px;
		padding-top: 36px;
		justify-content: space-between;
		background-image: url("/static/backgroud/top_bg2.png");
		background-repeat: no-repeat;
		background-position: center;
		background-size: cover;
	}

	.topbar-color-default {
		color: #5b9100;
	}
	
	.topbtm {
		width: 100%;
		margin-bottom: 5px;
		justify-content: space-around;
	}
	
	.topbtm-name {
		max-width: 300rpx;
		padding: 3px 12px;
		background-color: #9fda39;
		border-radius: 5px;
		text-align: center;
		font-weight: 500;
		color: #497400;
		font-size: 14px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	
	.topbtm-egg {
		width: 60px;
		padding: 3px 12px;
		background-color: #9fda39;
		border-radius: 50px;
		text-align: center;
		color: #497400;
		font-size: 14px;
	}
	
	.topbtm-null {
		width: 60px;
		padding: 3px 12px;
	}
	
	.cal {
		width: 46rpx;
		height: 46rpx;
		margin-right: 20rpx;
	}
	
	.main {
		width: 100%;
		/* height: 70vh; */
		flex-grow: 1;
		justify-content: space-around;
		/* justify-content: space-between; */
	}
	
	.main-bar {
		width: 100%;
		height: 21px;
		background-color: #d8e8c6;
		
		font-size: 10px;
		font-weight: 500;
		color: #3d6706;
	}

	.main-tab {
		width: 90%;
		margin-top: 20rpx;
	}

	.tab-view {
		width: 100%;
		/* height: 69vh; */
		flex-grow: 1;
	}

	.btnBack {
		width: 70%;
		/* height: 6vh; */
		height: 80rpx;
		/* margin-bottom: 1vh; */
		margin-bottom: 20rpx;
		/* font-weight: bold; */
		color: white;
		font-size: 32rpx;
		line-height: 80rpx;
		border-radius: 27px;
		background-color: #81cd00;
	}
	
</style>