<template>
	<view class="user">
		<view class="user-navbar" :style="{'height': (statusBarHeight+44)+'px'}">
			<u-navbar :bgColor="bgColor" :fixed="false" title="我的">
				<view class="u-nav-slot" slot="left"></view>
				<view class="u-nav-slot" slot="content">
					<view class="nav"></view>
				</view>
			</u-navbar>
		</view>
		<view class="blank" :style="{'height': (statusBarHeight+44)+'px'}"></view>
		<view class="user-list">
			<view class="users">
				<view class="a" @click="openPage(1)">
					<image class="avater" v-if="userInfo.id" :src="userInfo.avatar?baseUrl+userInfo.avatar:'https://zhengxin.njrenzhou.cn/static/default.png'"></image>
					<image class="avater" v-else src="https://zhengxin.njrenzhou.cn/static/default.png"></image>
					<view class="name">{{userInfo.id?userInfo.nickname:"登录"}}</view>
					<image class="edit" v-if="userInfo.id" src="https://zhengxin.njrenzhou.cn/static/icon-edit.png"></image>
				</view>
				<view class="b" @click="openPage(2)">
					<image src="https://zhengxin.njrenzhou.cn/static/icon-site.png"></image>
				</view>
			</view>
			<view class="info">
				<view class="item" @click="openPage(3)"><text>{{info.event_count?info.event_count:0}}</text>我的发布</view>
				<view class="item" @click="openPage(4)"><text>{{info.collect_count?info.collect_count:0}}</text>我的收藏</view>
				<view class="item" @click="openPage(5)"><text>{{info.follow_count?info.follow_count:0}}</text>我的关注</view>
				<view class="item" @click="openPage(6)"><text>{{info.view_count?info.view_count:0}}</text>浏览记录</view>
			</view>
			<view class="menu">
				<view class="item" @click="openPage(7)">
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-user-01.png"></image>我的钱包
					</view>
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-arrow.png"></image>
					</view>
				</view>
				<view class="item" @click="openPage(11)">
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-user-05.png"></image>加入云股东
					</view>
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-arrow.png"></image>
					</view>
				</view>
				<view class="item" @click="openPage(8)">
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-user-02.png"></image>支付记录
					</view>
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-arrow.png"></image>
					</view>
				</view>
				<view class="item" @click="openPage(9)">
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-user-03.png"></image>联系客服
					</view>
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-arrow.png"></image>
					</view>
				</view>
				<view class="item" @click="openPage(10)">
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-user-04.png"></image>意见反馈
					</view>
					<view class="fl">
						<image src="https://zhengxin.njrenzhou.cn/static/icon-arrow.png"></image>
					</view>
				</view>
			</view>
		</view>
		<foo-bar @toIndex="toIndex" :home="3"></foo-bar>
		<u-popup :show="show" :round="10" mode="center" @close="close" @open="open">
			<view class="wechat">
				<view class="title">联系客服</view>
				<view class="info">
					<view class="item" v-for="(a,i) in lianxiInfo" :key="i" v-if="i<=2">{{a.title}}：<text>{{a.number}}</text></view>
				</view>
				<view class="btn" @click="show = false">我知道了</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import fooBar from '@/components/fooBar/fooBar.vue'
	export default {
		components: {
			fooBar
		},
		data() {
			return {
				show: false,
				statusBarHeight: 0,
				bgColor: "transparent",
				index: 3,
				userInfo: {},
				info: {},
				baseUrl: "",
				lianxiInfo: []
			}
		},
		
		onLoad() {
			uni.hideTabBar();
			this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.baseUrl = this.$baseUrl;
		},
		onShow() {
			if(uni.getStorageSync("token")){
				this.getUserInfo()
			}else{
				this.userInfo = {}
			}
		},
		methods: {
			//联系客服
			async getlianxi() {
				const { code, data } = await this.$api.getlianxi({})
				if(code == 1){
					this.lianxiInfo = data
					this.show = true
				}
			},
			//获取用户信息
			async getUserInfo() {
				const { code, data , msg } = await this.$api.getMemberInfo({token: uni.getStorageSync("token")});
				if(code == 1){
					uni.setStorageSync('userInfo', data.user);
					this.userInfo = data.user;
					this.getHomeInfo();
				}else{
					uni.showToast({
						title: msg,
						icon: "none",
					})
				}
			},
			openPage(index,id){
				if(index == 2){
					uni.navigateTo({
						url: "/pages/user/site"
					})
					return ;
				}
				if(!uni.getStorageSync("token")){
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return ;
				}
				if(index == 1){
					uni.navigateTo({
						url: "/pages/user/personal"
					})
				}else if(index == 3){
					uni.navigateTo({
						url: "/pages/user/release"
					})
				}else if(index == 4){
					uni.navigateTo({
						url: "/pages/user/like"
					})
				}else if(index == 5){
					uni.navigateTo({
						url: "/pages/user/collect"
					})
				}else if(index == 6){
					uni.navigateTo({
						url: "/pages/user/history"
					})
				}else if(index == 7){
					uni.navigateTo({
						url: "/pages/user/wallet"
					})
				}else if(index == 8){
					uni.navigateTo({
						url: "/pages/user/payList"
					})
				}else if(index == 9){
					this.getlianxi();
					
				}else if(index == 10){
					uni.navigateTo({
						url: "/pages/user/feedback"
					})
				}else if(index == 11){
					uni.navigateTo({
						url: "/pages/user/about"
					})
				}
			},
			//官方公告
			async getHomeInfo() {
				const { code, data } = await this.$api.getHomeInfo({token: uni.getStorageSync("token")})
				if(code == 1){
					this.info = data.user
				}
			},
			
			open() {
			  // console.log('open');
			},
			close() {
			  this.showPopup = false
			  // console.log('close');
			},
			async toIndex(index) {
				let that = this
				that.index = index
				if (index == 0) {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}else if (index == 2) {
					uni.switchTab({
						url: '/pages/release/index'
					})
				} else if (index == 3) {
					uni.switchTab({
						url: '/pages/user/index'
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.user {
		min-height: 100vh;
		background: url(https://zhengxin.njrenzhou.cn/static/bg.png) center top no-repeat;
		background-size: 100% auto;
		padding-bottom: 150rpx;
		overflow: hidden;
		box-sizing: border-box;
		.wechat{
			width: 620rpx;
			height: 510rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			text-align: center;
			.title{
				font-weight: 500;
				font-size: 36rpx;
				color: #333333;
				padding: 30rpx 0;
				border-bottom: 1px solid #EAEAEA;
			}
			.info{
				padding: 30rpx 50rpx;
				overflow: hidden;
				.item{
					text-align: left;
					line-height: 60rpx;
					font-weight: 500;
					font-size: 30rpx;
					color: #999999;
					text{
						color: #333333;
					}
				}
			}
			.btn{
				width: 300rpx;
				height: 90rpx;
				background: #FFFFFF;
				border-radius: 90rpx;
				border: 1px solid #00C6A9;
				text-align: center;
				font-weight: 500;
				font-size: 30rpx;
				color: #00C6A9;
				line-height: 90rpx;
				margin: 0 auto;
				margin-top: 20rpx;
			}
		}
		&-navbar{
			position: fixed;
			left: 0;
			right: 0;
			top: 0;
			z-index: 12;
			width: 100%;
			background: url(https://zhengxin.njrenzhou.cn/static/bg.png) center top no-repeat;
			background-size: 100% auto;
		}
		&-list{
			overflow: hidden;
			margin-top: 45rpx;
			.menu{
				width: 700rpx;
				min-height: 462rpx;
				background: #FFFFFF;
				box-shadow: 0px 3rpx 10rpx 0px rgba(9,44,39,0.05);
				border-radius: 20rpx;
				margin: 0 auto;
				margin-top: 50rpx;
				padding: 0 30rpx;
				box-sizing: border-box;
				.item{
					display: flex;
					align-items: center;
					justify-content: space-between;
					border-top: 1px solid #EAEAEA;
					padding: 35rpx 0;
					overflow: hidden;
					position: relative;
					&:first-child{
						border-color: #FFFFFF;
					}
					.fl{
						display: flex;
						align-items: center;
						font-weight: 500;
						font-size: 30rpx;
						color: #333333;
						image{
							width: 45rpx;
							height: 45rpx;
							margin-right: 10rpx;
						}
						button{
							width: 100%;
							height: 100%;
							position: absolute;
							left: 0;
							top: 0;
							z-index: 2;
							opacity: 0;
						}
					}
					.fr{
						image{
							width: 45rpx;
							height: 45rpx;
						}
					}
				}
			}
			.info{
				display: flex;
				align-items: center;
				overflow: hidden;
				margin-top: 40rpx;
				.item{
					flex: 1;
					font-weight: 500;
					font-size: 24rpx;
					color: #333333;
					text-align: center;
					text{
						display: block;
						font-weight: bold;
						font-size: 36rpx;
						color: #333333;
						margin-bottom: 20rpx;
					}
				}
			}
			.users{
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 25rpx;
				.a{
					font-weight: 400;
					font-size: 34rpx;
					color: #333333;
					line-height: 36rpx;
					display: flex;
					align-items: center;
					.avater{
						width: 110rpx;
						height: 110rpx;
						border-radius: 50%;
						margin-right: 25rpx;
					}
					.edit{
						width: 45rpx;
						height: 45rpx;
						margin-left: 10rpx;
						margin-top: 10rpx;
					}
				}
				.b{
					image{
						width: 45rpx;
						height: 45rpx;
					}
				}
			}
		}
	}
</style>
