<template>
	<view>
		<fs-avatar src="/static/images/my/my-bg.png" shape="square" width="100%" height="288rpx"></fs-avatar>
		<view class="my-box">
			<view class="layout-box radius-lg top-box">
				<view class="user-info" v-if="userInfo.name">
					<fs-avatar size="140rpx" :src="userInfo.photo || userAvatar"></fs-avatar>
					<!-- <fs-wx-avatar v-else></fs-wx-avatar> -->
					
					<view class="top-box-content">
						<text class="vm title">{{userInfo.name}}</text>
						<fs-icon type="icon-sex-male" color="#2285FF" style="margin-left: 10rpx;" v-if="userInfo.sex === '1'"></fs-icon>
						<fs-icon type="icon-sex-female" colorType="error" style="margin-left: 10rpx;" v-if="userInfo.sex === '2'"></fs-icon>
					</view>
				</view>
				<view v-else class="user-info">
					<fs-avatar size="140rpx" link="/modules/common/login/login" border>去登录</fs-avatar>
				</view>
				
				<fs-icon
					v-if="userInfo.name"
					class="top-box-edit"
					type="icon-edit"
					size="40rpx"
					link="./userInfo">
				</fs-icon>
				
				<view :style="{'margin-top': userInfo.name ? '70rpx' : '20rpx'}">
					<fs-divide-list :list="shortcutList">
						<template #default="{item}">
							<view class="top-box-hd">{{item.num || 0}}</view>
							<view class="content">{{item.title}}</view>
						</template>
					</fs-divide-list>
				</view>
			</view>
		</view>
		
		<fs-card gutter :titleStyle="{padding: '0'}">
			<template #title>
				<view class="title-hd" >常用工具</view>
			</template>
			<fs-grid :columnNum="4">
				<fs-grid-item v-for="(item, index) in 4" :key="index">
					<fs-avatar src="/static/images/my/invoice.png" size="80rpx"></fs-avatar>
					<view class="content">我的发票</view>
				</fs-grid-item>
			</fs-grid>
		</fs-card>
		
		<fs-cell-group arrow border gutter>
			<fs-cell link="/modules/common/licensePlate/list" value="车辆管理">
				<template #title>
					<fs-icon type="icon-car" colorType="primary"></fs-icon>
				</template>
			</fs-cell>
			<fs-cell link="/modules/common/address/list" value="地址管理">
				<template #title>
					<fs-icon type="icon-location" colorType="primary"></fs-icon>
				</template>
			</fs-cell>
			<fs-cell link="/modules/common/org" value="组织架构">
				<template #title>
					<fs-icon type="icon-org" colorType="primary"></fs-icon>
				</template>
			</fs-cell>
			<fs-cell link="/modules/common/addrbook/list" value="通讯录">
				<template #title>
					<fs-icon type="icon-tongxunlu" colorType="primary"></fs-icon>
				</template>
			</fs-cell>
			<fs-cell link="/modules/common/notice" value="我的消息">
				<template #title>
					<fs-icon type="icon-notice" colorType="primary"></fs-icon>
				</template>
			</fs-cell>
			<fs-cell link="/modules/common/feedback" value="意见反馈">
				<template #title>
					<fs-icon type="icon-feedback" colorType="primary"></fs-icon>
				</template>
			</fs-cell>
			<fs-cell link="/modules/common/version" value="版本记录">
				<template #title>
					<fs-icon type="icon-version" colorType="primary"></fs-icon>
				</template>
			</fs-cell>
		</fs-cell-group>
		
		<fs-gutter height="60rpx"></fs-gutter>
		<fs-button round block @click="handleLogout">退出登录</fs-button>
		<fs-gutter height="60rpx"></fs-gutter>
		
		<wx v-model="showLogin"></wx>
	</view>
</template>

<script setup>
import { computed, ref } from 'vue'
import useUser from '@/hooks/useUser'
import userAvatar from '/static/images/user-avatar.png'
import wx from '@/business/wx-login.vue'

const userInfo = useUser()
const shortcutList = ref([
	{
		title: '我的访客',
		num: 10
	},
	{
		title: '我的访客',
		num: 10
	}
])

const showLogin = ref(true)

const handleLogout = () => {
	store.dispatch('logout').then(res => {
		console.log('logout')
	})
}
</script>

<style lang="scss" scoped>
.my-box{
	padding: var(--gutter);
	margin-top: -200rpx;
	z-index: 100;
	position: relative;
}
.top-box{
	position: relative;
	
	&-edit{
		position: absolute;
		top: 10rpx;
		right: 20rpx;
	}
	
	&-hd{
		font-size: 23px;
		font-weight: bold;
	}
	
	&-content{
		padding: 10rpx 0;
	}
}
.user-info{
	position: absolute;
	z-index: 10;
	left: 50%;
	top: -70rpx;
	transform: translateX(-50%);
	text-align: center;
}
</style>
