feat(web-admin): add inspection item template list page.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-17 12:47:00 +08:00
1 parent e80dcd8519
commit 4a1444526a
1 file changed
+423
@@ -0,0 +1,423 @@
<!-- 质检基础信息 — 检测项目模版 -->
<!-- eslint-disable vue/no-v-model-argument -->
<template>
<div class="page-container">
<section class="panel">
<div class="panel-top">
<h2 class="title-bar-heading">检测项目模版列表</h2>
</div>
<div class="filter-block">
<el-form :model="searchForm" class="filter-form" @submit.prevent>
<div class="filter-grid">
<el-form-item label="模版名称">
<el-input v-model="searchForm.keyword" placeholder="模版名称" clearable />
</el-form-item>
<el-form-item label="状态">
<el-select
v-model="searchForm.status"
placeholder="全部"
clearable
style="width: 100%"
>
<el-option label="启用" value="1" />
<el-option label="停用" value="0" />
</el-select>
</el-form-item>
</div>
<div class="filter-actions-row">
<div class="filter-actions-end">
<el-button class="btn-ghost" @click="handleReset">
<el-icon><RefreshLeft /></el-icon>重置
</el-button>
<el-button class="btn-main" type="primary" @click="handleSearch">
<el-icon><Search /></el-icon>搜索
</el-button>
</div>
</div>
</el-form>
</div>
<div class="list-toolbar">
<div class="list-toolbar-row">
<el-button
v-if="canAdd"
class="btn-main"
type="primary"
@click="handleAdd"
>
<el-icon><Plus /></el-icon>新增模版
</el-button>
</div>
</div>
<div class="list-body list-wrap">
<el-table class="list-table" :data="tableData" v-loading="loading" stripe row-key="id">
<el-table-column
type="index"
label="序号"
min-width="68"
align="center"
header-align="center"
:index="(index) => (pagination.page - 1) * pagination.pageSize + index + 1"
/>
<el-table-column
prop="templateName"
label="模版名称"
min-width="180"
align="center"
header-align="center"
show-overflow-tooltip
/>
<el-table-column
prop="labItemCount"
label="实验室项目数"
min-width="120"
align="center"
header-align="center"
/>
<el-table-column
prop="thirdPartyItemCount"
label="第三方项目数"
min-width="120"
align="center"
header-align="center"
/>
<el-table-column
prop="status"
label="状态"
min-width="90"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-tag :type="row.status === '1' ? 'success' : 'info'" size="small">
{{ row.status === '1' ? '启用' : '停用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column
prop="createTime"
label="创建时间"
min-width="170"
align="center"
header-align="center"
>
<template #default="{ row }">{{ formatDisplayOrDash(row.createTime) }}</template>
</el-table-column>
<el-table-column
label="操作"
min-width="280"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-button v-if="canEdit" class="btn-op-item primary" @click="handleEdit(row)">
<el-icon><Edit /></el-icon>编辑
</el-button>
<el-button v-if="canEdit" class="btn-op-item" @click="handleToggleStatus(row)">
<el-icon><Switch /></el-icon>{{ row.status === '1' ? '停用' : '启用' }}
</el-button>
<el-button v-if="canRemove" class="btn-op-item" @click="handleDelete(row)">
<el-icon><Delete /></el-icon>删除
</el-button>
</template>
</el-table-column>
</el-table>
<div class="pagination list-pager-bar">
<el-pagination
:current-page="pagination.page"
:page-size="pagination.pageSize"
:total="pagination.total"
:page-sizes="[10, 20, 50]"
layout="total, sizes, prev, pager, next"
@size-change="(val) => ((pagination.page = 1), (pagination.pageSize = val), loadData())"
@current-change="(val) => ((pagination.page = val), loadData())"
/>
</div>
</div>
<el-dialog
v-model="dialogVisible"
:title="dialogTitle"
width="720px"
class="dialog-form-layout"
align-center
append-to-body
modal-class="protocol-dialog-mask"
destroy-on-close
:close-on-click-modal="false"
>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-position="top"
class="biz-dialog-form"
scroll-to-error
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
>
<div class="form-grid-2">
<el-form-item label="模版名称" prop="templateName">
<el-input v-model="formData.templateName" placeholder="请输入模版名称" maxlength="200" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio value="1">启用</el-radio>
<el-radio value="0">停用</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="实验室自检项目" class="form-col-span-2" prop="labItemIds">
<el-checkbox-group v-model="formData.labItemIds" class="qc-config-check-group">
<el-checkbox v-for="item in labOptions" :key="item.id" :value="item.id">
{{ item.itemName }}
</el-checkbox>
</el-checkbox-group>
<p v-if="!labOptions.length" class="hint-muted">暂无启用的实验室项目</p>
</el-form-item>
<el-form-item label="第三方检测项目" class="form-col-span-2" prop="thirdPartyItemIds">
<div v-for="group in thirdGroups" :key="group.companyId" class="tpl-third-group">
<div class="tpl-third-group__name">{{ group.companyName || '未命名公司' }}</div>
<el-checkbox-group v-model="formData.thirdPartyItemIds" class="qc-config-check-group">
<el-checkbox v-for="item in group.items" :key="item.id" :value="item.id">
{{ item.itemName }}
</el-checkbox>
</el-checkbox-group>
</div>
<p v-if="!thirdGroups.length" class="hint-muted">暂无启用的第三方项目</p>
</el-form-item>
<el-form-item label="备注" class="form-col-span-2">
<el-input v-model="formData.remark" type="textarea" :rows="2" placeholder="可选" />
</el-form-item>
</div>
</el-form>
<template #footer>
<el-button class="btn-ghost" @click="dialogVisible = false">
<el-icon><Close /></el-icon>取消
</el-button>
<el-button class="btn-main" type="primary" :loading="submitLoading" @click="handleSubmit">
<el-icon><Check /></el-icon>确定
</el-button>
</template>
</el-dialog>
</section>
</div>
</template>
<script setup lang="ts">
import { formatDisplayOrDash } from '@/utils/datetime-display'
import { ref, reactive, computed, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
Plus,
Close,
Check,
Search,
RefreshLeft,
Edit,
Delete,
Switch
} from '@element-plus/icons-vue'
import { useMenuPerm } from '@/hooks/core/useMenuPerm'
import { fetchQcLabTestItemsActive, type QcLabTestItem } from '@/api/qc-lab-test-item'
import { fetchQcThirdPartyItemsActive, type QcThirdPartyItem } from '@/api/qc-third-party-item'
import {
fetchQcInspectionItemTemplateList,
fetchCreateQcInspectionItemTemplate,
fetchUpdateQcInspectionItemTemplate,
fetchDeleteQcInspectionItemTemplate,
type QcInspectionItemTemplate
} from '@/api/qc-inspection-item-template'
defineOptions({ name: 'QualityInspectionInspectionItemTemplate' })
const { hasMenuPerm } = useMenuPerm()
const canAdd = computed(() => hasMenuPerm('biz:qcInspectionItemTemplate:add'))
const canEdit = computed(() => hasMenuPerm('biz:qcInspectionItemTemplate:edit'))
const canRemove = computed(() => hasMenuPerm('biz:qcInspectionItemTemplate:remove'))
const searchForm = reactive({ keyword: '', status: '' as string })
const tableData = ref<QcInspectionItemTemplate[]>([])
const loading = ref(false)
const pagination = reactive({ page: 1, pageSize: 10, total: 0 })
const dialogVisible = ref(false)
const dialogTitle = ref('新增模版')
const isEdit = ref(false)
const submitLoading = ref(false)
const formRef = ref()
const editingId = ref<string | null>(null)
const labOptions = ref<QcLabTestItem[]>([])
const thirdOptions = ref<QcThirdPartyItem[]>([])
const thirdGroups = computed(() => {
const map = new Map<string, { companyId: string; companyName: string; items: QcThirdPartyItem[] }>()
for (const item of thirdOptions.value) {
const cid = item.companyId || ''
if (!map.has(cid)) {
map.set(cid, {
companyId: cid,
companyName: item.companyName || '未命名公司',
items: []
})
}
map.get(cid)!.items.push(item)
}
return Array.from(map.values())
})
const formData = reactive({
templateName: '',
status: '1',
labItemIds: [] as string[],
thirdPartyItemIds: [] as string[],
remark: ''
})
const validateItems = (_rule: unknown, _value: unknown, callback: (e?: Error) => void) => {
if (!formData.labItemIds.length && !formData.thirdPartyItemIds.length) {
callback(new Error('请至少选择一个检测项目'))
return
}
callback()
}
const formRules = {
templateName: [{ required: true, message: '请输入模版名称', trigger: 'blur' }],
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
labItemIds: [{ validator: validateItems, trigger: 'change' }],
thirdPartyItemIds: [{ validator: validateItems, trigger: 'change' }]
}
async function loadItemOptions() {
const [lab, third] = await Promise.all([
fetchQcLabTestItemsActive(),
fetchQcThirdPartyItemsActive()
])
labOptions.value = lab || []
thirdOptions.value = third || []
}
async function loadData() {
loading.value = true
try {
const res = await fetchQcInspectionItemTemplateList({
page: pagination.page,
pageSize: pagination.pageSize,
keyword: searchForm.keyword || undefined,
status: searchForm.status || undefined
})
tableData.value = res.list || []
pagination.total = res.total ?? 0
} finally {
loading.value = false
}
}
function handleSearch() {
pagination.page = 1
loadData()
}
function handleReset() {
searchForm.keyword = ''
searchForm.status = ''
pagination.page = 1
loadData()
}
function resetForm() {
formData.templateName = ''
formData.status = '1'
formData.labItemIds = []
formData.thirdPartyItemIds = []
formData.remark = ''
editingId.value = null
}
async function handleAdd() {
isEdit.value = false
dialogTitle.value = '新增模版'
resetForm()
await loadItemOptions()
dialogVisible.value = true
}
async function handleEdit(row: QcInspectionItemTemplate) {
isEdit.value = true
dialogTitle.value = '编辑模版'
editingId.value = row.id
formData.templateName = row.templateName
formData.status = row.status || '1'
formData.labItemIds = [...(row.labItemIds || [])]
formData.thirdPartyItemIds = [...(row.thirdPartyItemIds || [])]
formData.remark = row.remark || ''
await loadItemOptions()
dialogVisible.value = true
}
async function handleSubmit() {
const valid = await formRef.value?.validate?.().catch(() => false)
if (!valid) return
submitLoading.value = true
try {
const payload = {
templateName: formData.templateName.trim(),
status: formData.status,
labItemIds: formData.labItemIds,
thirdPartyItemIds: formData.thirdPartyItemIds,
remark: formData.remark || undefined
}
if (isEdit.value && editingId.value) {
await fetchUpdateQcInspectionItemTemplate(editingId.value, payload)
ElMessage.success('已保存')
} else {
await fetchCreateQcInspectionItemTemplate(payload)
ElMessage.success('已新增')
}
dialogVisible.value = false
loadData()
} finally {
submitLoading.value = false
}
}
async function handleToggleStatus(row: QcInspectionItemTemplate) {
const next = row.status === '1' ? '0' : '1'
const tip = next === '1' ? '启用' : '停用'
await ElMessageBox.confirm(`确定${tip}模版「${row.templateName}」?`, '提示', {
type: 'warning'
})
await fetchUpdateQcInspectionItemTemplate(row.id, { status: next })
ElMessage.success(`已${tip}`)
loadData()
}
async function handleDelete(row: QcInspectionItemTemplate) {
await ElMessageBox.confirm(`确定删除模版「${row.templateName}」?`, '提示', { type: 'warning' })
await fetchDeleteQcInspectionItemTemplate(row.id)
ElMessage.success('已删除')
loadData()
}
onMounted(() => loadData())
</script>
<style scoped lang="scss">
.tpl-third-group {
margin-bottom: 10px;
&__name {
margin-bottom: 6px;
font-size: 13px;
font-weight: 600;
color: var(--mint-text, #1e293b);
}
}
.hint-muted {
margin: 0;
font-size: 12px;
color: var(--mint-text-muted, #94a3b8);
}
</style>