<template>
  <view class="container">
    <!-- 顶部标题栏 -->
    <view class="header">
      <text class="title">设置</text>
    </view>
    
    <!-- 顶部用户信息 -->
    <view class="user-info" @click="navigateTo('/pages/user/profile')">
      <view class="avatar">
        <image :src="userInfo.avatar || '/static/default-avatar.png'" mode="aspectFill"></image>
      </view>
      <view class="info">
        <text class="name">{{userInfo.nickname || '未登录'}}</text>
        <text class="phone">{{userInfo.phone ? hidePhone(userInfo.phone) : '点击登录'}}</text>
      </view>
      <view class="arrow">
        <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
      </view>
    </view>
    
    <!-- 功能列表 -->
    <view class="menu-list">
      <!-- 银行卡 -->
      <view class="menu-item" @click="navigateTo('/pages/user/bankCard')">
        <view class="item-left">
          <uni-icons type="wallet" size="20" color="#4a7dff"></uni-icons>
          <text class="text">我的银行卡</text>
        </view>
        <view class="item-right">
          <text class="tips" v-if="userInfo.bankCardCount > 0">{{userInfo.bankCardCount}}张</text>
          <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
        </view>
      </view>
      
      <!-- 实名认证 -->
      <view class="menu-item" @click="navigateTo('/pages/user/realAuth')">
        <view class="item-left">
          <uni-icons type="person" size="20" color="#4a7dff"></uni-icons>
          <text class="text">实名认证</text>
        </view>
        <view class="item-right">
          <text class="tips" :style="{color: userInfo.authStatus === 1 ? '#4a7dff' : '#ff5a5f'}">
            {{authStatusText[userInfo.authStatus] || '未认证'}}
          </text>
          <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
        </view>
      </view>
      
      <!-- 语言选择 -->
      <view class="menu-item" @click="navigateTo('/pages/user/language')">
        <view class="item-left">
          <uni-icons type="compose" size="20" color="#4a7dff"></uni-icons>
          <text class="text">语言设置</text>
        </view>
        <view class="item-right">
          <text class="tips">{{languageText[userInfo.language] || '简体中文'}}</text>
          <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
        </view>
      </view>
      
      <!-- 设置 -->
      <view class="menu-item" @click="navigateTo('/pages/user/settings')">
        <view class="item-left">
          <uni-icons type="gear" size="20" color="#4a7dff"></uni-icons>
          <text class="text">系统设置</text>
        </view>
        <view class="item-right">
          <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
        </view>
      </view>
    </view>
    
    <!-- 退出登录按钮 -->
    <view class="logout-btn" @click="handleLogout" v-if="userInfo.isLogin">
      <text>退出登录</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      userInfo: {
        avatar: '/static/avatar.jpg',
        nickname: '张三',
        phone: '13800138000',
        bankCardCount: 2,
        authStatus: 1, // 0-未认证 1-已认证 2-认证中 3-认证失败
        language: 'zh-CN',
        isLogin: true
      },
      authStatusText: {
        0: '未认证',
        1: '已认证',
        2: '认证中',
        3: '认证失败'
      },
      languageText: {
        'zh-CN': '简体中文',
        'en-US': 'English',
        'zh-TW': '繁體中文'
      }
    }
  },
  methods: {
    // 隐藏手机号中间四位
    hidePhone(phone) {
      return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
    },
    
    // 路由跳转
    navigateTo(url) {
      uni.navigateTo({
        url: url
      })
    },
    
    // 退出登录
    handleLogout() {
      uni.showModal({
        title: '提示',
        content: '确定要退出登录吗？',
        success: (res) => {
          if (res.confirm) {
            // 这里调用退出登录接口
            uni.showLoading({
              title: '正在退出...'
            })
            
            // 模拟退出登录
            setTimeout(() => {
              uni.hideLoading()
              this.userInfo.isLogin = false
              this.userInfo.nickname = ''
              this.userInfo.phone = ''
              uni.showToast({
                title: '退出成功',
                icon: 'success'
              })
              
              // 跳转到登录页或其他页面
              uni.reLaunch({
                url: '/pages/login/login'
              })
            }, 1000)
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding: 20rpx 30rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
  box-sizing: border-box;
}

.header {
  padding: 30rpx 0;
  text-align: center;
  
  .title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
  }
}

.user-info {
  display: flex;
  align-items: center;
  padding: 40rpx 30rpx;
  background-color: #fff;
  border-radius: 16rpx;
  margin-bottom: 20rpx;
  
  .avatar {
    width: 120rpx;
    height: 120rpx;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 30rpx;
    
    image {
      width: 100%;
      height: 100%;
    }
  }
  
  .info {
    flex: 1;
    display: flex;
    flex-direction: column;
    
    .name {
      font-size: 36rpx;
      font-weight: bold;
      color: #333;
      margin-bottom: 10rpx;
    }
    
    .phone {
      font-size: 28rpx;
      color: #999;
    }
  }
  
  .arrow {
    margin-left: 20rpx;
  }
}

.menu-list {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 0 30rpx;
  margin-bottom: 20rpx;
  
  .menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100rpx;
    border-bottom: 1rpx solid #f5f5f5;
    
    &:last-child {
      border-bottom: none;
    }
    
    .item-left {
      display: flex;
      align-items: center;
      
      .text {
        font-size: 30rpx;
        color: #333;
        margin-left: 20rpx;
      }
    }
    
    .item-right {
      display: flex;
      align-items: center;
      
      .tips {
        font-size: 26rpx;
        color: #999;
        margin-right: 10rpx;
      }
    }
  }
}

.logout-btn {
  height: 90rpx;
  line-height: 90rpx;
  text-align: center;
  background-color: #fff;
  border-radius: 16rpx;
  color: #ff5a5f;
  font-size: 32rpx;
  margin-top: 40rpx;
}
</style>