<template>
  <div class="profile-view">
    <div class="profile-header">
      <h1>个人中心</h1>
      <p class="subtitle">管理您的个人信息和账户设置</p>
    </div>

    <div class="profile-content">
      <el-tabs v-model="activeTab">
        <el-tab-pane label="基本信息" name="basic">
          <el-card>
            <div class="profile-section">
              <div class="avatar-section">
                <el-avatar :size="100" src="/avatar.svg">李志鹏</el-avatar>
                <el-button type="primary" size="small" style="margin-top: 16px;">
                  <el-icon><Upload /></el-icon>
                  更换头像
                </el-button>
              </div>

              <el-form :model="profileForm" label-width="100px" style="max-width: 600px;">
                <el-form-item label="姓名">
                  <el-input v-model="profileForm.name" />
                </el-form-item>
                <el-form-item label="工号">
                  <el-input v-model="profileForm.employeeId" disabled />
                </el-form-item>
                <el-form-item label="部门">
                  <el-input v-model="profileForm.department" />
                </el-form-item>
                <el-form-item label="职位">
                  <el-input v-model="profileForm.position" />
                </el-form-item>
                <el-form-item label="手机号">
                  <el-input v-model="profileForm.phone" />
                </el-form-item>
                <el-form-item label="邮箱">
                  <el-input v-model="profileForm.email" />
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="saveProfile">保存修改</el-button>
                  <el-button @click="resetProfile">重置</el-button>
                </el-form-item>
              </el-form>
            </div>
          </el-card>
        </el-tab-pane>

        <el-tab-pane label="账户安全" name="security">
          <el-card>
            <div class="security-section">
              <div class="security-item">
                <div class="security-info">
                  <h3>登录密码</h3>
                  <p>定期更换密码可以提高账户安全性</p>
                </div>
                <el-button type="primary" link @click="showPasswordDialog = true">修改密码</el-button>
              </div>
              
              <el-divider />
              
              <div class="security-item">
                <div class="security-info">
                  <h3>双因素认证</h3>
                  <p>开启后登录需要验证码，更加安全</p>
                </div>
                <el-switch v-model="twoFactorEnabled" />
              </div>
              
              <el-divider />
              
              <div class="security-item">
                <div class="security-info">
                  <h3>登录设备管理</h3>
                  <p>查看和管理您的登录设备</p>
                </div>
                <el-button type="primary" link>查看设备</el-button>
              </div>
            </div>
          </el-card>
        </el-tab-pane>

        <el-tab-pane label="通知设置" name="notification">
          <el-card>
            <div class="notification-section">
              <el-form label-width="150px">
                <el-form-item label="邮件通知">
                  <el-switch v-model="notificationSettings.email" />
                  <span class="setting-desc">接收系统邮件通知</span>
                </el-form-item>
                <el-form-item label="短信通知">
                  <el-switch v-model="notificationSettings.sms" />
                  <span class="setting-desc">接收重要事项短信提醒</span>
                </el-form-item>
                <el-form-item label="工单提醒">
                  <el-switch v-model="notificationSettings.ticket" />
                  <span class="setting-desc">新工单分配时提醒</span>
                </el-form-item>
                <el-form-item label="系统公告">
                  <el-switch v-model="notificationSettings.announcement" />
                  <span class="setting-desc">接收系统公告推送</span>
                </el-form-item>
              </el-form>
            </div>
          </el-card>
        </el-tab-pane>

        <el-tab-pane label="操作日志" name="logs">
          <el-card>
            <el-table :data="operationLogs" style="width: 100%">
              <el-table-column prop="time" label="时间" width="180" />
              <el-table-column prop="action" label="操作" width="200" />
              <el-table-column prop="ip" label="IP地址" width="150" />
              <el-table-column prop="device" label="设备" />
            </el-table>
          </el-card>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- 修改密码对话框 -->
    <el-dialog v-model="showPasswordDialog" title="修改密码" width="400px">
      <el-form :model="passwordForm" label-width="100px">
        <el-form-item label="原密码">
          <el-input v-model="passwordForm.oldPassword" type="password" show-password />
        </el-form-item>
        <el-form-item label="新密码">
          <el-input v-model="passwordForm.newPassword" type="password" show-password />
        </el-form-item>
        <el-form-item label="确认密码">
          <el-input v-model="passwordForm.confirmPassword" type="password" show-password />
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="showPasswordDialog = false">取消</el-button>
        <el-button type="primary" @click="changePassword">确认修改</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { Upload } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const activeTab = ref('basic')

const profileForm = ref({
  name: '李志鹏',
  employeeId: 'TH20230001',
  department: '技术研发部',
  position: '高级工程师',
  phone: '13800138000',
  email: 'lizhipeng@taihao.com'
})

const twoFactorEnabled = ref(false)

const notificationSettings = ref({
  email: true,
  sms: true,
  ticket: true,
  announcement: false
})

const operationLogs = ref([
  { time: '2024-12-06 18:30:00', action: '登录系统', ip: '192.168.1.100', device: 'Windows 11 / Chrome' },
  { time: '2024-12-06 14:20:00', action: '修改个人信息', ip: '192.168.1.100', device: 'Windows 11 / Chrome' },
  { time: '2024-12-05 09:15:00', action: '登录系统', ip: '192.168.1.100', device: 'Windows 11 / Chrome' },
  { time: '2024-12-04 16:45:00', action: '创建工单', ip: '192.168.1.100', device: 'Windows 11 / Chrome' }
])

const showPasswordDialog = ref(false)
const passwordForm = ref({
  oldPassword: '',
  newPassword: '',
  confirmPassword: ''
})

const saveProfile = () => {
  ElMessage.success('个人信息保存成功！')
}

const resetProfile = () => {
  ElMessage.info('已重置为原始信息')
}

const changePassword = () => {
  if (passwordForm.value.newPassword !== passwordForm.value.confirmPassword) {
    ElMessage.error('两次输入的密码不一致！')
    return
  }
  ElMessage.success('密码修改成功！')
  showPasswordDialog.value = false
  passwordForm.value = {
    oldPassword: '',
    newPassword: '',
    confirmPassword: ''
  }
}
</script>

<style lang="scss" scoped>
.profile-view {
  height: 100vh;
  background: #f5f7fa;
  overflow-y: auto;
}

.profile-header {
  padding: 32px 40px;
  background: #fff;
  border-bottom: 1px solid #e4e7ed;
  
  h1 {
    font-size: 28px;
    margin: 0 0 8px 0;
    color: #303133;
  }
  
  .subtitle {
    font-size: 14px;
    color: #909399;
    margin: 0;
  }
}

.profile-content {
  padding: 24px 40px;
  max-width: 1200px;
}

.profile-section {
  .avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 32px;
    padding: 24px;
    background: #f5f7fa;
    border-radius: 8px;
  }
}

.security-section {
  .security-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    
    .security-info {
      h3 {
        font-size: 16px;
        margin: 0 0 8px 0;
        color: #303133;
      }
      
      p {
        font-size: 14px;
        color: #909399;
        margin: 0;
      }
    }
  }
}

.notification-section {
  .setting-desc {
    margin-left: 12px;
    font-size: 13px;
    color: #909399;
  }
}
</style>
