<template>
	<zzx-navbar :scrollable="true" :back="false" title="我的"></zzx-navbar>
	<view class="m-header">
		<image class="header-bgImg" src="@/static/mine_bg.png" mode="widthFix"></image>
	</view>
	<view class="m-content-box">
		<view class="m-content">
			<view class="m-header-info">
				<view class="user-info">
					<image class="user-header" v-if="token&&userinfo.userAvatar!==null" :src="userinfo.userAvatar" mode=""></image>
					<image class="user-header" v-else src="@/static/default-header.png" mode=""></image>
					<view class="user-nickname">{{token?userinfo.userName:'暂未登录'}}</view>
				</view>
				<view class="user-setting" @click="RouterUtils.to_page('/pages/mine/accountSetting/index')">
					<image src="@/static/account-setting.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
	</view>
	<view style="height: 100rpx;"></view>
	<view class="content">
		<view class="m-mineinfo-card">
			<view class="item-info" v-for="(item,index) in cardList" :key="index"
				@click="RouterUtils.to_page(`/pages/mine/orderInfo/index?selIndex=${index}`)">
				<zzx-icon :name="item.icon" size="30"></zzx-icon>
				<view class="item-text">{{item.name}}</view>
			</view>
		</view>
		<view class="m-function-list">
			<view class="list-title">我的功能</view>
			<view class="cell-list">
				<view class="item-cell-contact">
					<view class="">客服</view>
					<zzx-icon name="ashRight" size="10"></zzx-icon>
					<button class="contact-btn" open-type="contact"></button>
				</view>
				<zzx-cell text="发票" url=''></zzx-cell>
				<zzx-cell text="意见反馈" url='/pages/mine/feedback/index'></zzx-cell>
				<zzx-cell text="家庭成员" url="/pages/index/userList/index?name=家庭成员"></zzx-cell>
				<zzx-cell text="评价" url='/pages/mine/mineComments/index'></zzx-cell>
			</view>
		</view>
		<view class="login-tips" v-if="!token">
			<view class="">终于等到你！快去登录吧~</view>
			<view class="" @click="submitLogin">马上登录</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref, onMounted,computed } from 'vue'
	import zzxNavbar from '@/components/zzx-navbar/zzx-navbar.vue';
	import zzxCell from '@/components/zzx-cell/zzx-cell.vue';
	import { RouterUtils,TipsUtils } from '@/utils/util';
	import { http } from '@/utils/http'
	import { useCacheStore } from '@/stores/cache'
	import { onLoad, onPageScroll } from '@dcloudio/uni-app';
	const cache = useCacheStore()
	const token=computed(()=>{
		return cache.get('TOKEN')
	})
	const userinfo=computed(()=>{
		return cache.get('USER_INFO')
	})
	const userAvatar=ref('/src/static/default-header.png')
	const cardList = ref([{
		name: '全部订单',
		icon: 'm-allorder'
	}, {
		name: '待付款',
		icon: 'm-pendPay'
	}, {
		name: '待使用',
		icon: 'm-pendUse'
	}, {
		name: '已完成',
		icon: 'm-done'
	}, {
		name: '售后',
		icon: 'm-after-sales'
	},])
	onMounted(()=>{
		get_userinfo()
	})
	onPageScroll((e) => { })

	const submitLogin = () => {
		uni.login({
			provider: 'weixin',
			success: (res) => {
				get_logininfo(res.code)
			}
		})
	}

	const get_logininfo = (item:string) => {
		http.get('/user/loginByCode', {data:{code:item}, loading: true }).then(res => {
			cache.set('TOKEN',res.result.token)
			cache.set('USER_INFO',res.result)
			get_userinfo()
			TipsUtils.tips_toast('登录成功')
		})
	}
	
	const get_userinfo=()=>{
		http.get('/user/getUserInfo', { loading: true }).then(res => {
			cache.set('USER_INFO',res.result)
		})
	}
</script>

<style>
	page {
		background: #fff;
	}
</style>
<style lang="less" scoped>
	.m-header {
		.header-bgImg {
			width: 100%;
		}
	}

	.m-content-box {
		position: relative;

		.m-content {
			position: absolute;
			border-radius: 32rpx 32rpx 0 0;
			background: #fff;
			top: -60rpx;
			width: 100%;
			height: 160rpx;

			.m-header-info {
				.user-info {
					text-align: center;
					position: relative;

					.user-header {
						position: absolute;
						left: 50%;
						transform: translate(-50%, -50%);
						width: 160rpx;
						height: 160rpx;
						border-radius: 50%;
					}

					.user-nickname {
						position: absolute;
						left: 50%;
						transform: translate(-50%, -50%);
						top: 130rpx;
						font-weight: 800;
						font-size: 36rpx;
						color: #222222;
					}
				}

				.user-setting {
					position: absolute;
					right: 0;
					top: 24rpx;

					&>image {
						width: 170rpx;
					}
				}
			}
		}
	}

	.m-mineinfo-card {
		background: #F6F6F6;
		border-radius: 32rpx;
		padding: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		margin-top: 20rpx;

		.item-info {
			text-align: center;

			.item-text {
				font-size: 24rpx;
				color: #222222;
			}
		}
	}

	.m-function-list {
		margin-top: 28rpx;

		.list-title {
			font-weight: 800;
			font-size: 32rpx;
			color: #222222;
		}

		.cell-list {
			.item-cell-contact {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 28rpx;
				color: #181818;
				height: 70rpx;
				padding: 10rpx;
				position: relative;

				.contact-btn {
					position: absolute;
					width: 100%;
					height: 70rpx;
					opacity: 0;
					// background-color: #C8FF0C;
				}
			}

			.item-cell-contact:active {
				background-color: #ececec;
				border-radius: 20rpx;
			}
		}
	}

	.login-tips {
		position: fixed;
		bottom: 22rpx;
		width: 686rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 10rpx;
		background: rgba(0, 0, 0, 0.6);
		border-radius: 8rpx;
		z-index: 9999;

		&>view:first-child {
			font-size: 28rpx;
			color: #FFFFFF;
		}

		&>view:last-child {
			width: 160rpx;
			height: 60rpx;
			background: #C8FF0C;
			border-radius: 8rpx;
			font-size: 28rpx;
			color: #222222;
			text-align: center;
			line-height: 60rpx;
		}
	}
</style>