Files
zkxw/web-admin/src/views/pilot-service/pilot-application/ContractProcessingCategoryDialog.vue
T
cykjandCursor c22a0d1eb0 feat(market): 完善临床科研与委托加工上线能力
补齐项目组负责人审批、费用信息、合作客户、生产出库菜单、申请单号 LCKY 前缀及配套 SQL 迁移,并同步相关前后端与单测。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-30 18:51:37 +08:00

299 lines
8.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- 委托加工 · 维护业务类型 -->
<!-- eslint-disable vue/no-v-model-argument -->
<template>
<el-dialog
:model-value="modelValue"
title="维护业务类型"
width="720px"
class="dialog-form-layout"
align-center
append-to-body
modal-class="protocol-dialog-mask"
destroy-on-close
:close-on-click-modal="false"
@open="handleOpen"
@update:model-value="emit('update:modelValue', $event)"
>
<div class="list-toolbar" style="margin-bottom: 12px">
<div class="list-toolbar-row">
<div class="list-toolbar-selected">
预置 {{ fixedOptions.length }} 项不可删;自定义类型会出现在申请单下拉中
</div>
<el-button class="btn-main" type="primary" @click="openEdit()">
<el-icon><Plus /></el-icon>
新增自定义
</el-button>
</div>
</div>
<el-table v-loading="loading" :data="tableRows" class="list-table" stripe max-height="420">
<el-table-column
type="index"
label="序号"
min-width="56"
align="center"
header-align="center"
/>
<el-table-column
label="来源"
min-width="88"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-tag size="small" :type="row.fixed ? 'info' : 'success'">
{{ row.fixed ? '预置' : '自定义' }}
</el-tag>
</template>
</el-table-column>
<el-table-column
label="业务类型"
prop="label"
min-width="200"
align="center"
header-align="center"
show-overflow-tooltip
/>
<el-table-column
label="操作"
min-width="180"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ row }">
<div v-if="!row.fixed" style="display: flex; justify-content: center; gap: 8px">
<el-button class="btn-op-item" @click="openEdit(row)">
<el-icon><Edit /></el-icon>编辑
</el-button>
<el-button class="btn-op-item" @click="handleDelete(row)">
<el-icon><Delete /></el-icon>删除
</el-button>
</div>
<span v-else class="form-tip">—</span>
</template>
</el-table-column>
</el-table>
<template #footer>
<el-button @click="emit('update:modelValue', false)">
<el-icon><Close /></el-icon>关闭
</el-button>
</template>
</el-dialog>
<el-dialog
v-model="editVisible"
:title="editId ? '编辑自定义业务类型' : '新增自定义业务类型'"
width="480px"
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="editFormRef"
:model="editForm"
:rules="editRules"
label-position="top"
class="protocol-form"
>
<el-form-item label="业务类型名称" prop="categoryName">
<el-input
v-model="editForm.categoryName"
maxlength="64"
show-word-limit
placeholder="请输入业务类型名称"
/>
</el-form-item>
<el-form-item label="备注">
<el-input
v-model="editForm.remark"
type="textarea"
:rows="2"
maxlength="200"
show-word-limit
placeholder="选填"
/>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="editVisible = false">
<el-icon><Close /></el-icon>取消
</el-button>
<el-button type="primary" :loading="saving" @click="handleSave">
<el-icon><Check /></el-icon>确定
</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { Check, Close, Delete, Edit, Plus } from '@element-plus/icons-vue'
import type { FormInstance, FormRules } from 'element-plus'
import {
fetchContractProcessingCategoryList,
fetchCreateContractProcessingCategory,
fetchDeleteContractProcessingCategory,
fetchUpdateContractProcessingCategory
} from '@/api/admin'
import {
CLINICAL_RESEARCH_CATEGORY_OPTIONS,
CONTRACT_PROCESSING_CATEGORY_OPTIONS
} from '@/constants/clinical-research-category'
import { fetchAllPagedRecords } from '@/utils/fetch-paged-list'
defineOptions({ name: 'ContractProcessingCategoryDialog' })
const props = withDefaults(
defineProps<{
modelValue: boolean
bizType?: 'basic_experiment' | 'contract_processing'
}>(),
{ bizType: 'contract_processing' }
)
const emit = defineEmits<{
(e: 'update:modelValue', val: boolean): void
(e: 'changed'): void
}>()
type Row = {
id: string
label: string
fixed: boolean
remark?: string
}
const loading = ref(false)
const customItems = ref<Api.ContractProcessingCategory.Item[]>([])
const fixedOptions = computed(() =>
props.bizType === 'basic_experiment'
? CLINICAL_RESEARCH_CATEGORY_OPTIONS
: CONTRACT_PROCESSING_CATEGORY_OPTIONS
)
const tableRows = computed<Row[]>(() => [
...fixedOptions.value.map((o) => ({
id: `fixed:${o.value}`,
label: o.label,
fixed: true
})),
...customItems.value.map((c) => ({
id: c.id,
label: c.categoryName,
fixed: false,
remark: c.remark
}))
])
const editVisible = ref(false)
const editId = ref('')
const saving = ref(false)
const editFormRef = ref<FormInstance>()
const editForm = reactive({ categoryName: '', remark: '' })
const editRules: FormRules = {
categoryName: [{ required: true, message: '请输入业务类型名称', trigger: 'blur' }]
}
async function loadList() {
loading.value = true
customItems.value = []
const bizType = props.bizType
try {
const rows = await fetchAllPagedRecords((page, pageSize) =>
fetchContractProcessingCategoryList({ page, pageSize, bizType })
)
// 必须带 bizType;缺字段的旧响应直接丢弃,避免串业务线
customItems.value = rows.filter((r) => r.bizType === bizType)
} catch (e) {
console.error(e)
customItems.value = []
ElMessage.error('加载业务类型失败')
} finally {
loading.value = false
}
}
function handleOpen() {
loadList()
}
watch(
() => props.bizType,
() => {
customItems.value = []
if (props.modelValue) loadList()
}
)
function openEdit(row?: Row) {
if (row?.fixed) return
editId.value = row?.id || ''
editForm.categoryName = row?.label || ''
editForm.remark = row?.remark || ''
editVisible.value = true
}
async function handleSave() {
try {
await editFormRef.value?.validate()
} catch {
return
}
saving.value = true
try {
const payload = {
categoryName: editForm.categoryName.trim(),
remark: editForm.remark.trim() || undefined
}
if (editId.value) {
await fetchUpdateContractProcessingCategory(editId.value, payload)
ElMessage.success('已更新')
} else {
await fetchCreateContractProcessingCategory({
...payload,
bizType: props.bizType
})
ElMessage.success('已新增')
}
editVisible.value = false
await loadList()
emit('changed')
} catch (e: any) {
ElMessage.error(e?.message || '保存失败')
} finally {
saving.value = false
}
}
async function handleDelete(row: Row) {
if (row.fixed) return
try {
await ElMessageBox.confirm(`确定删除业务类型「${row.label}」?`, '提示', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
} catch {
return
}
try {
await fetchDeleteContractProcessingCategory(row.id)
ElMessage.success('已删除')
await loadList()
emit('changed')
} catch (e: any) {
ElMessage.error(e?.message || '删除失败')
}
}
watch(
() => props.modelValue,
(v) => {
if (!v) editVisible.value = false
}
)
</script>