<template>
   <div class="app-container">
      <div class="user-container">
        <!-- 搜索区域 -->
        <div class="search-area">
          <el-input
            v-model="queryParams.userName"
            placeholder="请输入用户名查询"
            clearable
            prefix-icon="Search"
            class="search-input"
          />
          
          <el-select v-model="queryParams.roleId" placeholder="角色" clearable class="search-select">
            <el-option label="全部" value="" />
            <el-option
              v-for="role in roleOptions"
              :key="role.roleId"
              :label="role.roleName"
              :value="role.roleId"
            />
          </el-select>
          
          <div class="search-buttons">
            <el-button type="primary" class="search-btn" @click="handleQuery">搜索</el-button>
            <el-button class="reset-btn" @click="resetQuery">重置</el-button>
          </div>
          
          <div class="action-buttons">
            <el-button type="primary" class="search-btn" @click="handleAdd">新增</el-button>
            <el-button class="reset-btn" plain @click="handleImport">导入</el-button>
            <el-button class="reset-btn" plain @click="handleExport">导出</el-button>
            <el-button class="export-btn" :disabled="multiple"  type="info" @click="handleDelete">删除</el-button>
            
          </div>
        </div>

        <!-- 用户表格 -->
        <el-table
          v-loading="loading"
          :data="userList"
          @selection-change="handleSelectionChange"
          style="width: 100%"
          class="custom-table"
          :header-cell-style="{ backgroundColor: '#343744', color: '#fff' }"
          :bg-color="'#292C38'"
        >
          <el-table-column type="selection" width="50" align="left" />
          <el-table-column label="序号" width="60" align="left">
            <template #default="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" align="left">
            <template #default="scope">
              <el-button link text @click="handleUpdate(scope.row)">编辑</el-button>
              <el-button link text type="primary" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
          <el-table-column label="人像" prop="avatar" align="left" class="avatar-box">
            <template #default="scope"> 
              <div class="avatar-box">
                <img :src="scope.row.avatar" alt="" />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用户名" prop="userName" align="left" />
          <!-- <el-table-column label="昵称" prop="userName" align="left" /> -->
          <el-table-column label="角色" align="left">
            <template #default="scope">
              <span>{{ scope.row.roles ? scope.row.roles.map(role => role.roleName).join(', ') : '-' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="手机号" prop="phonenumber" align="left" />
          <el-table-column label="账号状态" align="left">
            <template #default="scope">
                {{ scope.row.status === '0' ? '正常' : '停用' }}
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="left" prop="createTime" width="160">
            <template #default="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页组件 -->
        <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </div>

      <!-- 添加或修改用户对话框 -->
      <el-dialog :title="title" v-model="open" width="600px" append-to-body>
        <el-form :model="form" :rules="rules" ref="userRef" label-width="80px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="用户名" prop="userName">
                <el-input 
                  v-model="form.userName" 
                  placeholder="请输入用户昵称" 
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="手机号" prop="phonenumber">
                <el-input 
                  v-model="form.phonenumber" 
                  placeholder="请输入手机号码" 
                />
              </el-form-item>
            </el-col>
          </el-row>
          
          <el-row>
            <el-col :span="24">
              <el-form-item label="人像">
                <div class="avatar-uploader-box">
                  <div v-if="form.avatar" class="avatar-preview">
                    <img :src="form.avatar" class="avatar" />
                    <div class="avatar-count">1/1</div>
                    <div class="avatar-replace" @click.stop="handleRemoveAvatar">
                      <el-icon><Close /></el-icon>
                    </div>
                  </div>
                  <el-upload
                    v-else
                    class="avatar-uploader"
                    :show-file-list="false"
                    :action="upload.avatarUrl"
                    :headers="upload.headers"
                    :before-upload="beforeAvatarUpload"
                    :on-success="handleAvatarSuccess"
                  >
                    <div class="avatar-upload-placeholder">
                      <el-icon class="avatar-uploader-icon"><Plus /></el-icon>
                      <div class="avatar-count">0/1</div>
                    </div>
                  </el-upload>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          
          <el-row>
            <el-col :span="24">
              <el-form-item label="角色">
                <el-checkbox-group v-model="form.roleIds">
                  <el-checkbox 
                    v-for="role in roleOptions" 
                    :key="role.roleId" 
                    :label="role.roleId">
                    {{ role.roleName }}
                  </el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="状态">
                <el-radio-group v-model="form.status">
                  <el-radio
                    v-for="dict in sys_normal_disable"
                    :key="dict.value"
                    :label="dict.value"
                  >{{ dict.label }}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
         
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button class="export-btn" @click="cancel">取 消</el-button>
            <el-button class="search-btn" type="primary" @click="submitForm">确 定</el-button>
          
          </div>
        </template>
      </el-dialog>

      <!-- 用户导入对话框 -->
      <el-dialog :title="upload.title" v-model="upload.open" width="500px" append-to-body class="import-dialog">
        <div class="import-title">选择需要导入的项目文件</div>
        <el-upload
          ref="uploadRef"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url + '?updateSupport=' + upload.updateSupport"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
          class="import-upload"
        >
          <div class="upload-content">
            <el-icon class="upload-icon"><upload-filled /></el-icon>
            <div class="upload-text">拖拽文件到这里，或</div>
            <div class="upload-link">
              <el-icon class="upload-icon-small" style="color: #347AE2"><upload-filled /></el-icon>
              <span class="click-upload">点此添加</span>
            </div>
          </div>
        </el-upload>
        <div class="import-footer">
          <div class="footer-left">
            <el-checkbox v-model="upload.updateSupport">是否更新已经存在的用户数据</el-checkbox>
          </div>
          <div class="footer-right">
            <span class="file-format">仅允许导入xls、xlsx格式文件。</span>
            <el-link type="primary" :underline="false" class="download-link" @click="importTemplate">下载模板</el-link>
          </div>
        </div>
        <template #footer>
          <div class="dialog-footer">
            <el-button class="export-btn" @click="upload.open = false">取 消</el-button>
            <el-button class="search-btn" type="primary" @click="submitFileForm">确 定</el-button>
          </div>
        </template>
      </el-dialog>
   </div>
</template>

<script setup name="User">
import { getToken } from "@/utils/auth";
import { 
  changeUserStatus, 
  listUser, 
  resetUserPwd, 
  delUser, 
  getUser, 
  updateUser, 
  addUser, 
  deptTreeSelect,
  uploadAvatar
} from "@/api/system/user";
import { listRole } from "@/api/system/role";
import { Plus, Delete, UploadFilled, Close } from '@element-plus/icons-vue';

const router = useRouter();
const { proxy } = getCurrentInstance();
const { sys_normal_disable, sys_user_sex } = proxy.useDict("sys_normal_disable", "sys_user_sex");

const userList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);
const postOptions = ref([]);
const roleOptions = ref([]);
const initPassword = ref(""); // 初始密码变量

// 用户导入参数
const upload = reactive({
  open: false,
  title: "",
  isUploading: false,
  updateSupport: 0,
  headers: { Authorization: "Bearer " + getToken() },
  url: import.meta.env.VITE_APP_BASE_API + "/system/user/importData",
  avatarUrl: import.meta.env.VITE_APP_BASE_API + "/system/user/profile/avatar"
});

// 列显隐信息
const columns = ref([
  { key: 0, label: `用户编号`, visible: true },
  { key: 1, label: `用户名称`, visible: true },
  { key: 2, label: `用户昵称`, visible: true },
  { key: 3, label: `部门`, visible: true },
  { key: 4, label: `手机号码`, visible: true },
  { key: 5, label: `状态`, visible: true },
  { key: 6, label: `创建时间`, visible: true }
]);

const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  userName: undefined,
  phonenumber: undefined,
  status: undefined,
  roleId: undefined,
  deptId: undefined
});

const form = ref({});

const rules = ref({
  userName: [
    { required: true, message: "用户名称不能为空", trigger: "blur" },
    { min: 2, max: 20, message: "用户名称长度必须介于 2 和 20 之间", trigger: "blur" }
  ],
  userName: [{ required: true, message: "用户昵称不能为空", trigger: "blur" }],
  password: [
    { required: true, message: "用户密码不能为空", trigger: "blur" },
    { min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur" }
  ],
  email: [{ type: "email", message: "请输入正确的邮箱地址", trigger: ["blur", "change"] }],
  phonenumber: [{ pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur" }]
});

/** 查询用户列表 */
function getList() {
  loading.value = true;
  listUser(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
    loading.value = false;
    userList.value = res.rows;
    total.value = res.total;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  queryParams.value.pageNum = 1;
  handleQuery();
}

/** 选择条数 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.userId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 删除按钮操作 */
function handleDelete(row) {
  const userIds = row.userId || ids.value;
  proxy.$modal.confirm('确定删除此用户吗?', '删除').then(function() {
    return delUser(userIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 批量删除操作 */
function handleBatchDelete() {
  if (ids.value.length === 0) {
    proxy.$modal.msgError("请选择要删除的数据");
    return;
  }
  proxy.$modal.confirm('确定删除选中的用户吗?', '删除').then(function() {
    return delUser(ids.value);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  // getInitPassword().then(response => {
  //   if (response && response.data) {
  //     initPassword.value = response.data.password;
  //   }
    title.value = "添加用户";
    open.value = true;
  // }).catch(() => {
  //   title.value = "添加用户";
  //   open.value = true;
  // });
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const userId = row.userId || ids.value[0];
  getUser(userId).then(response => {
    form.value = response.data;
    form.value.roleIds = response.roleIds || [];
    open.value = true;
    title.value = "修改用户";
    form.password = "";
  });
}

/** 查看详情 */
function viewDetails(row) {
  // 实际应用中跳转到用户详情页
  console.log("查看用户详情", row);
}

/** 重置表单 */
function reset() {
  form.value = {
    userId: undefined,

    userName: undefined,
    userName: undefined,
    password: undefined,
    phonenumber: undefined,
    email: undefined,
    sex: undefined,
    status: "0",
    remark: undefined,
    roleIds: [],
    avatar: undefined
  };
  proxy.resetForm("userRef");
}

/** 提交表单 */
function submitForm() {
  proxy.$refs["userRef"].validate(valid => {
    if (valid) {
      if (form.value.userId != undefined) {
        updateUser(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        form.value.password = form.value.password || initPassword.value;
        addUser(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download("system/user/export", {
    ...queryParams.value,
    pageNum: undefined,
    pageSize: undefined
  }, `用户数据_${new Date().getTime()}.xlsx`);
}

/** 导入按钮操作 */
function handleImport() {
  upload.title = "用户导入";
  upload.open = true;
  upload.isUploading = false;
}

/** 分配角色 */
function handleAuthRole(row) {
  router.push("/system/user-auth/role/" + row.userId);
}

/** 导入对话框关闭时清除数据 */
function handleFileUploadProgress(event, file, fileList) {
  upload.isUploading = true;
}

/** 导入成功处理 */
function handleFileSuccess(response, file, fileList) {
  upload.open = false;
  upload.isUploading = false;
  proxy.$refs["uploadRef"].clearFiles();
  if (response.code === 200) {
    proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
    getList(); // 刷新列表数据
  } else {
    proxy.$modal.msgError(response.msg);
  }
}

/** 下载导入模板 */
function importTemplate() {
  proxy.download("system/user/importTemplate", {}, `user_template_${new Date().getTime()}.xlsx`);
}

/** 提交上传文件 */
function submitFileForm() {
  proxy.$refs["uploadRef"].submit();
}

/** 头像上传前处理 */
function beforeAvatarUpload(file) {
  const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
  const isLt2M = file.size / 1024 / 1024 < 2;

  if (!isJPG) {
    proxy.$modal.msgError('上传头像图片只能是JPG或PNG格式!');
    return false;
  }
  if (!isLt2M) {
    proxy.$modal.msgError('上传头像图片大小不能超过2MB!');
    return false;
  }
  return true;
}

/** 头像上传成功处理 */
function handleAvatarSuccess(res, file) {
  if (res.code === 200) {
    form.value.avatar = res.imgUrl;
    proxy.$modal.msgSuccess("上传成功");
  } else {
    proxy.$modal.msgError(res.msg || "上传失败");
  }
}

/** 移除头像 */
function handleRemoveAvatar() {
  form.value.avatar = undefined;
}

onMounted(() => {
  getList();
  getRoleOptions();
  getPostOptions();
});

// 获取角色下拉列表
function getRoleOptions() {
  listRole().then(res => {
    roleOptions.value = res.rows;
  });
}

// 获取岗位下拉列表
function getPostOptions() {
  // 这里假设你有API获取岗位列表
  postOptions.value = [];
}
</script>

<style lang="scss" scoped>
.app-container {
  padding: 20px;
  background-color: #292C38;
  color: #ffffff;
  min-height: 100%;
  
  border-radius: 10px;
}

.user-container {
  background-color: #292c38;
  border-radius: 4px;
}

.tabs-view {
  display: flex;
  border-bottom: 1px solid #4c4f5f;
  margin-bottom: 20px;

  .tab-item {
    padding: 10px 20px;
    cursor: pointer;
    color: #96a0b5;
    position: relative;
    margin-right: 20px;

    &.active {
      color: #ffffff;
      font-weight: bold;
      
      &::after {
        content: '';
        position: absolute;
        bottom: -1px;
        left: 0;
        width: 100%;
        height: 2px;
        background-color: #409eff;
      }
    }
  }
}

.search-area {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  
  .search-input {
    width: 250px;
    margin-right: 10px;
  }
  
  .search-select {
    width: 150px;
    margin-right: 10px;
  }
  
  .search-buttons {
    margin-right: 20px;
    display: flex;
    gap: 10px;
  }
  
  .action-buttons {
    margin-left: auto;
    display: flex;

  }
}
// 输入框 下拉框 搜索栏
:deep(.el-input__wrapper:hover) {
  box-shadow: none !important;
}

:deep(.el-select) {
  border:none !important;
  width:140px !important;
  // 修改el-select的输入框的border 
  --el-border-color-hover: #343744!important;
  --el-border-color: #343744!important;
}

:deep(.el-select__wrapper.is-focused) {
  box-shadow: none !important;
}

:deep(.el-select__wrapper) {
  background: #343744 !important;
  color: #96A0B5 !important;
  border-radius: 8px !important;
  height: 36px !important;
  width: 140px;
  font-size: 15px;
  border: none !important;
  border:none !important;
}

:deep(.el-input__wrapper) {
  background: #343744 !important;
  color: #96A0B5 !important;
  border-radius: 8px !important;
  height: 36px !important;
  border: none !important;
  box-shadow: none !important;
}

:deep(.el-select__placeholder) {
  color: #96A0B5 !important;
}
.avatar-box{
  width: 50px;
  height: 50px;
  object-fit: cover;
  overflow: hidden;
  border-radius: 8px;
}
.custom-table {
  background-color: #292c38 !important;
  color: #ffffff;
  margin-bottom: 20px;
  border-radius: 4px;
  overflow: hidden;
  
  // 防止表格闪白
  :deep(.el-loading-mask) {
    background-color: rgba(41, 44, 56, 0.7) !important;
  }
  
  :deep(.el-table__empty-block) {
    background-color: #292c38 !important;
  }
  
  :deep(.el-table__empty-text) {
    color: #96A0B5 !important;
  }
  
  // 确保整个表格区域背景色
  :deep(.el-table) {
    background-color: #292c38 !important;
  }
  
  :deep(.el-table__body) {
    background-color: #292c38 !important;
  }
  
  :deep(.el-table__inner-wrapper::before) {
    display: none; /* 隐藏表格顶部的边框线 */
  }
  
  :deep(.el-table__header) {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    overflow: hidden;
  }
  
  :deep(.el-table__header-wrapper) {
    th {
      background-color: #343744 !important;
      color: #96A0B5!important;
      font-weight: normal;
      border-bottom: none; /* 移除th底部边线 */
    }
    
    tr th.el-table__cell:first-child {
      border-top-left-radius: 6px;
      
      .cell {
        border-top-left-radius: 6px;
      }
    }
    
    tr th.el-table__cell:last-child {
      border-top-right-radius: 4px;
      
      .cell {
        border-top-right-radius: 4px;
      }
    }
    
    .el-table__header th.el-table__cell {
      background-color: #343744 !important;
      color: #96A0B5;
    }
    
    tr {
      background-color: #343744 !important;
    }
  }
  
  :deep(.el-table__body-wrapper) {
   
    td {
      height: 68px!important;
      background-color: #292c38;
      color: #ffffff;
      border-bottom: 1px solid #4C4F5F;
    }
  }
  
  :deep(.el-table__body tr:hover > td) {
    background: #2B3B5A!important; 
    
  }
  
  :deep(.el-button--link) {
    border: none;
    background: transparent;
    color: #347AE2;
    padding: 0;
    margin: 0 5px;
  }
  
  :deep(.el-button.is-text) {
    background-color: transparent !important;
    border-color: transparent;
    color: #347AE2;
    
    &:hover, &:focus, &:active {
      background-color: transparent !important;
      color: #347AE2;
    }
  }
  
  :deep(.el-button.el-button--primary.is-text) {
    background-color: transparent !important;
    color: #347AE2;
    
    &:hover {
      background-color: transparent !important;
      color: #347AE2;
    }
  }
  
  :deep(.el-table__body tr:hover .el-button--link.is-text) {
    background-color: transparent !important;
    color: #347AE2;
  }
}

.status-normal {
  color: #67c23a;
}

.status-disabled {
  color: #e6a23c;
}

:deep(.el-input__wrapper) {
  background-color: #292c38;
  box-shadow: 0 0 0 1px #565C70 inset !important;
  
  .el-input__inner {
    color: #ffffff;
  }
}

:deep(.el-input__count) {
  background: transparent !important;
  color: #C0C4CC !important;
  
  .el-input__count-inner {
    background: transparent !important;
    color: #C0C4CC !important;
  }
}

:deep(.el-radio__label) {
  color: #C8C9CC;
}

:deep(.el-radio.is-checked .el-radio__label) {
  color: #409EFF;
}

:deep(.el-button) {
  background-color: #292c38;
  border-color: #4c4f5f;
  color: #ffffff;
  
  &.el-button--primary {
    background-color: #409eff;
    border-color: #409eff;
  }
}

:deep(.el-select) {
  .el-input__wrapper {
    background-color: #292c38;
    box-shadow: 0 0 0 1px #565C70 inset !important;
  }
}

// 弹窗样式优化
:deep(.el-dialog) {
  .el-form-item__label {
    color: #96A0B5 !important;
  }
  .el-radio__label {
    color: #C8C9CC !important;
  }
  
  .el-radio.is-checked .el-radio__label {
    color: #409EFF !important;
  }
}

// 保留搜索区域的样式
.search-area {
  :deep(.el-input__wrapper) {
    background: #343744 !important;
    color: #96A0B5 !important;
    border-radius: 8px !important;
    height: 36px !important;
    border: none !important;
    box-shadow: none !important;
  }
}

// 全局表格样式覆盖，防止闪白
:deep(.el-table) {
  --el-table-bg-color: #292c38 !important;
  --el-table-tr-bg-color: #292c38 !important;
  --el-table-border-color: #4C4F5F !important;
  --el-table-header-bg-color: #343744 !important;
  --el-table-row-hover-bg-color: #2B3B5A !important;
  
  &::before {
    display: none;
  }
}

// 导入弹窗样式
.import-dialog {
  :deep(.el-dialog__header) {
    margin-right: 0;
    padding: 20px;
    border-bottom: 1px solid #4C4F5F;
  }

  :deep(.el-dialog__body) {
    padding: 20px;
  }

  :deep(.el-dialog__footer) {
    padding: 20px;
    border-top: 1px solid #4C4F5F;
  }

  .import-title {
    font-size: 14px;
    color: #96A0B5;
    margin-bottom: 20px;
  }

  .import-upload {
    :deep(.el-upload-dragger) {
      width: 100%;
      height: 200px;
      background-color: #292C38;
      border: 1px dashed #4C4F5F;
      border-radius: 8px;
      display: flex;
      justify-content: center;
      align-items: center;

      &:hover {
        border-color: #347AE2;
      }
    }

    .upload-content {
      display: flex;
      flex-direction: column;
      align-items: center;
      color: #96A0B5;

      .upload-icon {
        font-size: 40px;
        color: #96A0B5;
        margin-bottom: 10px;
      }

      .upload-text {
        font-size: 14px;
        margin-bottom: 10px;
      }

      .upload-link {
        display: flex;
        align-items: center;
        color: #347AE2;
        cursor: pointer;

        .upload-icon-small {
          font-size: 16px;
          margin-right: 4px;
        }

        .click-upload {
          font-size: 14px;
        }
      }
    }
  }

  .import-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;

    .footer-left {
      :deep(.el-checkbox__label) {
        color: #96A0B5;
      }
    }

    .footer-right {
      display: flex;
      align-items: center;
      gap: 10px;

      .file-format {
        color: #96A0B5;
        font-size: 12px;
      }

      .download-link {
        font-size: 12px;
      }
    }
  }

  .dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }
}

/* 头像上传样式 */
.avatar-uploader-box {
  display: flex;
  justify-content: flex-start;
  margin-top: 8px;
}

.avatar-uploader {
  text-align: center;
}

.avatar-preview {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 0;
  overflow: visible; /* 修改为visible，使计数器可以溢出边界 */
  
  .avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
    border: 1px solid #343744;
  }
  
  .avatar-count {
    position: absolute;
    top: -5px;
    right: -30px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
    z-index: 1;
  }
  
  .avatar-replace {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 1;
    z-index: 2;
    
    .el-icon {
      font-size: 14px;
      color: #ffffff;
    }
  }
}

.avatar-upload-placeholder {
  width: 120px;
  height: 120px;
  border: 1px dashed #4C4F5F;
  border-radius: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  background-color: transparent;
  overflow: visible; /* 修改为visible，使计数器可以溢出边界 */
  
  &:hover {
    border-color: #409EFF;
  }
  
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
  }
  
  .avatar-count {
    position: absolute;
    top: -5px;
    right: -30px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
    z-index: 1;
  }
}
</style>
