<template>
	<view class="my-userinfo-container">
		<!-- 头像和昵称区域 -->
		<view class="top-box">
			<image :src="avatarUrl" class="avatar"></image>
			<view class="nickname">盛大鹏</view>
		</view>

		<!-- 面板区域 -->
		<view class="panel-list">
			<!-- 第1个面板 -->
			<view class="panel">
				<view class="panel-body">
					<view class="panel-item">
						<text>0</text>
						<text>勋章</text>
					</view>
					<view class="panel-item">
						<text>0</text>
						<text>挑战历史</text>
					</view>
				</view>
			</view>

			<!-- 第2个面板 -->
			<view class="panel">
				<!-- 轮播图 -->
				<swiper :indicator-dots="false" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
					<swiper-item v-for="(item, i) in swiperList" :key="i">
						<navigator class="swiper-item">
							<image :src="item"></image>
						</navigator>
					</swiper-item>
				</swiper>
			</view>

			<!-- 第3个面板 -->
			<view class="panel">
				<view class="function-list">
					<view class="panel-list-item" v-for="(item,i) in functionList" :key="i">
						<image class="function-img" :src="item.uploadPath"></image>
						<text style="margin-right: 220px;">{{item.name}}</text>
						<uni-icons type="arrowright" size="15"></uni-icons>
					</view>
				</view>
			</view>
		</view>

		<tabbar :page="page"></tabbar>
	</view>
</template>

<script>
	import tabbar from "@/components/tabbar/tabbar.vue";
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				page: "",
				avatarUrl: uni.$http.baseUrl + "/profile//2024/01/18/6147d64a3b94d7b3d3cc35aaf8cbfe06.png",
				//轮播图数据列表
				swiperList: [],
				//主页功能列表
				functionList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getFunctionList()
		},
		onShow() {
			this.page = "my"
		},
		computed: {
			...mapState('m_user', ['userinfo'])
		},
		methods: {
			...mapMutations('m_user', ['updateAddress', 'updateUserInfo', 'updateToken']),
			async logout() {
				const [err, succ] = await uni.showModal({
					title: '提示',
					content: '确认退出登录吗？'
				}).catch(err => err)

				if (succ && succ.confirm) {
					this.updateAddress({})
					this.updateUserInfo({})
					this.updateToken('')
				}
			},
			async getSwiperList() {

				const {
					data: res
				} = await uni.$http.post('/small/customImage/listAll', {
					page: "my"
				})
				if (!res.success) return uni.$showMsg()

				res.data.forEach(item => {
					item.uploadPath = uni.$http.baseUrl + item.uploadPath
					this.swiperList.push(item.uploadPath)
				})
				uni.$showMsg('数据请求成功！')
			},
			async getFunctionList() {

				const {
					data: res
				} = await uni.$http.post('/small/project/home/listAll')
				if (!res.success) return uni.$showMsg()

				res.data.forEach(item => {
					item.uploadPath = uni.$http.baseUrl + item.uploadPath
				})
				this.functionList = res.data;
				uni.$showMsg('数据请求成功！')
			}
		},
		navClickHandler(item) {

		},
		components: {
			tabbar
		}
	}
</script>

<style lang="scss">
	.my-userinfo-container {
		height: 100%;
		background-color: #F4F4F4;

		.top-box {
			height: 400rpx;
			background-color: #aba9d0;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;

			.avatar {
				width: 90px;
				height: 90px;
				border-radius: 45px;
				border: 2px solid #FFF;
				box-shadow: 0 1px 5px black;
			}

			.nickname {
				font-size: 16px;
				color: black;
				font-family: Georgia, 'Times New Roman', Times, serif;
				margin-top: 10px;
			}
		}
	}

	.panel-list {
		padding: 0 10px;
		position: relative;
		top: -10px;

		.panel {
			background-color: white;
			border-radius: 3px;
			margin-bottom: 8px;

			.panel-title {
				line-height: 45px;
				padding-left: 10px;
				font-size: 15px;
				border-bottom: 1px solid #F4F4F4;
			}

			.panel-body {
				display: flex;
				justify-content: space-around;

				.panel-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: space-around;
					padding: 10px 0;
					font-size: 13px;

					.icon {
						width: 35px;
						height: 35px;
					}
				}
			}
		}
	}

	.function-img {
		width: 30px;
		height: 30px;
	}

	.panel-list-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 15px;
		padding: 0 10px;
		line-height: 45px;
	}

	swiper {
		height: 230rpx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
			border-radius: 4px;
		}
	}
</style>