<template>
	<view>
		<view class="container">
			<view class="flex justify-between align-center" style="height: 200upx;" v-if="isLogin">
				<view class="padding-left">
					<view class="text-black text-bold text-xl">
						{{userData.nickName}}
						<!-- <u-button @click="logout" size="mini" style="margin-left: 10rpx;">退出</u-button> -->
					</view>
					<view class="flex align-center padding-top-sm">
						<view>
							<view class="text-black text-bold">{{+userData.usableHot}}</view>
							<view class="text-gray text-sm margin-top-xs">热力</view>
						</view>
						<view style="height: 60upx;border: #dadada 1px solid; margin: 0 30upx;"></view>
						<view>
							<view class="text-black text-bold">{{+userData.usablePoints}}</view>
							<view class="text-gray text-sm margin-top-xs">积分</view>
						</view>
						<view class="padding-left">
							<button class="cu-btn sm line-black round" @click="edit">
								<text class="cuIcon-post padding-right-xs"></text>
								<text v-if="!$u.test.isEmpty(userData.phone)">修改资料</text>
								<text v-else>完善个人信息</text>
							</button>
						</view>
					</view>
				</view>
				<view class="flex align-center">
					<view class="padding-right">
						<u-avatar :src="userData.avatar" size="120"></u-avatar>
					</view>
				</view>
			</view>
			<view class="text-center padding-sm" v-else>
				<view class="margin-bottom">
					<u-avatar size="120"></u-avatar>
				</view>
				<u-button class="custom-style" shape="circle" @click="toAuth">授权登录</u-button>
			</view>
			<view class="padding-lg flex justify-around align-center">
				<view class="flex" @click="navByIcon('','/pages/activityList/mine/pointsDetail')">
					<image src="/static/icon-points.png" style="width: 80upx;height: 80upx;"></image>
					<view class="padding-left-sm">
						<view class="text-bold text-lg">积分明细</view>
						<view class="text-gray">消费赚积分</view>
					</view>
				</view>
				<view class="flex" @click="navByIcon('','/pages/activityList/mine/boostDetail')">
					<image src="/static/icon-order.png" style="width: 80upx;height: 80upx;"></image>
					<view class="padding-left-sm">
						<view class="text-bold text-lg">热力明细</view>
						<view class="text-gray">助力奖赏</view>
					</view>
				</view>
			</view>
		</view>
		<view class="container">
			<block v-for="(item, index) in iconList" :key="index">
				<block v-if="item.name == '分割线'">
					<view class="padding">
						<u-line color="#d3d3d3"></u-line>
					</view>
				</block>
				<block v-else>
					<view class="flex justify-between align-center padding" @click="navByIcon(item.name,item.url)" v-if="item.show">
						<view class="flex align-center">
							<view class="flex align-center" style="width: 38rpx;height: 38rpx;">
								<image :src="item.icon" :style="{width: item.width, height: item.height}"></image>
							</view>
							<view class="text-black text-bold text-lg padding-left">{{item.name}}</view>
						</view>
						<view class="cuIcon-right"></view>
					</view>
				</block>
			</block>
		</view>
	</view>
</template>

<script>
	import {authUrl} from '@/common/conf/config.js'
	export default {
		props: {
			activityId: {
				type: String,
				default: '',
			}
		},
		data() {
			return {
				userId: '',
				userData: {},
				isLogin: true,
				isAgency: false,
				iconList: [
					{name: '我的礼品', icon: '/static/icon-gift.png', width: '36upx', height: '33upx', url: '/pages/activityList/mine/myGift', show: true},
					{name: '我的商品', icon: '/static/icon-delivery.png', width: '36upx', height: '36upx', url: '/pages/activityList/mine/pointsGoods/list', show: true},
					{name: '我的作品', icon: '/static/icon-music.png', width: '33upx', height: '32upx', url: '/pages/activityList/mine/myMusic', show: true},
					{name: '我的助力', icon: '/static/icon-history.png', width: '32upx', height: '32upx', url: '/pages/activityList/mine/myBoost', show: true},
					{name: '我的公益', icon: '/static/icon-welfare.png', width: '31upx', height: '31upx', url: '/pages/activityList/mine/myWelfare', show: true},
					{name: '分割线', icon: '', width: '', height: '', url: ''},
					{name: '成为代理', icon: '/static/icon-agency.png', width: '33upx', height: '32upx', url: '/pages/activityList/mine/agent/agentDetail', show: false},
					{name: '去推广', icon: '/static/icon-promote.png', width: '31upx', height: '30upx', url: '/pages/activityList/mine/agent/promote', show: false},
					{name: '我的推广', icon: '/static/icon-myPromote.png', width: '29upx', height: '30upx', url: '/pages/activityList/mine/agent/myPromote', show: false},
					{name: '我的收益', icon: '/static/icon-income.png', width: '24upx', height: '34upx', url: '/pages/activityList/mine/agent/myIncome/myIncome', show: false},
					{name: '更多活动', icon: '/static/icon-activity.png', width: '26upx', height: '31upx', url: '/pages/activityList/index', show: true},
					{name: '活动规则', icon: '/static/icon-rule.png', width: '29upx', height: '33upx', url: '', show: true}
				],
			}
		},
		mounted() {
			this.userId = uni.getStorageSync("userId")
			if (this.$u.test.isEmpty(this.userId)) {
				this.isLogin = false;
			} else {
				this.isLogin = true;
				this.getUserInfo();
			}
		},
		methods: {
			logout() {
				this.isLogin = false;
				uni.clearStorage()
			},
			toAuth() {
				let param = "pages/activityList/home/home?current=2&activityId=" + this.activityId;
				window.location.href = authUrl(param);
			},
			getUserInfo() {
				this.$u.api.user.detail({id: this.userId}).then(res => {
					this.userData = res;
				})
			},
			//跳转需要带参数
			edit() {
				uni.navigateTo({
					url: '/pages/activityList/mine/edit?userId=' + this.userData.id
				})
			},
			navByIcon(name, url) {
				if (name == '更多活动') {
					uni.reLaunch({
						url: url
					})
				} else {
					if (!this.isLogin) {
						this.toAuth();
					} else {		
						uni.navigateTo({
							url: url + "?activityId=" + this.activityId
						})
					}
				}
			}
		}
	}
</script>

<style>
	.container {
		margin: 30upx;
		background-color: #ffffff;
		border-radius: 28upx;
		box-shadow: -1upx -1upx 60upx #d8d8d8;
	}
	.custom-style {
		background-color: #5b3ee7;
		width: 200upx;
		height: 60upx;
		color: #ffffff;
	}
</style>
