<template>
	<view class="">
		<u-navbar :title="$t('upload.title')" :border-bottom="false" :background="bgc" title-color='#333' back-icon-color="#333"
			title-size='36' height='38'></u-navbar>
        <view class="zhengce">
        	<view class="" @click="btnxq(1)">
        		{{ $t('settings.privacyPolicy') }}  <image src="https://api.ccttiot.com/smartmeter/img/static/uKpBiM6T9kj4BddzJtDc" mode=""></image>
        	</view>
        	<view class="" @click="btnxq(2)">
        		{{ $t('settings.userAgreement') }}  <image src="https://api.ccttiot.com/smartmeter/img/static/uKpBiM6T9kj4BddzJtDc" mode=""></image>
        	</view>
        	<view class="" @click="btnxq(3)">
        		{{ $t('settings.aboutUs') }}  <image src="https://api.ccttiot.com/smartmeter/img/static/uKpBiM6T9kj4BddzJtDc" mode=""></image>
        	</view>
			<view class="" v-if="logoflag == true" style="border: 0;" @click="btnxq(5)">
				{{ $t('settings.loginNow') }}  <image src="https://api.ccttiot.com/smartmeter/img/static/uKpBiM6T9kj4BddzJtDc" mode=""></image>
			</view>
        	<view class="" v-if="logoflag == false" style="border: 0;" @click="btnxq(4)">
        		{{ $t('settings.logout') }}  <image src="https://api.ccttiot.com/smartmeter/img/static/uKpBiM6T9kj4BddzJtDc" mode=""></image>
        	</view>
        </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                bgc: {
                	backgroundColor: "#fff",
                },
				logoflag:true
			}
		},
		onShow() {
			this.getinfo()
		},
		methods: {
			// 获取用户信息
			getinfo() {
				this.$u.get(`/system/user/profile`).then((res) => {
					if (res.code == 200) {
						uni.setStorageSync('user',res.data)
						uni.setStorageSync('userId',res.data.userId)
						this.logoflag = false
					}else if(res.code == 401){
						this.logoflag = true
					}
				})
			},
            // 跳转到详情
             btnxq(num){
            	if(num == 1){
            		uni.navigateTo({
            			url:'/page_user/yinsixq?tit=' + encodeURIComponent(this.$t('settings.privacyPolicy'))  + '&id=' + 2
            		})
            	}else if(num == 2){
            		uni.navigateTo({
            			url:'/page_user/yinsixq?tit=' + encodeURIComponent(this.$t('settings.userAgreement'))  + '&id=' + 1
            		})
            	}else if(num == 3){
            		uni.navigateTo({
            			url:'/page_user/yinsixq?tit=' + encodeURIComponent(this.$t('settings.aboutUs')) + '&id=' + 3
            		})
            	}else if(num == 4){
            		uni.showModal({  
            		    title: this.$t('common.tip'),  
            		    content: this.$t('settings.logoutConfirm'),  
            		    success: (res) => {  
            		        if (res.confirm) { 
            				   try {
            				       uni.clearStorageSync()
            				       console.log('所有本地存储数据已清空')
            				   } catch (error) {
            				       console.error('清空本地存储失败', error)
            				   }
            		           uni.reLaunch({
            		           	url:'/pages/login/login'
            		           })
            		        } else if (res.cancel) {  
            		           
            		        }  
            		    }  
            		})
            	}else if(num == 5){
					uni.reLaunch({
						url:'/pages/login/login'
					})
				}
             }
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
    }
	.zhengce{
		width: 670rpx;
		height: 420rpx;
		margin: auto;
		background: #FFFFFF;
		box-shadow: 0rpx 10rpx 64rpx 0rpx rgba(0,0,0,0.08);
		margin-top: 28rpx;
		border-radius: 20rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		box-sizing: border-box;
		view{
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 1px solid #D8D8D8;
			padding-bottom: 28rpx;
			box-sizing: border-box;
			padding-top: 28rpx;
			font-size: 36rpx;
			color: #3D3D3D;
			image{
				width: 18rpx;
				height: 32rpx;
			}
		}
	}
</style>