<template>
  <div>
    <h1>检疫配置管理</h1>
    
    <!-- 配置类型切换 -->
    <a-card style="margin-bottom: 16px;">
      <a-radio-group v-model:value="currentConfigType" @change="handleConfigTypeChange">
        <a-radio :value="'quarantineItems'">检疫项目配置</a-radio>
        <a-radio :value="'quarantineProcesses'">检疫流程配置</a-radio>
        <a-radio :value="'quarantineStandards'">检疫标准配置</a-radio>
        <a-radio :value="'quarantineTypes'">检疫类型配置</a-radio>
        <a-radio :value="'quarantinePersonnel'">检疫人员配置</a-radio>
      </a-radio-group>
    </a-card>
    
    <!-- 检疫项目配置 -->
    <div v-if="currentConfigType === 'quarantineItems'">
      <!-- 搜索和操作栏 -->
      <a-card style="margin-bottom: 16px;">
        <div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center;">
          <a-input v-model:value="quarantineItemsSearchKeyword" placeholder="输入检疫项目名称" style="width: 250px;">
            <template #prefix>
              <span class="iconfont icon-sousuo"></span>
            </template>
          </a-input>
          
          <a-select v-model:value="quarantineItemsTypeFilter" placeholder="检疫类型" style="width: 120px;">
            <a-select-option value="">全部</a-select-option>
            <a-select-option value="animal">动物检疫</a-select-option>
            <a-select-option value="product">动物产品检疫</a-select-option>
            <a-select-option value="transport">运输检疫</a-select-option>
            <a-select-option value="slaughter">屠宰检疫</a-select-option>
            <a-select-option value="other">其他检疫</a-select-option>
          </a-select>
          
          <a-button type="primary" @click="handleQuarantineItemsSearch" style="margin-left: auto;">
            <span class="iconfont icon-sousuo"></span> 搜索
          </a-button>
          
          <a-button type="default" @click="handleQuarantineItemsReset">重置</a-button>
          
          <a-button type="primary" danger @click="handleAddQuarantineItem">
            <span class="iconfont icon-tianjia"></span> 新增项目
          </a-button>
        </div>
      </a-card>
      
      <!-- 数据列表 -->
      <a-card>
        <a-table
          :columns="quarantineItemsColumns"
          :data-source="quarantineItemsData"
          :pagination="quarantineItemsPagination"
          row-key="id"
          :row-selection="{ selectedRowKeys: quarantineItemsSelectedRowKeys, onChange: onQuarantineItemsSelectChange }"
        >
          <!-- 操作列 -->
          <template #bodyCell:action="{ record }">
            <div style="display: flex; gap: 8px;">
              <a-button size="small" @click="handleEditQuarantineItem(record)">编辑</a-button>
              <a-button size="small" danger @click="handleDeleteQuarantineItem(record.id)">删除</a-button>
            </div>
          </template>
        </a-table>
      </a-card>
      
      <!-- 新增/编辑检疫项目模态框 -->
      <a-modal
        v-model:open="isQuarantineItemsModalOpen"
        :title="isEditingQuarantineItem ? '编辑检疫项目' : '新增检疫项目'"
        :footer="null"
        width={600}
      >
        <a-form
          :model="currentQuarantineItem"
          layout="vertical"
        >
          <a-form-item label="项目名称"
                       :rules="[{ required: true, message: '请输入项目名称' }]">
            <a-input v-model:value="currentQuarantineItem.name" placeholder="请输入检疫项目名称" />
          </a-form-item>
          
          <a-form-item label="适用检疫类型"
                       :rules="[{ required: true, message: '请选择适用检疫类型' }]">
            <a-select v-model:value="currentQuarantineItem.applicableType" placeholder="请选择适用检疫类型">
              <a-select-option value="animal">动物检疫</a-select-option>
              <a-select-option value="product">动物产品检疫</a-select-option>
              <a-select-option value="transport">运输检疫</a-select-option>
              <a-select-option value="slaughter">屠宰检疫</a-select-option>
              <a-select-option value="other">其他检疫</a-select-option>
            </a-select>
          </a-form-item>
          
          <a-form-item label="检测标准">
            <a-input.TextArea v-model:value="currentQuarantineItem.standard" placeholder="请输入检测标准" rows={3} />
          </a-form-item>
          
          <a-form-item label="描述">
            <a-input.TextArea v-model:value="currentQuarantineItem.description" placeholder="请输入项目描述" rows={3} />
          </a-form-item>
        </a-form>
        
        <div style="display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px;">
          <a-button @click="handleQuarantineItemsCancel">取消</a-button>
          <a-button type="primary" @click="handleQuarantineItemsSave">保存</a-button>
        </div>
      </a-modal>
    </div>
    
    <!-- 检疫流程配置 -->
    <div v-else-if="currentConfigType === 'quarantineProcesses'">
      <!-- 搜索和操作栏 -->
      <a-card style="margin-bottom: 16px;">
        <div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center;">
          <a-input v-model:value="quarantineProcessesSearchKeyword" placeholder="输入流程名称" style="width: 250px;">
            <template #prefix>
              <span class="iconfont icon-sousuo"></span>
            </template>
          </a-input>
          
          <a-select v-model:value="quarantineProcessesTypeFilter" placeholder="检疫类型" style="width: 120px;">
            <a-select-option value="">全部</a-select-option>
            <a-select-option value="animal">动物检疫</a-select-option>
            <a-select-option value="product">动物产品检疫</a-select-option>
            <a-select-option value="transport">运输检疫</a-select-option>
            <a-select-option value="slaughter">屠宰检疫</a-select-option>
            <a-select-option value="other">其他检疫</a-select-option>
          </a-select>
          
          <a-button type="primary" @click="handleQuarantineProcessesSearch" style="margin-left: auto;">
            <span class="iconfont icon-sousuo"></span> 搜索
          </a-button>
          
          <a-button type="default" @click="handleQuarantineProcessesReset">重置</a-button>
          
          <a-button type="primary" danger @click="handleAddQuarantineProcess">
            <span class="iconfont icon-tianjia"></span> 新增流程
          </a-button>
        </div>
      </a-card>
      
      <!-- 数据列表 -->
      <a-card>
        <a-table
          :columns="quarantineProcessesColumns"
          :data-source="quarantineProcessesData"
          :pagination="quarantineProcessesPagination"
          row-key="id"
          :row-selection="{ selectedRowKeys: quarantineProcessesSelectedRowKeys, onChange: onQuarantineProcessesSelectChange }"
        >
          <!-- 操作列 -->
          <template #bodyCell:action="{ record }">
            <div style="display: flex; gap: 8px;">
              <a-button size="small" @click="handleEditQuarantineProcess(record)">编辑</a-button>
              <a-button size="small" @click="handleProcessSteps(record)">步骤管理</a-button>
              <a-button size="small" danger @click="handleDeleteQuarantineProcess(record.id)">删除</a-button>
            </div>
          </template>
        </a-table>
      </a-card>
    </div>
    
    <!-- 检疫标准配置 -->
    <div v-else-if="currentConfigType === 'quarantineStandards'">
      <!-- 搜索和操作栏 -->
      <a-card style="margin-bottom: 16px;">
        <div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center;">
          <a-input v-model:value="quarantineStandardsSearchKeyword" placeholder="输入标准名称" style="width: 250px;">
            <template #prefix>
              <span class="iconfont icon-sousuo"></span>
            </template>
          </a-input>
          
          <a-select v-model:value="quarantineStandardsTypeFilter" placeholder="标准类型" style="width: 120px;">
            <a-select-option value="">全部</a-select-option>
            <a-select-option value="national">国家标准</a-select-option>
            <a-select-option value="industry">行业标准</a-select-option>
            <a-select-option value="local">地方标准</a-select-option>
            <a-select-option value="enterprise">企业标准</a-select-option>
          </a-select>
          
          <a-button type="primary" @click="handleQuarantineStandardsSearch" style="margin-left: auto;">
            <span class="iconfont icon-sousuo"></span> 搜索
          </a-button>
          
          <a-button type="default" @click="handleQuarantineStandardsReset">重置</a-button>
          
          <a-button type="primary" danger @click="handleAddQuarantineStandard">
            <span class="iconfont icon-tianjia"></span> 新增标准
          </a-button>
        </div>
      </a-card>
      
      <!-- 数据列表 -->
      <a-card>
        <a-table
          :columns="quarantineStandardsColumns"
          :data-source="quarantineStandardsData"
          :pagination="quarantineStandardsPagination"
          row-key="id"
          :row-selection="{ selectedRowKeys: quarantineStandardsSelectedRowKeys, onChange: onQuarantineStandardsSelectChange }"
        >
          <!-- 操作列 -->
          <template #bodyCell:action="{ record }">
            <div style="display: flex; gap: 8px;">
              <a-button size="small" @click="handleEditQuarantineStandard(record)">编辑</a-button>
              <a-button size="small" @click="handleViewQuarantineStandard(record)">查看</a-button>
              <a-button size="small" danger @click="handleDeleteQuarantineStandard(record.id)">删除</a-button>
            </div>
          </template>
        </a-table>
      </a-card>
    </div>
    
    <!-- 检疫类型配置 -->
    <div v-else-if="currentConfigType === 'quarantineTypes'">
      <!-- 搜索和操作栏 -->
      <a-card style="margin-bottom: 16px;">
        <div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center;">
          <a-input v-model:value="quarantineTypesSearchKeyword" placeholder="输入类型名称" style="width: 250px;">
            <template #prefix>
              <span class="iconfont icon-sousuo"></span>
            </template>
          </a-input>
          
          <a-button type="primary" @click="handleQuarantineTypesSearch" style="margin-left: auto;">
            <span class="iconfont icon-sousuo"></span> 搜索
          </a-button>
          
          <a-button type="default" @click="handleQuarantineTypesReset">重置</a-button>
          
          <a-button type="primary" danger @click="handleAddQuarantineType">
            <span class="iconfont icon-tianjia"></span> 新增类型
          </a-button>
        </div>
      </a-card>
      
      <!-- 数据列表 -->
      <a-card>
        <a-table
          :columns="quarantineTypesColumns"
          :data-source="quarantineTypesData"
          :pagination="quarantineTypesPagination"
          row-key="id"
          :row-selection="{ selectedRowKeys: quarantineTypesSelectedRowKeys, onChange: onQuarantineTypesSelectChange }"
        >
          <!-- 操作列 -->
          <template #bodyCell:action="{ record }">
            <div style="display: flex; gap: 8px;">
              <a-button size="small" @click="handleEditQuarantineType(record)">编辑</a-button>
              <a-button size="small" danger @click="handleDeleteQuarantineType(record.id)">删除</a-button>
            </div>
          </template>
        </a-table>
      </a-card>
    </div>
    
    <!-- 检疫人员配置 -->
    <div v-else-if="currentConfigType === 'quarantinePersonnel'">
      <!-- 搜索和操作栏 -->
      <a-card style="margin-bottom: 16px;">
        <div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center;">
          <a-input v-model:value="quarantinePersonnelSearchKeyword" placeholder="输入人员姓名" style="width: 250px;">
            <template #prefix>
              <span class="iconfont icon-sousuo"></span>
            </template>
          </a-input>
          
          <a-select v-model:value="quarantinePersonnelTypeFilter" placeholder="所属部门" style="width: 150px;">
            <a-select-option value="">全部</a-select-option>
            <a-select-option value="animalHealth">动物卫生监督所</a-select-option>
            <a-select-option value="quarantineStation">检疫站</a-select-option>
            <a-select-option value="veterinaryStation">兽医站</a-select-option>
            <a-select-option value="other">其他部门</a-select-option>
          </a-select>
          
          <a-button type="primary" @click="handleQuarantinePersonnelSearch" style="margin-left: auto;">
            <span class="iconfont icon-sousuo"></span> 搜索
          </a-button>
          
          <a-button type="default" @click="handleQuarantinePersonnelReset">重置</a-button>
          
          <a-button type="primary" danger @click="handleAddQuarantinePersonnel">
            <span class="iconfont icon-tianjia"></span> 新增人员
          </a-button>
        </div>
      </a-card>
      
      <!-- 数据列表 -->
      <a-card>
        <a-table
          :columns="quarantinePersonnelColumns"
          :data-source="quarantinePersonnelData"
          :pagination="quarantinePersonnelPagination"
          row-key="id"
          :row-selection="{ selectedRowKeys: quarantinePersonnelSelectedRowKeys, onChange: onQuarantinePersonnelSelectChange }"
        >
          <!-- 操作列 -->
          <template #bodyCell:action="{ record }">
            <div style="display: flex; gap: 8px;">
              <a-button size="small" @click="handleEditQuarantinePersonnel(record)">编辑</a-button>
              <a-button size="small" @click="handleViewQuarantinePersonnel(record)">查看</a-button>
              <a-button size="small" danger @click="handleDeleteQuarantinePersonnel(record.id)">删除</a-button>
            </div>
          </template>
        </a-table>
      </a-card>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { message } from 'ant-design-vue'

// 当前配置类型
const currentConfigType = ref('quarantineItems')

// 检疫项目配置相关变量
const quarantineItemsSearchKeyword = ref('')
const quarantineItemsTypeFilter = ref('')
const quarantineItemsSelectedRowKeys = ref([])
const isQuarantineItemsModalOpen = ref(false)
const isEditingQuarantineItem = ref(false)
const currentQuarantineItem = reactive({
  id: '',
  name: '',
  applicableType: 'animal',
  standard: '',
  description: ''
})

// 检疫项目分页配置
const quarantineItemsPagination = reactive({
  current: 1,
  pageSize: 10,
  total: 0,
  showSizeChanger: true,
  showQuickJumper: true,
  showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，共 ${total} 条`
})

// 检疫项目数据（模拟数据）
const quarantineItemsData = ref([
  {
    id: '1',
    name: '体温检测',
    applicableType: 'animal',
    standard: '体温在38.5℃-39.5℃之间视为正常',
    description: '使用体温计测量动物体温，判断是否发热'
  },
  {
    id: '2',
    name: '临床检查',
    applicableType: 'animal',
    standard: '无咳嗽、腹泻、精神萎靡等症状',
    description: '观察动物精神状态、饮食情况、呼吸状况等'
  },
  {
    id: '3',
    name: '疫苗接种记录',
    applicableType: 'animal',
    standard: '按规定完成免疫接种',
    description: '核查动物疫苗接种记录，确保免疫程序完整'
  },
  {
    id: '4',
    name: '疫情监测',
    applicableType: 'animal',
    standard: '无传染病症状和接触史',
    description: '了解动物来源地疫情情况，检查动物是否有传染病症状'
  },
  {
    id: '5',
    name: '感官检查',
    applicableType: 'product',
    standard: '无异味、异色、异状',
    description: '通过视觉、嗅觉、触觉检查产品外观和气味'
  },
  {
    id: '6',
    name: '微生物检测',
    applicableType: 'product',
    standard: '符合国家标准规定的微生物限量',
    description: '检测产品中的细菌、病毒等微生物含量'
  },
  {
    id: '7',
    name: '兽药残留检测',
    applicableType: 'product',
    standard: '符合国家标准规定的残留限量',
    description: '检测产品中兽药残留量是否超标'
  },
  {
    id: '8',
    name: '重金属检测',
    applicableType: 'product',
    standard: '符合国家标准规定的重金属限量',
    description: '检测产品中重金属含量是否超标'
  },
  {
    id: '9',
    name: '宰前检查',
    applicableType: 'slaughter',
    standard: '健康状况良好，无传染病症状',
    description: '屠宰前对动物进行健康检查'
  },
  {
    id: '10',
    name: '宰后检验',
    applicableType: 'slaughter',
    standard: '无病理变化，符合卫生标准',
    description: '屠宰后对动物胴体进行检验'
  }
])

// 检疫项目表格列定义
const quarantineItemsColumns = [
  {
    title: '项目名称',
    dataIndex: 'name',
    key: 'name'
  },
  {
    title: '适用检疫类型',
    dataIndex: 'applicableType',
    key: 'applicableType',
    width: 150,
    customRender: ({ text }) => getTypeText(text)
  },
  {
    title: '检测标准',
    dataIndex: 'standard',
    key: 'standard',
    ellipsis: true
  },
  {
    title: '描述',
    dataIndex: 'description',
    key: 'description',
    ellipsis: true
  },
  {
    title: '操作',
    key: 'action',
    width: 150,
    scopedSlots: { customRender: 'action' }
  }
]

// 检疫流程配置相关变量
const quarantineProcessesSearchKeyword = ref('')
const quarantineProcessesTypeFilter = ref('')
const quarantineProcessesSelectedRowKeys = ref([])
const isQuarantineProcessesModalOpen = ref(false)
const isEditingQuarantineProcess = ref(false)
const currentQuarantineProcess = reactive({
  id: '',
  name: '',
  applicableType: 'animal',
  description: '',
  steps: []
})

// 检疫流程分页配置
const quarantineProcessesPagination = reactive({
  current: 1,
  pageSize: 10,
  total: 0,
  showSizeChanger: true,
  showQuickJumper: true,
  showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，共 ${total} 条`
})

// 检疫流程数据（模拟数据）
const quarantineProcessesData = ref([
  {
    id: '1',
    name: '动物检疫流程',
    applicableType: 'animal',
    description: '适用于动物检疫的标准流程',
    steps: [
      { id: '1', name: '申报受理', order: 1 },
      { id: '2', name: '资料审核', order: 2 },
      { id: '3', name: '现场检疫', order: 3 },
      { id: '4', name: '实验室检测', order: 4 },
      { id: '5', name: '结果判定', order: 5 },
      { id: '6', name: '出具证明', order: 6 }
    ]
  },
  {
    id: '2',
    name: '动物产品检疫流程',
    applicableType: 'product',
    description: '适用于动物产品检疫的标准流程',
    steps: [
      { id: '1', name: '申报受理', order: 1 },
      { id: '2', name: '资料审核', order: 2 },
      { id: '3', name: '感官检查', order: 3 },
      { id: '4', name: '实验室检测', order: 4 },
      { id: '5', name: '结果判定', order: 5 },
      { id: '6', name: '出具证明', order: 6 }
    ]
  },
  {
    id: '3',
    name: '运输检疫流程',
    applicableType: 'transport',
    description: '适用于动物运输检疫的标准流程',
    steps: [
      { id: '1', name: '申报受理', order: 1 },
      { id: '2', name: '资料审核', order: 2 },
      { id: '3', name: '动物健康检查', order: 3 },
      { id: '4', name: '运输工具检查', order: 4 },
      { id: '5', name: '消毒情况检查', order: 5 },
      { id: '6', name: '出具证明', order: 6 }
    ]
  }
])

// 检疫流程表格列定义
const quarantineProcessesColumns = [
  {
    title: '流程名称',
    dataIndex: 'name',
    key: 'name'
  },
  {
    title: '适用检疫类型',
    dataIndex: 'applicableType',
    key: 'applicableType',
    width: 150,
    customRender: ({ text }) => getTypeText(text)
  },
  {
    title: '步骤数量',
    dataIndex: 'steps',
    key: 'stepCount',
    width: 100,
    customRender: ({ text }) => text ? text.length : 0
  },
  {
    title: '描述',
    dataIndex: 'description',
    key: 'description',
    ellipsis: true
  },
  {
    title: '操作',
    key: 'action',
    width: 200,
    scopedSlots: { customRender: 'action' }
  }
]

// 检疫标准配置相关变量
const quarantineStandardsSearchKeyword = ref('')
const quarantineStandardsTypeFilter = ref('')
const quarantineStandardsSelectedRowKeys = ref([])
const isQuarantineStandardsModalOpen = ref(false)
const isEditingQuarantineStandard = ref(false)
const currentQuarantineStandard = reactive({
  id: '',
  name: '',
  type: 'national',
  standardNumber: '',
  releaseDate: '',
  implementDate: '',
  content: '',
  description: ''
})

// 检疫标准分页配置
const quarantineStandardsPagination = reactive({
  current: 1,
  pageSize: 10,
  total: 0,
  showSizeChanger: true,
  showQuickJumper: true,
  showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，共 ${total} 条`
})

// 检疫标准数据（模拟数据）
const quarantineStandardsData = ref([
  {
    id: '1',
    name: '动物检疫管理办法',
    type: 'national',
    standardNumber: '农业部令2019年第4号',
    releaseDate: '2019-04-17',
    implementDate: '2019-06-01',
    content: '规定了动物检疫的基本要求、检疫程序、检疫结果处理等内容',
    description: '动物检疫管理的基本法规'
  },
  {
    id: '2',
    name: '动物产品检疫规程',
    type: 'industry',
    standardNumber: 'NY/T 1944-2010',
    releaseDate: '2010-09-21',
    implementDate: '2011-01-01',
    content: '规定了动物产品检疫的术语和定义、检疫程序、检疫方法、检疫结果判定和处理等内容',
    description: '动物产品检疫的行业标准'
  },
  {
    id: '3',
    name: '生鲜乳质量安全检测标准',
    type: 'national',
    standardNumber: 'GB 19301-2010',
    releaseDate: '2010-03-26',
    implementDate: '2010-12-01',
    content: '规定了生鲜乳的质量安全要求、检测方法、检验规则和标识、包装、运输、贮存等内容',
    description: '生鲜乳质量安全的国家标准'
  }
])

// 检疫标准表格列定义
const quarantineStandardsColumns = [
  {
    title: '标准名称',
    dataIndex: 'name',
    key: 'name'
  },
  {
    title: '标准类型',
    dataIndex: 'type',
    key: 'type',
    width: 100,
    customRender: ({ text }) => getStandardTypeText(text)
  },
  {
    title: '标准编号',
    dataIndex: 'standardNumber',
    key: 'standardNumber',
    width: 150
  },
  {
    title: '实施日期',
    dataIndex: 'implementDate',
    key: 'implementDate',
    width: 120
  },
  {
    title: '描述',
    dataIndex: 'description',
    key: 'description',
    ellipsis: true
  },
  {
    title: '操作',
    key: 'action',
    width: 180,
    scopedSlots: { customRender: 'action' }
  }
]

// 检疫类型配置相关变量
const quarantineTypesSearchKeyword = ref('')
const quarantineTypesSelectedRowKeys = ref([])
const isQuarantineTypesModalOpen = ref(false)
const isEditingQuarantineType = ref(false)
const currentQuarantineType = reactive({
  id: '',
  name: '',
  code: '',
  description: ''
})

// 检疫类型分页配置
const quarantineTypesPagination = reactive({
  current: 1,
  pageSize: 10,
  total: 0,
  showSizeChanger: true,
  showQuickJumper: true,
  showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，共 ${total} 条`
})

// 检疫类型数据（模拟数据）
const quarantineTypesData = ref([
  {
    id: '1',
    name: '动物检疫',
    code: 'animal',
    description: '对活体动物进行的检疫活动'
  },
  {
    id: '2',
    name: '动物产品检疫',
    code: 'product',
    description: '对动物产品进行的检疫活动'
  },
  {
    id: '3',
    name: '运输检疫',
    code: 'transport',
    description: '对运输中的动物进行的检疫活动'
  },
  {
    id: '4',
    name: '屠宰检疫',
    code: 'slaughter',
    description: '对屠宰过程中的动物进行的检疫活动'
  },
  {
    id: '5',
    name: '其他检疫',
    code: 'other',
    description: '其他类型的检疫活动'
  }
])

// 检疫类型表格列定义
const quarantineTypesColumns = [
  {
    title: '类型名称',
    dataIndex: 'name',
    key: 'name'
  },
  {
    title: '类型代码',
    dataIndex: 'code',
    key: 'code',
    width: 120
  },
  {
    title: '描述',
    dataIndex: 'description',
    key: 'description',
    ellipsis: true
  },
  {
    title: '操作',
    key: 'action',
    width: 150,
    scopedSlots: { customRender: 'action' }
  }
]

// 检疫人员配置相关变量
const quarantinePersonnelSearchKeyword = ref('')
const quarantinePersonnelTypeFilter = ref('')
const quarantinePersonnelSelectedRowKeys = ref([])
const isQuarantinePersonnelModalOpen = ref(false)
const isEditingQuarantinePersonnel = ref(false)
const currentQuarantinePersonnel = reactive({
  id: '',
  name: '',
  department: 'animalHealth',
  position: '',
  phone: '',
  email: '',
  qualification: '',
  description: ''
})

// 检疫人员分页配置
const quarantinePersonnelPagination = reactive({
  current: 1,
  pageSize: 10,
  total: 0,
  showSizeChanger: true,
  showQuickJumper: true,
  showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，共 ${total} 条`
})

// 检疫人员数据（模拟数据）
const quarantinePersonnelData = ref([
  {
    id: '1',
    name: '张三',
    department: 'animalHealth',
    position: '检疫员',
    phone: '13812345678',
    email: 'zhangsan@example.com',
    qualification: '高级兽医师',
    description: '从事动物检疫工作10年，经验丰富'
  },
  {
    id: '2',
    name: '李四',
    department: 'quarantineStation',
    position: '检疫主管',
    phone: '13912345678',
    email: 'lisi@example.com',
    qualification: '兽医师',
    description: '负责检疫站日常管理工作'
  },
  {
    id: '3',
    name: '王五',
    department: 'veterinaryStation',
    position: '兽医',
    phone: '13712345678',
    email: 'wangwu@example.com',
    qualification: '兽医师',
    description: '从事兽医临床工作5年'
  },
  {
    id: '4',
    name: '赵六',
    department: 'animalHealth',
    position: '检疫员',
    phone: '13612345678',
    email: 'zhaoliu@example.com',
    qualification: '助理兽医师',
    description: '从事动物检疫工作3年'
  }
])

// 检疫人员表格列定义
const quarantinePersonnelColumns = [
  {
    title: '姓名',
    dataIndex: 'name',
    key: 'name'
  },
  {
    title: '所属部门',
    dataIndex: 'department',
    key: 'department',
    width: 150,
    customRender: ({ text }) => getDepartmentText(text)
  },
  {
    title: '职位',
    dataIndex: 'position',
    key: 'position',
    width: 100
  },
  {
    title: '联系电话',
    dataIndex: 'phone',
    key: 'phone',
    width: 120
  },
  {
    title: '资格证书',
    dataIndex: 'qualification',
    key: 'qualification',
    width: 120
  },
  {
    title: '描述',
    dataIndex: 'description',
    key: 'description',
    ellipsis: true
  },
  {
    title: '操作',
    key: 'action',
    width: 180,
    scopedSlots: { customRender: 'action' }
  }
]

// 获取类型文本
const getTypeText = (type) => {
  const typeMap = {
    animal: '动物检疫',
    product: '动物产品检疫',
    transport: '运输检疫',
    slaughter: '屠宰检疫',
    other: '其他检疫'
  }
  return typeMap[type] || type
}

// 获取标准类型文本
const getStandardTypeText = (type) => {
  const typeMap = {
    national: '国家标准',
    industry: '行业标准',
    local: '地方标准',
    enterprise: '企业标准'
  }
  return typeMap[type] || type
}

// 获取部门文本
const getDepartmentText = (department) => {
  const departmentMap = {
    animalHealth: '动物卫生监督所',
    quarantineStation: '检疫站',
    veterinaryStation: '兽医站',
    other: '其他部门'
  }
  return departmentMap[department] || department
}

// 配置类型切换
const handleConfigTypeChange = (e) => {
  currentConfigType.value = e.target.value
  // 重置当前配置类型的搜索条件和分页
  switch (currentConfigType.value) {
    case 'quarantineItems':
      quarantineItemsSearchKeyword.value = ''
      quarantineItemsTypeFilter.value = ''
      quarantineItemsPagination.current = 1
      break
    case 'quarantineProcesses':
      quarantineProcessesSearchKeyword.value = ''
      quarantineProcessesTypeFilter.value = ''
      quarantineProcessesPagination.current = 1
      break
    case 'quarantineStandards':
      quarantineStandardsSearchKeyword.value = ''
      quarantineStandardsTypeFilter.value = ''
      quarantineStandardsPagination.current = 1
      break
    case 'quarantineTypes':
      quarantineTypesSearchKeyword.value = ''
      quarantineTypesPagination.current = 1
      break
    case 'quarantinePersonnel':
      quarantinePersonnelSearchKeyword.value = ''
      quarantinePersonnelTypeFilter.value = ''
      quarantinePersonnelPagination.current = 1
      break
  }
}

// 检疫项目相关方法
const onQuarantineItemsSelectChange = (newSelectedRowKeys) => {
  quarantineItemsSelectedRowKeys.value = newSelectedRowKeys
}

const handleQuarantineItemsSearch = () => {
  // 在实际应用中，这里应该调用API获取数据
  quarantineItemsPagination.current = 1
  // 模拟搜索效果
  message.success('搜索成功')
}

const handleQuarantineItemsReset = () => {
  quarantineItemsSearchKeyword.value = ''
  quarantineItemsTypeFilter.value = ''
  quarantineItemsPagination.current = 1
}

const handleAddQuarantineItem = () => {
  // 重置表单
  Object.assign(currentQuarantineItem, {
    id: '',
    name: '',
    applicableType: 'animal',
    standard: '',
    description: ''
  })
  isEditingQuarantineItem.value = false
  isQuarantineItemsModalOpen.value = true
}

const handleEditQuarantineItem = (record) => {
  // 复制记录到当前编辑对象
  Object.assign(currentQuarantineItem, { ...record })
  isEditingQuarantineItem.value = true
  isQuarantineItemsModalOpen.value = true
}

const handleDeleteQuarantineItem = (id) => {
  // 在实际应用中，这里应该调用API删除数据
  const index = quarantineItemsData.value.findIndex(item => item.id === id)
  if (index !== -1) {
    quarantineItemsData.value.splice(index, 1)
    message.success('删除成功')
  }
}

const handleQuarantineItemsSave = () => {
  // 在实际应用中，这里应该调用API保存数据
  if (isEditingQuarantineItem.value) {
    // 更新现有项目
    const index = quarantineItemsData.value.findIndex(item => item.id === currentQuarantineItem.id)
    if (index !== -1) {
      quarantineItemsData.value[index] = { ...currentQuarantineItem }
    }
  } else {
    // 添加新项目
    const newItem = {
      ...currentQuarantineItem,
      id: Date.now().toString()
    }
    quarantineItemsData.value.unshift(newItem)
  }
  isQuarantineItemsModalOpen.value = false
  message.success(isEditingQuarantineItem.value ? '更新成功' : '新增成功')
}

const handleQuarantineItemsCancel = () => {
  isQuarantineItemsModalOpen.value = false
}

// 检疫流程相关方法
const onQuarantineProcessesSelectChange = (newSelectedRowKeys) => {
  quarantineProcessesSelectedRowKeys.value = newSelectedRowKeys
}

const handleQuarantineProcessesSearch = () => {
  // 在实际应用中，这里应该调用API获取数据
  quarantineProcessesPagination.current = 1
  // 模拟搜索效果
  message.success('搜索成功')
}

const handleQuarantineProcessesReset = () => {
  quarantineProcessesSearchKeyword.value = ''
  quarantineProcessesTypeFilter.value = ''
  quarantineProcessesPagination.current = 1
}

const handleAddQuarantineProcess = () => {
  // 在实际应用中，这里应该打开新增流程模态框
  message.success('新增流程功能待实现')
}

const handleEditQuarantineProcess = (record) => {
  // 在实际应用中，这里应该打开编辑流程模态框
  message.success('编辑流程功能待实现')
}

const handleProcessSteps = (record) => {
  // 在实际应用中，这里应该打开步骤管理模态框
  message.success('步骤管理功能待实现')
}

const handleDeleteQuarantineProcess = (id) => {
  // 在实际应用中，这里应该调用API删除数据
  const index = quarantineProcessesData.value.findIndex(item => item.id === id)
  if (index !== -1) {
    quarantineProcessesData.value.splice(index, 1)
    message.success('删除成功')
  }
}

// 检疫标准相关方法
const onQuarantineStandardsSelectChange = (newSelectedRowKeys) => {
  quarantineStandardsSelectedRowKeys.value = newSelectedRowKeys
}

const handleQuarantineStandardsSearch = () => {
  // 在实际应用中，这里应该调用API获取数据
  quarantineStandardsPagination.current = 1
  // 模拟搜索效果
  message.success('搜索成功')
}

const handleQuarantineStandardsReset = () => {
  quarantineStandardsSearchKeyword.value = ''
  quarantineStandardsTypeFilter.value = ''
  quarantineStandardsPagination.current = 1
}

const handleAddQuarantineStandard = () => {
  // 在实际应用中，这里应该打开新增标准模态框
  message.success('新增标准功能待实现')
}

const handleEditQuarantineStandard = (record) => {
  // 在实际应用中，这里应该打开编辑标准模态框
  message.success('编辑标准功能待实现')
}

const handleViewQuarantineStandard = (record) => {
  // 在实际应用中，这里应该打开查看标准模态框
  message.success('查看标准功能待实现')
}

const handleDeleteQuarantineStandard = (id) => {
  // 在实际应用中，这里应该调用API删除数据
  const index = quarantineStandardsData.value.findIndex(item => item.id === id)
  if (index !== -1) {
    quarantineStandardsData.value.splice(index, 1)
    message.success('删除成功')
  }
}

// 检疫类型相关方法
const onQuarantineTypesSelectChange = (newSelectedRowKeys) => {
  quarantineTypesSelectedRowKeys.value = newSelectedRowKeys
}

const handleQuarantineTypesSearch = () => {
  // 在实际应用中，这里应该调用API获取数据
  quarantineTypesPagination.current = 1
  // 模拟搜索效果
  message.success('搜索成功')
}

const handleQuarantineTypesReset = () => {
  quarantineTypesSearchKeyword.value = ''
  quarantineTypesPagination.current = 1
}

const handleAddQuarantineType = () => {
  // 在实际应用中，这里应该打开新增类型模态框
  message.success('新增类型功能待实现')
}

const handleEditQuarantineType = (record) => {
  // 在实际应用中，这里应该打开编辑类型模态框
  message.success('编辑类型功能待实现')
}

const handleDeleteQuarantineType = (id) => {
  // 在实际应用中，这里应该调用API删除数据
  const index = quarantineTypesData.value.findIndex(item => item.id === id)
  if (index !== -1) {
    quarantineTypesData.value.splice(index, 1)
    message.success('删除成功')
  }
}

// 检疫人员相关方法
const onQuarantinePersonnelSelectChange = (newSelectedRowKeys) => {
  quarantinePersonnelSelectedRowKeys.value = newSelectedRowKeys
}

const handleQuarantinePersonnelSearch = () => {
  // 在实际应用中，这里应该调用API获取数据
  quarantinePersonnelPagination.current = 1
  // 模拟搜索效果
  message.success('搜索成功')
}

const handleQuarantinePersonnelReset = () => {
  quarantinePersonnelSearchKeyword.value = ''
  quarantinePersonnelTypeFilter.value = ''
  quarantinePersonnelPagination.current = 1
}

const handleAddQuarantinePersonnel = () => {
  // 在实际应用中，这里应该打开新增人员模态框
  message.success('新增人员功能待实现')
}

const handleEditQuarantinePersonnel = (record) => {
  // 在实际应用中，这里应该打开编辑人员模态框
  message.success('编辑人员功能待实现')
}

const handleViewQuarantinePersonnel = (record) => {
  // 在实际应用中，这里应该打开查看人员模态框
  message.success('查看人员功能待实现')
}

const handleDeleteQuarantinePersonnel = (id) => {
  // 在实际应用中，这里应该调用API删除数据
  const index = quarantinePersonnelData.value.findIndex(item => item.id === id)
  if (index !== -1) {
    quarantinePersonnelData.value.splice(index, 1)
    message.success('删除成功')
  }
}
</script>

<style scoped>
  h1 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    color: #333;
  }
</style>