<template>
	<view class='my-page'>
		<view class='my-top'>
			<view class='my-header'>
				<image class='header-img' src='https://ddh.yyhock.com/ddhMall/my-icon.png'></image>
					<view class='header-des'>
						<view class='des-name' v-if="userTel!=''">{{userTel}}</view>
						<view class='des-name' v-else @click='goLogin'>注册/登录</view>
						<view class='des-text'>多典花承诺保护您的信息安全</view>
					</view>
			</view>
			<view class="my-contain">
				<i class='con-top'></i>
				<view class='con-box' v-show='menuList && menuList.length>0'>
					<view class="box-line" v-for="item in menuList" @click='goItem(item)' :key="item.id">
						<view class='line-item'>
							<view class='item-l'>
								<image class='l-img' :src='item.iconUrl'></image>
								<view class='l-text'>{{item.title}}</view>
							</view>
							<view class='item-r'></view>
						</view>		
					</view>
					
				</view>
				
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userTel:'',
				menuList:[],
				mobileNum:''
			}
		},
		onLoad(){
			const token=uni.getStorageSync('token')
			console.log(token,'token')
			if(token==''){
				this.userTel=''
				this.Go('uni:/pages/login/login')
				return false
			}else{
				this.init()
				this.initTel()
			}
		},
		
		methods: {
			init(){
				const self=this
				self.$request('/pawn/client/userIndex','POST').then((res)=>{
						const { userInfo,menuList }=res.result
						self.userTel=userInfo.cell
						self.menuList=JSON.parse(menuList)
				})
			},
			goLogin(){
				this.Go('uni:/pages/login/login')
			},
			initTel(){
				const self=this
				self.$request('/pawn/setting','GET').then(res => {
				
					const { protocol,phone }=res.result
					
					self.mobileNum=phone
				}).catch(err=>{
				  console.log(err,'请求出错')
				})
			},
			goItem(item){
				
				if(item.linkUrl!=''){
					console.log('66',item)
					this.Go(item.linkUrl)
				}else{
					console.log('67',this.mobileNum,item)
					uni.makePhoneCall({
						phoneNumber: this.mobileNum
					});
				}
			
				
			}
		},
		onShow(){
			const token=uni.getStorageSync('token')
			console.log(token,'token')
			if(token==''){
				this.userTel=''
				this.Go('uni:/pages/login/login')
				return false
			}else{
				this.init()
				this.initTel()
			}
			
		}
	}
</script>
<style src='./index.less' lang="less" scoped></style>