<template>
	<view class="my">
		<view class="header">
			<u-row>
				<u-col span="2">
					<view class="avatar" @click="navigator('/pages/personalSettings/personalSettings')">
						<u-avatar :src="avatarUrl"></u-avatar>
					</view>
				</u-col>
				<u-col span="7" @click="navigator('/pages/personalSettings/personalSettings')">
					<view class="info">
						<view style="color: #ffffff;">{{info.Name[0].Value}}</view>
						<view style="color: #ffffff;">{{info.FPHONE}}</view>
					</view>
				</u-col>
				<u-col span="3">
					<view class="check" @click="navigator('/pages/realnameAuthentication/realnameAuthentication')">
						<text style="color: #ffffff;">{{checkStatus}}</text>
						<u-icon name="arrow-right" color="#ffffff" size="24" v-if="checkStatus"></u-icon>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="container">
			<view class="tab" v-for="(items,keys) in gridList" :key="keys">
				<u-tabs active-color="#7c59fc" :list="items"></u-tabs>
				<u-grid :col="4" :border="false">
					<u-grid-item v-for="(item,key) in items[0].list" :key="key" @click="navigator(item.url)">
						<u-icon
						label-pos="bottom"
						label-color="#000000"
						:label="item.label"
						:margin-top="20"
						:name="item.iconUrl"
						:size="60"></u-icon>
					</u-grid-item>
				</u-grid>
			</view>
		</view>
		
		<u-popup v-model="showPop" mode="center" border-radius="15">
			<view style="padding: 10px;">
				<view>
					<u-image width="400" height="400" :src="kfurl"></u-image>
				</view>
				<view style="text-align: center;color: #C8C9CC;">
					<div>长按保存到相册</div>
				</view>
			</view>
		</u-popup>

		<u-popup v-model="showPopA" mode="center" border-radius="15">
			<view style="padding: 10px;">
				<view>
					<u-image width="400" height="400" :src="kfurl"></u-image>
				</view>
				<view style="text-align: center;color: #C8C9CC;">
					<div>分享推广</div>
					<div>通过分享新师傅注册得更多权利</div>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {loading,hidden,toast} from '../../tips/myTips.js'
	import {getFileUrl,getKFQRcode} from '../../api/api.js'
	import {Validation,getUrl} from '../../api/apis.js'
	export default {
		onShow(){
			this.init()
			uni.$u.mpShare.title = '页面分享';
		},
		data(){
			return {
				gridList:[
					[
						{
							name:'金融',
							list:[
								{
									label:'我的钱包',
									iconUrl:'/static/images/my/money.png',
									url:'/pages/myWallet/myWallet'
								},
								{
									label:'缴纳保证金',
									iconUrl:'/static/images/my/bond.png',
									url:'/pages/deposit/deposit'
								}
							]
						}
					],
					[
						{
							name:'个人',
							list:[
								{
									label:'个人设置',
									iconUrl:'/static/images/my/user.png',
									url:'/pages/personalSettings/personalSettings'
								},
								{
									label:'居住住址',
									iconUrl:'/static/images/my/location.png',
									url:'/pages/address/address'
								},
								{
									label:'服务区域',
									iconUrl:'/static/images/my/quyu.png',
									url:'/pages/serviceArea/serviceArea'
								},
								{
									label:'服务类目',
									iconUrl:'/static/images/my/category.png',
									url:'/pages/serviceCategory/serviceCategory'
								},
								{
									label:'实名认证',
									iconUrl:'/static/images/my/renzheng.png',
									url:'/pages/realnameAuthentication/realnameAuthentication'
								},
								{
									label:'个人评价',
									iconUrl:'/static/images/my/feedback.png',
									url:'/pages/personalEvaluation/personalEvaluation'
								}
							]
						}
					],
					[
						{
							name:'更多',
							list:[
								{
									label:'更多设置',
									iconUrl:'/static/images/my/set.png',
									url:'/pages/moreSettings/moreSettings'
								},
								{
									label:'帮助中心',
									iconUrl:'/static/images/my/help1.png',
									url:'/pages/help/help'
								},
								{
									label:'意见反馈',
									iconUrl:'/static/images/my/feedback1.png',
									url:'/pages/feedback/feedback'
								},
								{
									label:'联系客服',
									iconUrl:'/static/images/my/customer.png',
									url:'kf'
								},
								{
									label:'京台服务',
									iconUrl:'/static/images/my/feedback.png',
									url:'jt'
								}
							]
						}
					]
				],
				avatarUrl:'',
				showPop:false,
				showPopA:false,
				kfurl:'',
			}
		},
		methods:{
			init(){
				let that = this
				loading()
				wx.login({
					success(res) {
						that.$store.state.login = true
						hidden()
						that.$store.state.code = res.code
						Validation(res.code).then((res) => {
							hidden()
							if(res.data.result.isRegister == false){
								console.log("此处设置token,注册状态(注册失败),没有师傅信息")
								that.$store.state.token = res.data.result.token
								that.$store.state.register = res.data.result.isRegister
							}else{
								console.log("此处设置token,注册状态(注册成功),师傅信息")
								that.$store.state.token = res.data.result.token
								that.$store.state.register = res.data.result.isRegister
								that.$store.state.userInfo = JSON.parse(res.data.result.result)
								console.log("师傅信息:",that.$store.state.userInfo)
								that.$store.state.initComplete = true
								that.$store.state.loading = true
								loading()
								getUrl(that.$store.state.userInfo.FUserImage).then((res) => {
									hidden()
									if(res.data.code == 0){
										that.avatarUrl = res.data.result[0].fileurl
									}else{
										toast(res.data.message)
									}
								})
								
							}
						})
					}
				})
			},
			navigator(url){
				if(!this.$store.state.register){
					uni.showToast({
						title:'请先登录',
						icon:'none'
					})
				}else if(url == 'kf'){
					console.log("弹出客服二维码")
					let that = this
					loading()
					getKFQRcode().then((res) => {
						if(res.data.code == 0){
							hidden()
							that.kfurl = res.data.result[0].fileurl
							that.showPop = true
							console.log("客服二维码:",res.data.result[0].fileurl)
						}else{
							hidden()
						}
						
					})
				}else if(url == 'jt'){
					console.log("弹出京台小程序二维码")
					this.kfurl = '/static/images/jt.jpg'
					this.showPopA = true
				}else{
					uni.navigateTo({
						url:url
					})
				}
			},
		},
		computed:{
			checkStatus:function(){
				switch(this.info.FCheckStatus){
					case '0':
						return '未认证'
					case '1':
						return '认证中'
					case '2':
						return '已认证'
				}
			},
			info:function(){
				return this.$store.state.userInfo
			}
		}
	}
</script>

<style>
	.header{
		padding: 5% 2%;
		background-color: #7c59fc;
	}
</style>
