<template>
  <el-card shadow="hover">
    <template #header>
      <el-row justify="space-between" align="middle">
        <el-text tag="span" size="large">用户管理</el-text>
        <el-button type="primary" @click="dialogVisible = true">新增用户</el-button>
      </el-row>
    </template>

    <el-table :data="users" stripe>
      <el-table-column prop="id" label="ID" width="80" />
      <el-table-column prop="name" label="姓名" width="120" />
      <el-table-column prop="email" label="邮箱" />
      <el-table-column prop="role" label="角色" width="120">
        <template #default="{ row }">
          <el-tag :type="row.role === '管理员' ? 'danger' : row.role === '编辑' ? 'warning' : 'info'">
            {{ row.role }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template #default="{ row }">
          <el-switch v-model="row.status" />
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180">
        <template #default>
          <el-button size="small" type="primary" link>编辑</el-button>
          <el-button size="small" type="danger" link>删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-row justify="end" style="margin-top: 20px">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="100"
        :page-size="10"
      />
    </el-row>
  </el-card>

  <el-dialog v-model="dialogVisible" title="新增用户" width="500px">
    <el-form :model="form" label-width="80px">
      <el-form-item label="姓名">
        <el-input v-model="form.name" placeholder="请输入姓名" />
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="form.email" placeholder="请输入邮箱" />
      </el-form-item>
      <el-form-item label="角色">
        <el-select v-model="form.role" placeholder="请选择角色" style="width: 100%">
          <el-option label="管理员" value="管理员" />
          <el-option label="编辑" value="编辑" />
          <el-option label="用户" value="用户" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click="dialogVisible = false">确认</el-button>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'

const dialogVisible = ref(false)

const form = reactive({
  name: '',
  email: '',
  role: '',
})

const users = ref([
  { id: 1, name: '张三', email: 'zhangsan@example.com', role: '管理员', status: true },
  { id: 2, name: '李四', email: 'lisi@example.com', role: '编辑', status: true },
  { id: 3, name: '王五', email: 'wangwu@example.com', role: '用户', status: false },
  { id: 4, name: '赵六', email: 'zhaoliu@example.com', role: '用户', status: true },
  { id: 5, name: '孙七', email: 'sunqi@example.com', role: '编辑', status: true },
])
</script>
