<template>
  <view class="mine">
    <view class="top">
		<view class="topBox">
			<image src="/static/img/pic_def_ava@2x.png" mode="" class="touxiang"></image>
			 <view class="name">{{ currentUser.supplierName }}</view>
		</view>
     <!-- <image :src="currentUser.avatar"></image> -->
	 
    </view>
	<view class="cont" style="margin-top: -50rpx;"> 
		<view class="contBox">
			<!-- <view class="line" >
				<view class="lineName">
					<image src="/static/img/my_icon_history@2x.png" mode="" class="lineIcon"></image>
					语音播报提醒
				</view>
				<image src="/static/img/icon_arrow.png" mode="" class="jtImg"></image>
			</view> -->
			<view class="line" @click="goUp">
				<view class="lineName">
					<image src="/static/img/my_icon_psw@2x.png" mode="" class="lineIcon"></image>
					修改密码
				</view>
				<image src="/static/img/icon_arrow.png" mode="" class="jtImg"></image>
			</view>
			<view class="line" @click="goBrand">
				<view class="lineName">
					<image src="/static/img/my_icon_jiuc@2x.png" mode="" class="lineIcon"></image>
					经营品牌</view>
				<image src="/static/img/icon_arrow.png" mode="" class="jtImg"></image>
			</view>
		</view>
		
		<!-- <view class="contBox" style="margin-top: 20rpx;">
			<view class="line">
				<view class="lineName">当前版本</view>
				<view class="version">version1.0.0</view>
			</view>
			<view class="line" @click="claerHc">
				<view class="lineName">清除缓存</view>
				<image src="/static/img/icon_arrow.png" mode="" class="jtImg"></image>
			</view>
		</view> -->
		
		
	</view>
    <view class="bottom">
      
      <view class="logout" @click="logout">退出</view>
    </view>
  </view>
</template>

<script>
  const GoEasy = uni.$GoEasy;
  export default {
    data() {
      return {
        currentUser: null,
		token:'',
      }
    },
    onShow() {
      this.currentUser = uni.getStorageSync("loginInfo")
	  var token= uni.getStorageSync("accessToken")
	  this.token=token
	  if(token){
	  	 this.imLoginUrl()
	  }else{
		  uni.navigateTo({
		    url: './login'
		  })
	  }
    },
    methods: {
		imLoginUrl(){
			this.$http2('imSys/imLoginUrl', {
			   token:this.token,
			   type:1
			  },'POST').then(res => {
			 	  console.log(res)	
				  if(res.code!=0){
					 // uni.clearStorageSync();
					this.logout()
				  }
			  }) 
		},
		claerHc(){
			uni.showToast({
			  icon: 'none',
			  title: '清除成功',
			  duration: 3000
			});
		},
		goUp(){
			uni.navigateTo({
				url:'editPass'
			})
		},
		goBrand(){
			uni.navigateTo({
				url:'brand'
			})
		},
	saveWebState(){
		var standalone = window.navigator.standalone
		var userAgent = window.navigator.userAgent.toLowerCase()
		var safari = /safari/.test(userAgent)
		var ios = /iphone|ipod|ipad|mac/.test(userAgent)
		var android = /android/.test(userAgent)
		if (ios) {
					 if ( true) {//!standalone&& !safari
					   window.webkit.messageHandlers.saveWebState.postMessage(2)
					 }
		} else if (android) {
			  window.android.saveWebState(2)
		}
	},
      logout() {
		 // uni.clearStorageSync();
		  GoEasy.disconnect({
			 onSuccess: function(){
				 console.log("GoEasy disconnect successfully.")
				 uni.removeStorageSync('accessToken');
				 uni.removeStorageSync('loginInfo')
				  uni.navigateTo({
				    url: './login'
				  })
			 },
			 onFailed: function(error){
				 uni.removeStorageSync('accessToken');
				 uni.removeStorageSync('loginInfo')
				  uni.navigateTo({
				    url: './login'
				  })
				 console.log("Failed to disconnect GoEasy, code:"+error.code+ ",error:"+error.content);
			 }
		 });
		  this.saveWebState()
       /* if(GoEasy.getConnectionStatus() === 'disconnected') {
          return
        }
        uni.showLoading({
          title: '注销中',
          mask: true,
        });
        GoEasy.disconnect({
          onSuccess: function () {
            uni.hideLoading();
            console.log('注销成功')
            uni.$currentUser = null;
            
          },
          onFailed: function (error) {
            uni.hideLoading();
            uni.showToast({
              icon: 'none',
              title: '注销超时，请检查网络！（务必确保注销成功才允许客户退出应用，否则有可能会收到上个用户的消息。）',
              duration: 6000
            });
            console.log('注销失败', error);
          }
        }); */
      }
    }
  }
</script>

<style scoped>
.topBox{
	display: flex;
	color: #FFFFFF;
	font-weight: 500;
	font-size: 34rpx;
	color: #FFFFFF;
	padding-left: 25rpx;
	padding-top: 70rpx;
}
.cont{
	padding: 0 24rpx;
}
.lineIcon{
	width: 40rpx;height: 40rpx;margin-right: 10rpx;
}
.lineName{
	display: flex;line-height: 42rpx;
}
.contBox{
	background: #FFFFFF;
	border-radius: 10rpx;
}
  .mine {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
	background: #F7F7F7;
  }

  .top {
    height: 240rpx;
    background: #46B1F8;
  /*  display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center; */
  }

  .top .touxiang {
    width: 82rpx;
    height: 82rpx;
  /*  border-radius: 156rpx; */
  }

  .top .name {
    line-height: 82rpx;
	padding-left: 16rpx;
  }

  .bottom {
    text-align: center;
    line-height: 200rpx;
	margin-top: 100rpx;
  }

  .logout {
    width: 702rpx;
    height: 88rpx;
    background: #FFFFFF;
    border-radius: 10rpx;
    margin: 0 auto;
	text-align: center;
	line-height: 88rpx;
	font-size: 28rpx;
	color: #F03B3B;
  }
  .line{
  	display: flex;justify-content: space-between;
  	padding: 30rpx 20rpx;
  	border-bottom: 1px solid #eee;
  	color: #333333;
  }
  .jtImg{
  	width: 20rpx;height: 20rpx;margin-top: 6rpx;
  }
</style>
