<template>
  <div class="page-container">
    <div class="page-header">
      <span class="breadcrumb-label">当前位置：</span>
      <span class="breadcrumb-current">设备管理</span>
    </div>

    <!-- 查询栏 -->
    <div class="search-bar">
      <div class="search-item">
        <label>设备类型：</label>
        <select v-model="searchForm.terminalType">
          <option value="">全部</option>
          <option value="C">床头分机</option>
          <option value="D">病房门口机</option>
          <option value="H">护士站主机</option>
          <option value="X">护士站信息屏</option>
          <option value="T">LCD走廊显示屏</option>
          <option value="P">LED走廊显示屏</option>
          <option value="M">病区门口机</option>
        </select>
      </div>
      <div class="search-item">
        <label>所属科室：</label>
        <select v-model="searchForm.deptCode" @change="onDeptChange">
          <option value="">全部</option>
          <option v-for="(dept, index) in deptList" :key="index" :value="dept">{{ dept }}</option>
        </select>
      </div>
      <div class="search-item">
        <label>所属病区：</label>
        <select v-model="searchForm.wardCode">
          <option value="">全部</option>
          <option v-for="(ward, index) in wardList" :key="index" :value="ward">{{ ward }}</option>
        </select>
      </div>
      <div class="search-item">
        <label>在线状态：</label>
        <select v-model="searchForm.isOnline">
          <option value="">全部</option>
          <option :value="1">在线</option>
          <option :value="0">离线</option>
        </select>
      </div>
      <div class="search-item">
        <label>设备名称：</label>
        <input type="text" v-model="searchForm.terminalDesc" placeholder="请输入设备名称" />
      </div>
      <button class="search-btn" @click="handleSearch">查询</button>
      <button class="reset-btn" @click="handleReset">重置</button>
      <button class="add-btn" @click="handleAdd" v-if="isAdmin">新增</button>
    </div>

    <!-- 数据列表 -->
    <div class="table-container">
      <div v-if="loading" class="loading-mask">
        <div class="loading-spinner"></div>
        <span>加载中...</span>
      </div>
      <table class="data-table" v-show="!loading">
        <thead>
          <tr>
            <th>设备类型</th>
            <th>设备编码</th>
            <th>设备名称</th>
            <th>所属科室</th>
            <th>所属病区</th>
            <th>IP地址</th>
            <th>子网掩码</th>
            <th>默认网关</th>
            <th>Mac地址</th>
            <th>设备位置</th>
            <th>在线状态</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="item in tableData" :key="item.id">
            <td>{{ formatTerminalType(item.terminalType) }}</td>
            <td>{{ item.terminalNumber }}</td>
            <td>{{ item.terminalDesc }}</td>
            <td>{{ item.deptCode }}</td>
            <td>{{ item.wardCode }}</td>
            <td>{{ item.ipAddress }}</td>
            <td>{{ item.subnetMask }}</td>
            <td>{{ item.gatewayAddress }}</td>
            <td>{{ item.macAddress }}</td>
            <td>{{ item.tenementName }}</td>
            <td>
              <span :class="item.isOnline === 1 ? 'status-online' : 'status-offline'">
                {{ item.isOnline === 1 ? '在线' : '离线' }}
              </span>
            </td>
          </tr>
          <tr v-if="tableData.length === 0">
            <td colspan="11" class="empty-tip">暂无数据</td>
          </tr>
        </tbody>
      </table>
    </div>

    <!-- 分页 -->
    <div class="pagination" v-if="total > 0">
      <span class="pagination-info">共 {{ total }} 条记录</span>
      <div class="pagination-controls">
        <button class="page-btn" :disabled="currentPage === 1" @click="changePage(1)">首页</button>
        <button class="page-btn" :disabled="currentPage === 1" @click="changePage(currentPage - 1)">上一页</button>
        <span class="page-numbers">
          <button 
            v-for="page in displayPages" 
            :key="page" 
            class="page-num" 
            :class="{ active: page === currentPage }"
            @click="changePage(page)"
          >{{ page }}</button>
        </span>
        <button class="page-btn" :disabled="currentPage === totalPages" @click="changePage(currentPage + 1)">下一页</button>
        <button class="page-btn" :disabled="currentPage === totalPages" @click="changePage(totalPages)">末页</button>
        <span class="page-size-selector">
          <select v-model="pageSize" @change="handlePageSizeChange">
            <option :value="10">10条/页</option>
            <option :value="20">20条/页</option>
            <option :value="50">50条/页</option>
            <option :value="100">100条/页</option>
          </select>
        </span>
        <span class="page-jump">
          跳至 <input type="number" v-model.number="jumpPage" min="1" :max="totalPages" @keyup.enter="handleJumpPage" /> 页
        </span>
      </div>
    </div>
    
    <!-- 新增设备弹窗 -->
    <div v-if="showAddDialog" class="dialog-overlay" @click.self="closeAddDialog">
      <div class="dialog-content">
        <div class="dialog-header">
          <span>新增设备</span>
          <button class="close-btn" @click="closeAddDialog">&times;</button>
        </div>
        <div class="dialog-body">
          <div class="form-row">
            <label class="required">设备类型：</label>
            <select v-model="addForm.terminalType" @change="onTypeChange">
              <option value="">请选择</option>
              <option value="C">床头分机</option>
              <option value="D">病房门口机</option>
              <option value="H">护士站主机</option>
              <option value="X">护士站信息屏</option>
              <option value="T">LCD走廊显示屏</option>
              <option value="P">LED走廊显示屏</option>
              <option value="M">病区门口机</option>
            </select>
          </div>
          <div class="form-row">
            <label>设备编码：</label>
            <input type="text" v-model="generatedCode" readonly class="readonly-input" placeholder="系统自动生成" />
          </div>
          <div class="form-row">
            <label>所属科室：</label>
            <select v-model="addForm.selectedDept" @change="onAddDeptChange">
              <option value="">请选择</option>
              <option v-for="dept in presetDeptList" :key="dept" :value="dept">{{ dept }}</option>
            </select>
          </div>
          <div class="form-row">
            <label>所属病区：</label>
            <select v-model="addForm.selectedWard" @change="onWardChange">
              <option value="">请选择</option>
              <option v-for="ward in realWardList" :key="ward.id" :value="ward.code">{{ ward.name }}</option>
            </select>
          </div>
          
          <!-- 设备名称组成部分 -->
          <div class="form-section">
            <div class="section-title">设备名称组成</div>
            <div class="form-row">
              <label>设备类型编号：</label>
              <input type="text" :value="addForm.terminalType" readonly class="readonly-input short-input" />
            </div>
            <div class="form-row">
              <label>病区代码：</label>
              <input type="text" v-model="addForm.wardCode" readonly class="readonly-input short-input" placeholder="选择病区后自动带出" />
            </div>
            <div class="form-row" v-if="needRoomCode">
              <label>病房代码：</label>
              <input type="text" v-model="addForm.roomCode" maxlength="4" @blur="formatRoomCode" placeholder="4位数字" class="short-input" />
            </div>
            <div class="form-row" v-if="needBedNo">
              <label>床位号：</label>
              <input type="text" v-model="addForm.bedNo" maxlength="3" @blur="formatBedNo" placeholder="3位数字" class="short-input" />
            </div>
            <div class="form-row" v-if="needDeviceNo">
              <label>设备号：</label>
              <input type="text" v-model="addForm.deviceNo" maxlength="2" @blur="formatDeviceNo" placeholder="2位数字" class="short-input" />
            </div>
          </div>
          
          <div class="form-row">
            <label class="required">IP地址：</label>
            <input type="text" v-model="addForm.ipAddress" placeholder="如：192.168.1.100" />
          </div>
          <div class="form-row">
            <label>子网掩码：</label>
            <input type="text" v-model="addForm.subnetMask" placeholder="如：255.255.255.0" />
          </div>
          <div class="form-row">
            <label>默认网关：</label>
            <input type="text" v-model="addForm.gatewayAddress" placeholder="如：192.168.1.1" />
          </div>
          <div class="form-row">
            <label>设备位置：</label>
            <input type="text" v-model="addForm.tenementName" placeholder="请输入设备安装位置" />
          </div>
        </div>
        <div class="dialog-footer">
          <button class="cancel-btn" @click="closeAddDialog">取消</button>
          <button class="confirm-btn" @click="submitAdd">确定</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, computed } from 'vue'
import request from '@/utils/request'

// 判断是否为管理员
const isAdmin = computed(() => {
  const userType = localStorage.getItem('userType')
  return userType === 'admin'
})

// 查询条件
const searchForm = reactive({
  terminalType: '',
  deptCode: '',
  wardCode: '',
  isOnline: '',
  terminalDesc: ''
})

// 下拉列表数据
const deptList = ref([])
const wardList = ref([])

// 表格数据
const tableData = ref([])

// 加载状态
const loading = ref(false)

// 分页相关
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(0)
const jumpPage = ref(1)

// 计算总页数
const totalPages = computed(() => Math.ceil(total.value / pageSize.value) || 1)

// 计算显示的页码
const displayPages = computed(() => {
  const pages = []
  const maxShow = 5
  let start = Math.max(1, currentPage.value - Math.floor(maxShow / 2))
  let end = Math.min(totalPages.value, start + maxShow - 1)
  if (end - start + 1 < maxShow) {
    start = Math.max(1, end - maxShow + 1)
  }
  for (let i = start; i <= end; i++) {
    pages.push(i)
  }
  return pages
})

// 新增弹窗
const showAddDialog = ref(false)
const realDeptList = ref([])
const realWardList = ref([])

// 新增表单
const addForm = reactive({
  terminalType: '',
  selectedDept: '',
  selectedWard: '',
  wardCode: '',
  roomCode: '',
  bedNo: '',
  deviceNo: '',
  ipAddress: '',
  subnetMask: '255.255.255.0',
  gatewayAddress: '',
  tenementName: ''
})

// 设备类型映射
const terminalTypeMap = {
  'C': '床头分机',
  'D': '病房门口机',
  'H': '护士站主机',
  'X': '护士站信息屏',
  'T': 'LCD走廊显示屏',
  'P': 'LED走廊显示屏',
  'M': '病区门口机'
}

// 预设的科室和病区数据
const deptWardData = {
  '急诊科': [
    { code: '01', name: '抢救区' },
    { code: '02', name: '危重诊疗区' },
    { code: '03', name: '普通诊疗区' },
    { code: '04', name: '急诊观察室' },
    { code: '05', name: '急诊综合病房/EICU' }
  ],
  '综合内科': [
    { code: '01', name: '综合内科一病区' },
    { code: '02', name: '综合内科二病区' },
    { code: '03', name: '综合内科三病区' }
  ],
  '康复医学科': [
    { code: '01', name: '神经康复病区' },
    { code: '02', name: '骨关节康复病区' },
    { code: '03', name: '心肺康复病区' }
  ],
  '心血管内科': [
    { code: '01', name: '冠心病病区' },
    { code: '02', name: '心律失常病区' },
    { code: '03', name: '心力衰竭与重症病区' },
    { code: '04', name: '高血压与心脏康复病区' },
    { code: '05', name: '心脏监护病房（CCU）' }
  ],
  '内分泌科': [
    { code: '01', name: '糖尿病病区' },
    { code: '02', name: '甲状腺与代谢病病区' },
    { code: '03', name: '肥胖与代谢综合征病区' }
  ],
  '神经内科': [
    { code: '01', name: '脑血管病病区' },
    { code: '02', name: '运动障碍与神经变性病病区' },
    { code: '03', name: '癫痫与睡眠障碍病区' },
    { code: '04', name: '神经免疫与感染病区' }
  ],
  '骨科': [
    { code: '01', name: '脊柱外科病区' },
    { code: '02', name: '关节外科病区' },
    { code: '03', name: '创伤骨科病区' },
    { code: '04', name: '手外科/显微外科病区' },
    { code: '05', name: '运动医学科病区' }
  ],
  '眼科': [
    { code: '01', name: '一病区' }
  ],
  '耳鼻喉科': [
    { code: '01', name: '耳科与颅底外科病区' },
    { code: '02', name: '鼻科与过敏性疾病病区' },
    { code: '03', name: '咽喉头颈外科病区' }
  ],
  '口腔科': [
    { code: '01', name: '口腔颌面外科病区' }
  ],
  '皮肤科': [
    { code: '01', name: '普通皮肤科病区' },
    { code: '02', name: '皮肤外科与美容病区' }
  ],
  '中医科': [
    { code: '01', name: '针灸推拿病区' },
    { code: '02', name: '康复病区' },
    { code: '03', name: '中医内科病区' },
    { code: '04', name: '中医骨伤病区' },
    { code: '05', name: '纯中医治疗病区' },
    { code: '06', name: '中西医结合病区' }
  ],
  '医学影像科': [
    { code: '01', name: 'X线/DR检查区' },
    { code: '02', name: 'CT检查区' },
    { code: '03', name: '磁共振检查区' },
    { code: '04', name: '超声检查区' },
    { code: '05', name: '临检室' }
  ]
}

// 获取科室列表
const presetDeptList = computed(() => Object.keys(deptWardData))

// 是否需要病房代码（床头分机、病房门口机）
const needRoomCode = computed(() => ['C', 'D'].includes(addForm.terminalType))

// 是否需要床位号（只有床头分机）
const needBedNo = computed(() => addForm.terminalType === 'C')

// 是否需要设备号（护士站主机、护士站信息屏、走廊显示屏、病区门口机）
const needDeviceNo = computed(() => ['H', 'X', 'T', 'P', 'M'].includes(addForm.terminalType))

// 生成的设备编码
const generatedCode = computed(() => {
  let code = addForm.terminalType || ''
  if (addForm.wardCode) code += addForm.wardCode
  if (needRoomCode.value && addForm.roomCode) code += addForm.roomCode
  if (needBedNo.value && addForm.bedNo) code += addForm.bedNo
  if (needDeviceNo.value && addForm.deviceNo) code += addForm.deviceNo
  return code
})

onMounted(async () => {
  loading.value = true
  try {
    // 使用合并接口，一次请求获取所有数据
    const res = await request.get('/api/terminal/init-data', {
      params: {
        page: currentPage.value,
        pageSize: pageSize.value
      }
    })
    if (res.code === 200 && res.data) {
      deptList.value = res.data.deptList || []
      wardList.value = res.data.wardList || []
      tableData.value = res.data.terminalList?.records || res.data.terminalList || []
      total.value = res.data.terminalList?.total || tableData.value.length
    }
  } catch (error) {
    console.error('加载数据失败：', error)
  } finally {
    loading.value = false
  }
})

// 加载所属科室列表
const loadDeptList = async () => {
  try {
    const res = await request.get('/api/terminal/dept-list')
    if (res.code === 200) {
      deptList.value = res.data || []
    }
  } catch (error) {
    console.error('加载科室列表失败：', error)
  }
}

// 加载病区列表
const loadWardList = async () => {
  try {
    const params = {}
    if (searchForm.deptCode) params.deptCode = searchForm.deptCode
    const res = await request.get('/api/terminal/ward-list', { params })
    if (res.code === 200) {
      wardList.value = res.data || []
    }
  } catch (error) {
    console.error('加载病区列表失败：', error)
  }
}

// 科室变化时
const onDeptChange = () => {
  searchForm.wardCode = ''
  loadWardList()
}

// 加载数据
const loadData = async () => {
  loading.value = true
  try {
    const params = {
      page: currentPage.value,
      pageSize: pageSize.value
    }
    if (searchForm.terminalType) params.terminalType = searchForm.terminalType
    if (searchForm.deptCode) params.deptCode = searchForm.deptCode
    if (searchForm.wardCode) params.wardCode = searchForm.wardCode
    if (searchForm.isOnline !== '') params.isOnline = searchForm.isOnline
    if (searchForm.terminalDesc) params.terminalDesc = searchForm.terminalDesc
    
    const res = await request.get('/api/terminal/list', { params })
    if (res.code === 200) {
      tableData.value = res.data?.records || res.data || []
      total.value = res.data?.total || tableData.value.length
    }
  } catch (error) {
    console.error('加载数据失败：', error)
  } finally {
    loading.value = false
  }
}

// 切换页码
const changePage = (page) => {
  if (page >= 1 && page <= totalPages.value) {
    currentPage.value = page
    jumpPage.value = page
    loadData()
  }
}

// 修改每页条数
const handlePageSizeChange = () => {
  currentPage.value = 1
  loadData()
}

// 跳转到指定页
const handleJumpPage = () => {
  const page = Math.min(Math.max(1, jumpPage.value), totalPages.value)
  changePage(page)
}

// 查询
const handleSearch = () => {
  currentPage.value = 1
  loadData()
}

// 重置
const handleReset = () => {
  searchForm.terminalType = ''
  searchForm.deptCode = ''
  searchForm.wardCode = ''
  searchForm.isOnline = ''
  searchForm.terminalDesc = ''
  currentPage.value = 1
  loadWardList()
  loadData()
}

// 新增按钮点击
const handleAdd = () => {
  // 重置表单
  resetAddForm()
  showAddDialog.value = true
}

// 重置新增表单
const resetAddForm = () => {
  addForm.terminalType = ''
  addForm.selectedDept = ''
  addForm.selectedWard = ''
  addForm.wardCode = ''
  addForm.roomCode = ''
  addForm.bedNo = ''
  addForm.deviceNo = ''
  addForm.ipAddress = ''
  addForm.subnetMask = '255.255.255.0'
  addForm.gatewayAddress = ''
  addForm.tenementName = ''
  realWardList.value = []
}

// 关闭新增弹窗
const closeAddDialog = () => {
  showAddDialog.value = false
}

// 设备类型变化
const onTypeChange = () => {
  // 清空相关字段
  addForm.roomCode = ''
  addForm.bedNo = ''
  addForm.deviceNo = ''
}

// 新增弹窗中科室变化
const onAddDeptChange = () => {
  addForm.selectedWard = ''
  addForm.wardCode = ''
  if (!addForm.selectedDept) {
    realWardList.value = []
    return
  }
  // 从预设数据中获取病区列表
  realWardList.value = deptWardData[addForm.selectedDept] || []
}

// 病区变化
const onWardChange = () => {
  const selected = realWardList.value.find(w => w.code === addForm.selectedWard)
  if (selected) {
    addForm.wardCode = selected.code || ''
  } else {
    addForm.wardCode = ''
  }
}

// 格式化病房代码（4位数字，不足前补0）
const formatRoomCode = () => {
  if (addForm.roomCode) {
    const num = addForm.roomCode.replace(/\D/g, '')
    addForm.roomCode = num.padStart(4, '0').slice(-4)
  }
}

// 格式化床位号（3位数字，不足前补0）
const formatBedNo = () => {
  if (addForm.bedNo) {
    const num = addForm.bedNo.replace(/\D/g, '')
    addForm.bedNo = num.padStart(3, '0').slice(-3)
  }
}

// 格式化设备号（2位数字，不足前补0）
const formatDeviceNo = () => {
  if (addForm.deviceNo) {
    const num = addForm.deviceNo.replace(/\D/g, '')
    addForm.deviceNo = num.padStart(2, '0').slice(-2)
  }
}

// 提交新增
const submitAdd = async () => {
  // 校验必填字段
  if (!addForm.terminalType) {
    alert('请选择设备类型')
    return
  }
  if (!addForm.ipAddress) {
    alert('请输入IP地址')
    return
  }
  
  // 构造设备名称
  let terminalDesc = ''
  if (addForm.wardCode) terminalDesc += addForm.wardCode
  if (needRoomCode.value && addForm.roomCode) terminalDesc += addForm.roomCode
  if (needBedNo.value && addForm.bedNo) terminalDesc += addForm.bedNo
  if (needDeviceNo.value && addForm.deviceNo) terminalDesc += addForm.deviceNo
  
  // 构造请求数据
  const data = {
    terminalType: addForm.terminalType,
    terminalDesc: terminalDesc,
    deptCode: addForm.selectedDept,
    wardCode: addForm.selectedWard ? (realWardList.value.find(w => w.code === addForm.selectedWard)?.name || '') : '',
    ipAddress: addForm.ipAddress,
    subnetMask: addForm.subnetMask,
    gatewayAddress: addForm.gatewayAddress,
    tenementName: addForm.tenementName
  }
  
  try {
    const res = await request.post('/api/terminal/add', data)
    if (res.code === 200) {
      alert('新增成功')
      closeAddDialog()
      loadData()
    } else {
      alert(res.message || '新增失败')
    }
  } catch (error) {
    console.error('新增失败：', error)
    alert('新增失败')
  }
}

// 格式化设备类型
const formatTerminalType = (type) => {
  const map = {
    'S': '室内机',
    'M': '门口机',
    'R': '入口机',
    'Z': '中心机',
    'F': '室内分机',
    'L': '数字门铃',
    'H': '护士站主机',
    'C': '床头分机',
    'D': '病房门口机',
    'X': '护士站信息屏',
    'T': 'LCD走廊显示屏',
    'P': 'LED走廊显示屏'
  }
  return map[type] || type || ''
}
</script>

<style scoped>
.page-container {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
}
.page-header {
  border-bottom: 1px solid #eee;
  padding-bottom: 15px;
  margin-bottom: 20px;
  font-size: 14px;
}
.breadcrumb-label { color: #666; }
.breadcrumb-current { color: #409eff; }

/* 查询栏 */
.search-bar {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
  padding: 15px;
  background: #f5f7fa;
  border-radius: 4px;
  flex-wrap: wrap;
}
.search-item {
  display: flex;
  align-items: center;
}
.search-item label {
  margin-right: 8px;
  color: #666;
  font-size: 14px;
  white-space: nowrap;
}
.search-item input,
.search-item select {
  padding: 8px 12px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  font-size: 14px;
}
.search-item input { width: 150px; }
.search-item select { width: 150px; }
.search-btn {
  padding: 8px 20px;
  background: #409eff;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.search-btn:hover { background: #66b1ff; }
.reset-btn {
  padding: 8px 20px;
  background: #fff;
  color: #666;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.reset-btn:hover { border-color: #409eff; color: #409eff; }
.add-btn {
  padding: 8px 20px;
  background: #67c23a;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.add-btn:hover { background: #85ce61; }

/* 数据表格 */
.table-container {
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th,
.data-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #eee;
  white-space: nowrap;
}
.data-table th {
  background: #f5f7fa;
  font-weight: 500;
  color: #333;
}
.data-table tbody tr:hover {
  background: #f5f7fa;
}
.empty-tip {
  text-align: center;
  color: #999;
  padding: 40px 0;
}

/* 加载状态 */
.loading-mask {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
  color: #909399;
}
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #409eff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 状态样式 */
.status-online {
  color: #67c23a;
  font-weight: 500;
}
.status-offline {
  color: #f56c6c;
  font-weight: 500;
}

/* 弹窗样式 */
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.dialog-content {
  background: #fff;
  border-radius: 8px;
  width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}
.dialog-header {
  padding: 15px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-weight: 500;
}
.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
}
.close-btn:hover { color: #666; }
.dialog-body {
  padding: 20px;
}
.dialog-footer {
  padding: 15px 20px;
  border-top: 1px solid #eee;
  text-align: right;
}
.form-row {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}
.form-row label {
  width: 120px;
  text-align: right;
  padding-right: 10px;
  color: #666;
  font-size: 14px;
}
.form-row label.required::before {
  content: '*';
  color: #f56c6c;
  margin-right: 4px;
}
.form-row input,
.form-row select {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  font-size: 14px;
}
.form-row input:focus,
.form-row select:focus {
  border-color: #409eff;
  outline: none;
}
.readonly-input {
  background: #f5f7fa;
  cursor: not-allowed;
}
.short-input {
  flex: none !important;
  width: 120px;
}
.form-section {
  background: #f9f9f9;
  padding: 15px;
  border-radius: 4px;
  margin: 15px 0;
}
.section-title {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}
.cancel-btn {
  padding: 8px 20px;
  background: #fff;
  color: #666;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 10px;
}
.cancel-btn:hover { border-color: #409eff; color: #409eff; }
.confirm-btn {
  padding: 8px 20px;
  background: #409eff;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.confirm-btn:hover { background: #66b1ff; }

/* 分页样式 */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding: 15px 0;
  border-top: 1px solid #eee;
}
.pagination-info {
  color: #666;
  font-size: 14px;
}
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}
.page-btn {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: #606266;
}
.page-btn:hover:not(:disabled) {
  color: #409eff;
  border-color: #c6e2ff;
}
.page-btn:disabled {
  color: #c0c4cc;
  cursor: not-allowed;
}
.page-numbers {
  display: flex;
  gap: 5px;
}
.page-num {
  min-width: 32px;
  height: 28px;
  padding: 0 6px;
  background: #fff;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: #606266;
}
.page-num:hover {
  color: #409eff;
  border-color: #c6e2ff;
}
.page-num.active {
  background: #409eff;
  border-color: #409eff;
  color: #fff;
}
.page-size-selector select {
  padding: 5px 10px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  font-size: 13px;
  margin-left: 10px;
}
.page-jump {
  font-size: 13px;
  color: #606266;
  margin-left: 10px;
}
.page-jump input {
  width: 50px;
  padding: 5px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  text-align: center;
  margin: 0 5px;
}</style>
