<template>
  <view class="container">
    <view class="detail-card">
      <view class="card-header">
        <view class="header-icon">
          <uni-icons type="person" size="24" color="#ffffff"></uni-icons>
        </view>
        <view class="header-info">
          <text class="card-name">{{ info.user.nickName }}<text class="card-code" v-if="info.user.userName">({{ info.user.userName }})</text></text>
        </view>
      </view>
      
      <view class="card-body">
        <view class="info-section">
          <view class="section-title">
            <view class="title-icon"></view>
            <text>基本信息</text>
          </view>
          <view class="info-list">
            <view class="list-item">
              <text class="item-label">用户昵称</text>
              <text class="item-value">{{ info.user.nickName || '-' }}</text>
            </view>
            <view class="list-item">
              <text class="item-label">用户名称</text>
              <text class="item-value">{{ info.user.userName || '-' }}</text>
            </view>
            <view class="list-item">
              <text class="item-label">手机号码</text>
              <text class="item-value">{{ info.user.phonenumber || '-' }}</text>
            </view>
            <view class="list-item">
              <text class="item-label">邮箱</text>
              <text class="item-value">{{ info.user.email || '-' }}</text>
            </view>
            <view class="list-item">
              <text class="item-label">用户性别</text>
              <text class="item-value">{{ sexStr || '-' }}</text>
            </view>
            <view class="list-item">
              <text class="item-label">部门</text>
              <text class="item-value">{{ info.user.deptId && info.user.deptName || '-' }}</text>
            </view>
            <view class="list-item">
              <text class="item-label">状态</text>
              <text class="item-value" :class="getStatusClass(info.user.status)">{{ statusStr }}</text>
            </view>
            <view class="list-item" v-if="info.user.createTime">
              <text class="item-label">创建时间</text>
              <text class="item-value">{{ info.user.createTime }}</text>
            </view>
          </view>
        </view>
        
        <view class="info-section" v-if="info.user.remark">
          <view class="section-title">
            <view class="title-icon"></view>
            <text>备注</text>
          </view>
          <view class="remark-content">
            <text>{{ info.user.remark }}</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, computed } from 'vue'
import { getUser } from '@/api/system/user'
import { getDicts } from "@/api/system/dict/data"
import { onLoad } from "@dcloudio/uni-app"

const info = ref({})
const statusList = ref([])
const sexList = ref([])

const statusStr = computed(() => {
  const item = statusList.value.find(v => v.dictValue === info.value.user.status)
  return item ? item.dictLabel : ''
})

const sexStr = computed(() => {
  const item = sexList.value.find(v => v.dictValue === info.value.user.sex)
  return item ? item.dictLabel : ''
})

function getStatusClass(status) {
  const statusStr = String(status)
  if (statusStr === '0') {
    return 'status-normal'
  }
  if (statusStr === '1') {
    return 'status-disabled'
  }
  return 'status-default'
}

onLoad((option) => {
  getDicts('sys_normal_disable').then(res => {
    statusList.value = res.data
  })
  
  getDicts('sys_user_sex').then(res => {
    sexList.value = res.data
  })

  if (option.id) {
    getDetail(option.id)
  }
})

function getDetail(id) {
  getUser(id).then(res => {
    info.value = res.data
  })
}
</script>

<style lang="scss" scoped>
.container {
  background: #f5f7fa;
  padding-bottom: 24rpx;
}

.detail-card {
  margin: 24rpx;
  background: #ffffff;
  border-radius: 16rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16rpx 20rpx;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  
  .header-icon {
    width: 48rpx;
    height: 48rpx;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 16rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12rpx;
    backdrop-filter: blur(10rpx);
  }
  
  .header-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    
    .card-name {
      color: #ffffff;
      font-size: 28rpx;
      font-weight: 600;
      line-height: 1.2;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      
      .card-code {
        color: rgba(255, 255, 255, 0.85);
        font-size: 28rpx;
        font-weight: 400;
        margin-left: 8rpx;
      }
    }
  }
}

.card-body {
  padding: 24rpx;
}

.info-section {
  margin-bottom: 32rpx;
  
  &:last-child {
    margin-bottom: 0;
  }
  
  .section-title {
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
    
    .title-icon {
      width: 6rpx;
      height: 28rpx;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      border-radius: 3rpx;
      margin-right: 12rpx;
    }
    
    text {
      color: #2c3e50;
      font-size: 28rpx;
      font-weight: 600;
    }
  }
  
  .info-list {
    .list-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 20rpx;
      background: #f8f9fa;
      border-radius: 8rpx;
      margin-bottom: 12rpx;
      
      &:last-child {
        margin-bottom: 0;
      }
      
      .item-label {
        color: #7f8c8d;
        font-size: 26rpx;
      }
      
      .item-value {
        color: #2c3e50;
        font-size: 28rpx;
        font-weight: 500;
        text-align: right;
        
        &.status-normal {
          color: #52c41a;
        }
        
        &.status-disabled {
          color: #ff4d4f;
        }
        
        &.status-default {
          color: #666666;
        }
      }
    }
  }
  
  .remark-content {
    padding: 20rpx;
    background: #f8f9fa;
    border-radius: 8rpx;
    
    text {
      color: #2c3e50;
      font-size: 26rpx;
      line-height: 1.6;
    }
  }
}
</style>
