<template>
	<view class="ezy-my-page">
		<view class="icon-title-navBar-box">
			<view class="nav-bar-title"></view>
		</view>
		<view class="my-page-box">
			<view class="my-head-box">
				<icon class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.icon + ')'}"></icon>
				<view class="head-content-box">
					<text>{{myInfoData.nickName}}</text>
					<!-- <view class="ezy-jf-box" v-if="loginFlag">
						<icon class="jf-icon"></icon>
						<text class="jf-text">{{myInfoData.credit}}</text>
					</view> -->
				</view>
			</view>
			<!-- 图 -->
			<view class="my-banner-img"></view>

			<!-- 设置 -->
			<view class="my-list-box">
				<view class="list-item" @click="yingyongshezhi">
					<icon class="list-icon yysz-icon"></icon>
					<text>应用设置</text>
				</view>
			</view>
		</view>
		<!-- 底部 -->
		<CustomTabBar :currentTabNumber="3"></CustomTabBar>
	</view>
</template>

<script setup>
	import {
		myInfo,
		zhuxiao,
		duihuanmaCode,
		myCardList,
		commonCardList
	} from '@/api/my.js'
	import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		reactive,
		ref
	} from "vue";

	let myInfoData = reactive({
		userImg: '',
		userName: '',
		credit: '',
		vipFlag: '',
		nickName: '',
		icon: '',
	});


	// 获取用户数据
	function getMyInfo() {
		myInfo({}).then(res => {
			myInfoData.userName = res.data.userName;
			myInfoData.nickName = res.data.nickName;
			if (res.data.nickName) {
				myInfoData.nickName = res.data.nickName;
			} else {
				myInfoData.nickName = '鹅状元';
			}
			if (res.data.icon) {
				myInfoData.icon = res.data.icon;
			} else {
				getUserImg(res.data.growthType)
			}
		})
	}

	// 获取用户头像
	function getUserImg(data) {
		switch (data) {
			case 0:
				myInfoData.icon = 'static/images/my/head-img0.png'
				break;
			case 1:
				myInfoData.icon = 'static/images/my/head-img1.png'
				break;
			case 2:
				myInfoData.icon = 'static/images/my/head-img2.png'
				break;
			case 3:
				myInfoData.icon = 'static/images/my/head-img3.png'
				break;
			default:
				myInfoData.icon = 'static/images/my/head-unlogin-img.png'
				break;

		}
	}
	
	function yingyongshezhi() {
		uni.redirectTo({
			url: '/pages/chanpinMy/myInfo'
		})
	}

	onLoad((options) => {
		getMyInfo();
	})
</script>