<template>
	<div class="person-tab">
		<div class="card">
			<div class="card__header">
				<span v-if="userInfo" class="el-dropdown-link">
					<img class="avatar" :src="userInfo.headImg" />
					<span class="name">{{ userInfo.nickName }}</span>
				</span>
				<span class="value" style="margin: 20px 0px; padding: 20px 0px; font-size: 28px">{{
					timeState
				}}</span>
			</div>
			<!-- <p class="label">今日晴，0℃ - 10℃，天气寒冷，注意添加衣物。</p> -->
			<div class="card__container" style="padding-top: 20px">
				<span class="label" style="font-size: 18px">{{ nowDate }}</span>
				<ul class="count-sales__cop">
					<li>
						<!-- <img src="https://tool.lu/netcard/" /> -->
						<!-- https://ip.tool.lu/ -->
						<!-- http://aider.meizu.com/app/weather/listWeather?cityIds=101270101 -->
						<p>{{ value1 }}</p>
						<p>{{ value2 }}</p>
						<p>{{ value3 }}</p>
						<!-- <div class="fall">
							<i class="el-icon-bottom-right"></i>
							<span>-4℃</span>
						</div> -->
					</li>
					<li>
						<div class="login_panle_right" />
					</li>
					<!-- <li>
						<span>日同比</span>

						<div class="rise">
							<i class="el-icon-top-right"></i>
							<span>+7%</span>
						</div>
					</li> -->
				</ul>
			</div>

			<!-- <div class="card__footer">
				<span class="label">今日流量</span>
				<span class="value">1582</span>
			</div> -->
		</div>
	</div>
</template>

<script lang="ts">
import { ElNotification } from "element-plus";
import { computed, defineComponent, inject, onBeforeUnmount, onMounted, ref } from "vue";
import { useStore } from "vuex";
import { isPc } from "/@/core/utils";
export default defineComponent({
	setup() {
		const ifPc = isPc() ? true : false;
		// 请求服务
		const service = inject<any>("service");
		const store = useStore();
		// 用户信息
		const userInfo = computed<any>(() => store.getters.userInfo);
		// 数据列表
		const list = ref<any[]>([]);
		const value1 = ref<string>("");
		const value2 = ref<string>("");
		const value3 = ref<string>("");
		const nowDate = ref<string>("");
		const timeState = ref<string>("");
		onMounted(async () => {
			ElNotification.success({
				title: "更新公告V3.5.2",
				dangerouslyUseHTMLString: true,
				message: `<strong>
					<p>#修复了已知BUG</p>
					<p>#增加租机台账</p>
					</strong>`,
				position: "bottom-left",
				showClose: false,
				offset: 30
			});
			setInterval(formatDate, 500);
			list.value = await service.shuyouUtils.getWeatherCD();
			if (list.value.code == 200) {
				let value = list.value.value[0];
				let weathers = value.weathers[0];
				value1.value =
					value.city +
					" " +
					weathers.weather +
					" " +
					weathers.temp_night_c +
					"℃ ~ " +
					weathers.temp_day_c +
					"℃";
				value2.value = "空气质量：" + value.pm25.quality + ", pm2.5：" + value.pm25.pm25;
				value3.value = value.indexes[3].content;
				if (!ifPc) {
					value1.value = "";
					value2.value = "";
					value3.value = "";
				}
				// console.log(list.value.value[0].city);
				// console.log(list.value.value[0].weathers[0].weather);
				// console.log(list.value.value[0].weathers[0].temp_night_c);
				// console.log(list.value.value[0].weathers[0].temp_day_c);
				// console.log(list.value.value[0].pm25.pm25);
				// console.log(list.value.value[0].pm25.quality);
				// console.log(list.value.value[0].indexes[0].content);
			}
			// let arr = [];
			// let valueArr = [];
			// list.value.forEach((element) => {
			// 	arr.push(element.name);
			// 	valueArr.push({
			// 		value: element.game_count,
			// 		name: element.name
			// 	});
			// });
			// nameList.value = arr;
			// valueList.value = valueArr;
		});
		function formatDate() {
			let date = new Date();
			let year = date.getFullYear(); // 年
			let month = date.getMonth() + 1; // 月
			let day = date.getDate(); // 日
			let week = date.getDay(); // 星期
			let weekArr = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
			let h = date.getHours(); // 时
			let hour = h < 10 ? "0" + h : h; // 如果只有一位，则前面补零
			let m = date.getMinutes(); // 分
			let minute = m < 10 ? "0" + m : m; // 如果只有一位，则前面补零
			let s = date.getSeconds(); // 秒
			let second = s < 10 ? "0" + s : s; // 如果只有一位，则前面补零
			nowDate.value = `${year}-${month}-${day} ${weekArr[week]} ${hour}:${minute}:${second}`;
			//
			if (h < 10) {
				timeState.value = "早上好，请开始一天的工作吧";
			} else if (h < 12) {
				timeState.value = "上午好，喝口水再工作吧";
			} else if (h < 13) {
				timeState.value = "中午好，干饭了";
			} else if (h < 13 && m < 30) {
				timeState.value = "中午好，睡个午觉吧";
			} else if (h < 18) {
				timeState.value = "下午好，记得多喝热水";
			} else {
				timeState.value = "晚上好，总结一下今天的工作吧";
			}
			if (!ifPc) {
				nowDate.value = "";
				timeState.value = "";
			}
		}
		// onBeforeUnmount(async () => {
		// 	if (formatDate) {
		// 		clearInterval(formatDate); // 在Vue实例销毁前，清除时间定时器
		// 	}
		// });
		return {
			list,
			value1,
			value2,
			value3,
			nowDate,
			timeState,
			userInfo
		};
	}
	// data() {
	// 	return {
	// 		nowDate: "", // 当前日期
	// 		timeState: "早上好，请开始一天的工作吧"
	// 	};
	// },
	// methods: {
	// 	currentTime() {
	// 		setInterval(this.formatDate, 500);
	// 	},
	// 	formatDate() {
	// 		let date = new Date();
	// 		let year = date.getFullYear(); // 年
	// 		let month = date.getMonth() + 1; // 月
	// 		let day = date.getDate(); // 日
	// 		let week = date.getDay(); // 星期
	// 		let weekArr = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
	// 		let h = date.getHours(); // 时
	// 		let hour = h < 10 ? "0" + h : h; // 如果只有一位，则前面补零
	// 		let m = date.getMinutes(); // 分
	// 		let minute = m < 10 ? "0" + m : m; // 如果只有一位，则前面补零
	// 		let s = date.getSeconds(); // 秒
	// 		let second = s < 10 ? "0" + s : s; // 如果只有一位，则前面补零
	// 		this.nowDate = `${year}-${month}-${day} ${weekArr[week]} ${hour}:${minute}:${second}`;
	// 		//
	// 		if (h < 10) {
	// 			this.timeState = "早上好，请开始一天的工作吧";
	// 		} else if (h < 12) {
	// 			this.timeState = "上午好，休息一下再工作吧";
	// 		} else if (h < 14) {
	// 			this.timeState = "中午好，干饭了";
	// 		} else if (h < 18) {
	// 			this.timeState = "下午好，记得多喝热水";
	// 		} else {
	// 			this.timeState = "晚上好，总结一下今天的工作吧";
	// 		}
	// 	},
	// 	getWeather() {}
	// },
	// mounted() {
	// 	this.currentTime();
	// 	this.getWeather();
	// },
	// // 销毁定时器
	// beforeDestroy() {
	// 	if (this.formatDate) {
	// 		clearInterval(this.formatDate); // 在Vue实例销毁前，清除时间定时器
	// 	}
	// }
});
</script>

<style lang="scss" scoped>
.person-tab {
	height: 300px;
	padding: 0 20px;

	.card__header {
		margin-right: 10px;
		// cursor: pointer;

		.el-dropdown-link {
			display: flex;
			align-items: center;
		}

		.avatar {
			// margin-top: 5px;
			height: 35px;
			width: 35px;
			border: 1px solid rgb(0, 0, 0);
			border-radius: 35px;
		}

		.name {
			white-space: nowrap;
			font-size: 28px;
			font-weight: bold;
			margin-left: 15px;
			margin-right: 15px;
		}

		.el-icon-arrow-down {
			margin-left: 10px;
		}
	}
}

.count-sales {
	&__cop {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 150px;

		li {
			p {
				font-size: 14px;
				margin-top: 5px;
			}

			// display: flex;
			list-style: none;
			flex: 1;
			color: #353434;

			.fall,
			.rise {
				display: flex;
				align-items: center;
				margin-left: 10px;
			}

			.fall {
				color: #13ae7c;
			}

			.rise {
				color: #f21e37;
			}

			.login_panle_right {
				background-image: url("../../../assets/icon/bg/undraw_programming_re_kg9v.svg");
				background-size: cover;
				height: 200px;
				width: 300px;
				float: right !important;
			}
		}
	}
}
</style>
