<template>
	<view class="">
		<view class="absTop"></view>
		<view class="mainBox">
			<view class="exit flexA" :style="token?'visibility: visible':'visibility: hidden'" @click="showCancel = true">
					<image  src="/static/exit.png" mode=""></image>
					退出登录
			</view>
			<view class="topInfo flexA">
				<image :src="userInfo.avatar" mode=""></image>
				<view class="right">
					<view class="">{{userInfo.nickname || '未登录'}}</view>
					<view class="">{{userInfo.mobile || ''}}</view>
				</view>
			</view>
			<view class="money">
				<view class="item">
					<view class="qian"><text style="font-size: 32rpx;">¥</text>{{allMoney.money || 0}}</view>
					<view class="yue">账户余额</view>
					<view class="tixian flexC" @click="totackMoney(1)">提现</view>
				</view>
				<view class="item">
					<view class="qian"><text style="font-size: 32rpx;">¥</text>{{allMoney.score || 0}}</view>
					<view class="yue">保证金</view>
					<view class="tixian flexC" @click="totackMoney(2)">提现</view>
				</view>
				<view class="item">
					<image src="/static/bill.png" mode=""></image>
					<view class="tixian flexC" @click="totackMoney(3)">账户流水</view>
				</view>
			</view>
		</view>
		<view style="height: 462rpx;"></view>
		<view class="cenBox">
			<view class="item" @click="toMyPage(1)">
				<image src="/static/center1.png" mode=""></image>
				我买入的
			</view>
			<view class="item" @click="toMyPage(2)">
				<image src="/static/center2.png" mode=""></image>
				我卖出的
			</view>
			<view class="item" @click="toMyPage(3)">
				<image src="/static/center3.png" mode=""></image>
				我的发布
			</view>
			<view class="item" @click="toMyPage(4)">
				<image src="/static/center4.png" mode=""></image>
				我的收藏
			</view>
		</view>
		<view class="botBox">
			<view class="title">更多服务</view>
			<view class="group">
				<view class="item" v-for="(item,idx) in serviceList" :key="idx" @click="openService(idx)">
					<image :src="`/static/bot${idx+1}.png`" mode=""></image>
					{{item.name}}
				</view>
			</view>
		</view>

		<u-modal :show="showCancel" :showCancelButton="true" @confirm="confirmCancel" @cancel="showCancel=false" content='您确定要退出登录吗'></u-modal>
		<u-popup :show="showService" mode="center"  bgColor="transparent" :round="15" >
		    <view class="centerBox">
					<image class="potImg" src="/static/codeBg.png" mode=""></image>
					<view class="popTitle">	{{Service==1?'我的客服':'品牌入驻'}} </view>
					<image class="code" :src="qrCode" mode=""></image>
					<view class="dashed"></view>
					<view class="botText">长按识别二维码</view>
		    </view>
			<view class="close" @click="showService=false">
				<image class="wh100" src="/static/close.png" mode=""></image>
			</view>
		</u-popup>
		<Botton  :flag="2"></Botton>

	</view>
</template>

<script>
	import Botton from "@/components/Botton.vue"
	import {toa} from '@/utils/toast.js'
	import { getUserInfo,logotLogin,getContactQrcode } from '@/api/mine.js'
	
	export default {
		components: {
			Botton
		},
		data() {
			return {
				serviceList : [
				{name:'联系客服'},
				{name:'品牌入驻'},
				{name:'意见反馈'},
				{name:'常见问题'},
				{name:'我的任务'},
				{name:'我的点赞'},
				{name:'历史记录'},
				{name:'常用地址'},
				],
				showService:false,
				Service:0 ,// 是否是联系客服
				token:'',
				userInfo:{},
				allMoney:{},
				showCancel:false,
				qrCode:''
			}
		},
		onShow() {
			this.token = uni.getStorageSync('token') || ''
			this.userInfo = uni.getStorageSync('userInfo') || ''
			if(this.token){
				this.getUserInfo()
			}
			
		},
		methods: {
			async confirmCancel(){
				  try {
				    const res = await logotLogin()
					setTimeout(()=>{
						toa.success('退出成功')
					},200)
					uni.clearStorage()
					uni.navigateTo({
						url:'/pages/login/login'
					})
				    console.log('logotLogin', res)
				    // 保存数据
				  } catch (err) {
				 	uni.showToast({ title:err,icon:'none' })
				    console.log('logotLogin', err)
				  }
			},
			async getUserInfo(){
			  try {
			    const res = await getUserInfo()
			    console.log('getUserInfo', res)
				this.allMoney = res.user
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('getUserInfo', err)
			  }
			},
			totackMoney(type) {
				if(type==3) {
					uni.navigateTo({
						url:'/pages/mine/accountFlow'
					})
				}else {
					uni.navigateTo({
						url:'/pages/mine/withdrawal?type='+type
					})
				}
			},
			toMyPage(type){
				if(type==1) return uni.navigateTo({	url:'/pages/mine/buyerOrder'	})
				if(type==2) return uni.navigateTo({	url:'/pages/mine/sellerOrder'	})
				if(type==3) return uni.navigateTo({	url:'/pages/mine/myRelease'	})
				if(type==4) return uni.navigateTo({	url:'/pages/mine/myCollection'	})
			},
			openService(idx){
				if(idx==0)  {
					this.Service = 1	
					this.getContactQrcode(1)
				}
				if(idx==1)  {
					this.Service = 0
					this.getContactQrcode(2)
				}
				if(idx==2)  return uni.navigateTo({	url:'/pages/mine/Feedback'	})
				if(idx==3)  return uni.navigateTo({	url:'/pages/mine/commonProblem'	})
				
			},
			async getContactQrcode(type){
			  try {
			    const res = await getContactQrcode(type)
				this.qrCode = res.qrcode
				this.showService = true
			    // console.log('getContactQrcode', res)
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('getContactQrcode', err)
			  }
			},
		},
	}
</script>

<style lang="less">
	page {
		 background: rgba(246,246,246,1);
	}
	.absTop {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 306rpx;
		opacity: 1;
		background: linear-gradient(180deg, rgba(255,249,221,1) 0%, rgba(255,249,221,0) 100%);
		z-index: 0;
	}
	.mainBox {
		position: absolute;
		left: 0;
		top: 0;
		padding: 28rpx 32rpx;
		box-sizing: border-box;
		.exit {
			justify-content: flex-end;
			image {
				width: 40rpx;
				height: 40rpx;
			}
			 color: rgba(0,0,0,1);
			 font-size: 24rpx;
			 font-weight: 400;
		}
		.topInfo {
			image {
				margin-right: 24rpx;
				width: 108rpx;
				height: 108rpx;
				border-radius: 50%;
			}
			view:nth-child(1){
				margin: 8rpx 0;
				 font-size: 32rpx;
				 font-weight: 700;
			}
			view:nth-child(2){
				  color: rgba(0,0,0,0.9);
				  font-size: 28rpx;
			}
		}
		.money {
			display: flex;
			justify-content: space-around;
			margin: 32rpx auto 24rpx;
			width: 702rpx;
			height: 250rpx;
			border-radius: 24rpx;
			opacity: 1;
			background: rgba(255,255,255,1);
			.item {
				padding: 32rpx 0;
				width: 144rpx;
				position: relative;
				image {
					width: 80.74rpx;
					height: 75.09rpx;
				}
				display: flex;
				flex-direction: column;
				align-items: center;
				.qian {
					 color: rgba(248,83,23,1);
					 font-size: 44rpx;
				}
				.yue {
					margin-top: 18rpx;
					 color: rgba(0,0,0,0.9);
					 font-size: 24rpx;
				}
				.tixian {
					position: absolute;
					left: 0;
					bottom: 32rpx;
					width: 144rpx;
					height: 56rpx;
					border-radius: 50rpx;
					opacity: 1;
					background: rgba(254,208,0,1);	
					 color: rgba(0,0,0,0.9);
					 font-size: 24rpx;
					 font-weight: 700;
				}
			}
		}
	}
	.cenBox {
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		margin: 24rpx auto 24rpx;
		width: 702rpx;
		height: 184rpx;
		border-radius: 24rpx;
		background: rgba(255,255,255,1);
		.item {
			display: flex;
			align-items: center;
			flex-direction: column;
			image {
				width: 64rpx;
				height: 64rpx;
				margin-bottom: 16rpx;
			}
			 color: rgba(100,101,102,1);
			 font-size: 26rpx;
		}
	}
	.botBox {
		margin: 0 auto;
		padding: 32rpx 0;
		box-sizing: border-box;
		width: 702rpx;
		height: 464rpx;
		border-radius: 24rpx;
		opacity: 1;
		background: rgba(255,255,255,1);
		.group {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			.item {
				width: 174rpx;
				height: 184rpx;
				display: flex;
				align-items: center;
				flex-direction: column;
			}
			image {
				width: 64rpx;
				height: 64rpx;
				margin-bottom: 16rpx;
			}
			 color: rgba(100,101,102,1);
			 font-size: 26rpx;
		}
		.title {
			margin: 0 0 56rpx 32rpx;
			 color: rgba(50,50,51,1);
			 font-size: 28rpx;
			 font-weight: 700;
		}
	}
	
	.centerBox {
		box-sizing: border-box;
		width: 622rpx;
		height: 656rpx;
		border-radius: 15rpx;
		position: relative;
		// background: url(/static/codeBg.png);
		.potImg {
			position: absolute;
			top: 0;
			left: 0;
			width: 622rpx;
			height: 656rpx;
		}
		.popTitle {
			position: absolute;
			top: 56rpx;
			left: 50%;
			transform: translateX(-50%);
			 color: rgba(0,0,0,0.9);
			 font-size: 34rpx;
			 font-weight: 700;
		}
		.code {
			position: absolute;
			left: 150rpx;
			top: 160rpx;
			width: 326rpx;
			height: 326rpx;
		}
		.botText {
			position: absolute;
			bottom: 56rpx;
			 color: rgba(0,0,0,0.4);
			 font-size: 28rpx;
			left: 50%;
			transform: translateX(-50%);
		}
		.dashed {
			position: absolute;
			bottom: 50rpx;
			left: 0;
			border-top: 2rpx solid #000;
			height: 0rpx;
		}
	
	}
		.close {
			width: 48rpx;
			height: 48rpx;
			margin: 0 auto;
			margin-top: 24rpx;
		}
</style>