<script>
import {logout, getInfo} from '@/api/index.js'
export default {
  data() {
    return {
      userInfo: {},
    }
  },
  mounted() {
    this.getData();
  },
  methods:{
    // 用户数据
    getData() {
      this.userInfo = {};
      getInfo().then(res => {
        if (res.data.code == 200) {
          this.userInfo = res.data.data;
          uni.setStorageSync('wx_phone', res.data.data.cPhone);
        }
      })
    },
    goSetting(){
      uni.navigateTo({
        url: '/setting/myNew/security'
      })
    },
    // 退出登录
    onLogout() {
      uni.showModal({
        title: '确定退出登录吗',
        success: (res) => {
          if (res.confirm) {
            logout().then(res => {
              if (res.data.code == 200) {
                uni.removeStorageSync('access-token')
                uni.switchTab({
                  url: '/pages/my/my'
                })
                uni.showToast({
                  title: '已退出登录',
                  icon: 'none'
                })
              }
            })
          }
        }
      })
    },
  }
}
</script>

<template>
  <view class="sett-box">
    <view class="userInfo">
      <u-avatar :src="userInfo.cIcon" size="80rpx"/>
      <text>{{ userInfo.cNickName }}</text>
    </view>
    <u-cell :titleStyle="{fontWeight: 500}" title="账号安全" isLink class="security" @click="goSetting()"></u-cell>
    <view class="logOut" @click="onLogout()">退出登录</view>
  </view>
</template>

<style scoped lang="scss">
.sett-box{
  width: 750rpx;
  height: 100vh;
  background: #F5F8F8;
  padding:36rpx 40rpx;
  position: relative;
  .userInfo{
    width: 678rpx;
    height: 128rpx;
    background: #FFFFFF;
    border-radius: 24rpx;
    padding: 24rpx;
    line-height: 80rpx;
    display: flex;
    margin-bottom:24rpx;
    text{
      margin-left: 20rpx;
      display: inline-block;
    }
  }
  .security{
    width: 678rpx;
    height: 88rpx;
    background: #FFFFFF;
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    ::v-deep .u-cell__body{
      padding: 25rpx 30rpx;
    }
    ::v-deep .u-line{
      display: none;
    }
  }
  .logOut{
    width: 670rpx;
    height: 84rpx;
    background: #FFFFFF;
    border-radius: 60rpx 60rpx 60rpx 60rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: 500;
    font-size: 28rpx;
    color: #333333;
    line-height: 84rpx;
    text-align: center;
    position: absolute;
    bottom: 110rpx;
  }
}
</style>
