548 lines
15 KiB
Plaintext
548 lines
15 KiB
Plaintext
<template>
|
|
<div class="fa-full-height">
|
|
<FaSearchBar
|
|
v-show="showSearchBar"
|
|
ref="searchBarRef"
|
|
v-model="searchForm"
|
|
:items="TrialStudySearchItems"
|
|
:rules="searchBarRules"
|
|
:is-expand="false"
|
|
:show-expand="true"
|
|
:show-reset="true"
|
|
:show-search="true"
|
|
:disabled-search="false"
|
|
:default-expanded="false"
|
|
include-audit
|
|
@search="handleSearch"
|
|
@reset="onResetSearch"
|
|
/>
|
|
|
|
<ElCard class="fa-table-card" :style="{ 'margin-top': showSearchBar ? '12px' : '0' }">
|
|
<FaTableHeader
|
|
v-model:columns="columnChecks"
|
|
v-model:showSearchBar="showSearchBar"
|
|
:loading="loading"
|
|
@refresh="refreshData"
|
|
>
|
|
<template #left>
|
|
<FaTableHeaderLeft
|
|
:remove-ids="selectedIds"
|
|
:perm-create="['module_bre:trial_study:create']"
|
|
:perm-import="['module_bre:trial_study:import']"
|
|
:perm-export="['module_bre:trial_study:export']"
|
|
:perm-delete="['module_bre:trial_study:delete']"
|
|
:delete-loading="batchDeleting"
|
|
:create-loading="createLoading"
|
|
@add="handleAdd"
|
|
@import="openImport"
|
|
@export="openExport"
|
|
@delete="handleBatchDelete"
|
|
/>
|
|
</template>
|
|
</FaTableHeader>
|
|
|
|
<FaTable
|
|
ref="faTableRef"
|
|
:loading="loading"
|
|
:data="data"
|
|
:columns="columns"
|
|
:pagination="pagination"
|
|
@selection-change="onTableSelectionChange"
|
|
@pagination:size-change="handleSizeChange"
|
|
@pagination:current-change="handleCurrentChange"
|
|
/>
|
|
</ElCard>
|
|
|
|
<FaDialog
|
|
v-model="dialogVisible.visible"
|
|
:title="dialogVisible.title"
|
|
width="920px"
|
|
dialog-class="crud-embed-dialog"
|
|
modal-class="crud-embed-dialog"
|
|
:form-mode="dialogVisible.type"
|
|
:confirm-loading="submitLoading"
|
|
:close-on-click-modal="false"
|
|
@cancel="crud.handleCloseDialog"
|
|
@close="crud.handleCloseDialog"
|
|
@confirm="crud.handleSubmit"
|
|
>
|
|
<template v-if="dialogVisible.type === 'detail'">
|
|
<FaDescriptions
|
|
:column="4"
|
|
:data="detailFormData"
|
|
:items="TrialStudyDetailItems"
|
|
max-height="70vh"
|
|
/>
|
|
</template>
|
|
<template v-else>
|
|
<FaForm
|
|
:key="TrialStudyFormRenderKey"
|
|
scrollbar
|
|
max-height="70vh"
|
|
ref="dataFormRef"
|
|
v-model="formData"
|
|
:items="TrialStudyDialogFormItems"
|
|
:rules="rules"
|
|
label-suffix=":"
|
|
:label-width="120"
|
|
label-position="right"
|
|
:span="12"
|
|
:gutter="16"
|
|
:show-reset="false"
|
|
:show-submit="false"
|
|
class="crud-dialog-art-form"
|
|
/>
|
|
</template>
|
|
</FaDialog>
|
|
|
|
<FaImportDialog
|
|
v-model="importVisible"
|
|
:content-config="TrialStudyImportContentConfig"
|
|
default-template-file-name="trial_study_import_template.xlsx"
|
|
@upload="handleCrudImportUpload"
|
|
/>
|
|
|
|
<FaExportDialog
|
|
v-model="exportVisible"
|
|
:content-config="TrialStudyExportContentConfig"
|
|
:query-params="exportQueryParams"
|
|
:page-data="data"
|
|
:selection-data="selectedRows"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { TableOperationAction } from "@/utils/table";
|
|
import { renderTableOperationCell, stripPaginationParams, toCrudCols } from "@utils";
|
|
import { useCrudForm } from "@/hooks/core/useCrudForm";
|
|
import { ResultEnum } from "@/enums/api/result.enum";
|
|
import type { IContentConfig, IObject } from "@/components/modal/types";
|
|
import type { AuditSearchFormParams } from "@/components/forms/fa-search-bar/auditSearchFormItems";
|
|
import type { FormItem } from "@/components/forms/fa-form/index.vue";
|
|
import TrialAPI, { type TrialOption } from "@/api/module_bre/trial";
|
|
import TrialStudyAPI, { type TrialStudyForm, type TrialStudyPageQuery, type TrialStudyTable } from "@/api/module_bre/trial_study";
|
|
import type { ColumnOption } from "@/types/component";
|
|
import FaDescriptions from "@/components/others/fa-descriptions/index.vue";
|
|
import FaForm from "@/components/forms/fa-form/index.vue";
|
|
import FaTableHeader from "@/components/tables/fa-table-header/index.vue";
|
|
|
|
defineOptions({
|
|
name: "TrialStudy",
|
|
inheritAttrs: false,
|
|
});
|
|
|
|
const trialOptions = ref<TrialOption[]>([]);
|
|
|
|
const trialOptionsMap = computed(() => {
|
|
const m: Record<number, string> = {};
|
|
for (const o of trialOptions.value) m[o.value] = o.label;
|
|
return m;
|
|
});
|
|
|
|
async function loadTrialOptions() {
|
|
try {
|
|
const res = await TrialAPI.getTrialOptions();
|
|
if (res.data.code === ResultEnum.SUCCESS) {
|
|
trialOptions.value = res.data.data ?? [];
|
|
}
|
|
} catch (error: unknown) {
|
|
if (import.meta.env.DEV) console.error("[TrialStudy] loadTrialOptions", error);
|
|
}
|
|
}
|
|
|
|
const createInitialFormData = (): TrialStudyForm => ({
|
|
id: undefined,
|
|
trial_id: undefined,
|
|
study_name: undefined,
|
|
site_id: undefined,
|
|
year: undefined,
|
|
block_count: undefined,
|
|
design_type: undefined,
|
|
remark: undefined,
|
|
});
|
|
|
|
type TrialStudySearchFormParams = {
|
|
trial_id?: number;
|
|
study_name?: string;
|
|
site_id?: number;
|
|
} & AuditSearchFormParams;
|
|
|
|
const searchForm = ref<TrialStudySearchFormParams>({
|
|
trial_id: undefined,
|
|
study_name: undefined,
|
|
site_id: undefined,
|
|
created_id: undefined,
|
|
updated_id: undefined,
|
|
created_time: [],
|
|
updated_time: [],
|
|
});
|
|
|
|
const showSearchBar = ref(true);
|
|
const searchBarRef = ref<{ validate: () => Promise<boolean> } | null>(null);
|
|
const searchBarRules: Record<string, unknown> = {};
|
|
|
|
const TrialStudySearchItems = computed(() => [
|
|
{
|
|
label: "所属试验",
|
|
key: "trial_id",
|
|
type: "select",
|
|
props: {
|
|
placeholder: "请选择所属试验",
|
|
options: trialOptions.value,
|
|
clearable: true,
|
|
filterable: true,
|
|
},
|
|
span: 8,
|
|
},
|
|
{
|
|
label: "研究点名称",
|
|
key: "study_name",
|
|
type: "input",
|
|
placeholder: "请输入研究点名称",
|
|
clearable: true,
|
|
span: 8,
|
|
},
|
|
{
|
|
label: "基地ID",
|
|
key: "site_id",
|
|
type: "input",
|
|
placeholder: "请输入基地ID",
|
|
clearable: true,
|
|
span: 8,
|
|
},
|
|
]);
|
|
|
|
const faTableRef = ref<{ elTableRef?: { clearSelection: () => void } } | null>(null);
|
|
const { selectedRows, selectedIds, batchDeleting, onTableSelectionChange } = useTableSelection<TrialStudyTable>();
|
|
|
|
const createLoading = ref(false);
|
|
|
|
const {
|
|
columns,
|
|
columnChecks,
|
|
data,
|
|
loading,
|
|
pagination,
|
|
searchParams,
|
|
getData,
|
|
replaceSearchParams,
|
|
resetSearchParams,
|
|
handleSizeChange,
|
|
handleCurrentChange,
|
|
refreshData,
|
|
refreshCreate,
|
|
refreshUpdate,
|
|
refreshRemove,
|
|
} = useTable({
|
|
core: {
|
|
apiFn: TrialStudyAPI.getTrialStudyList,
|
|
apiParams: {
|
|
page_no: 1,
|
|
page_size: 10,
|
|
},
|
|
columnsFactory: (): ColumnOption<TrialStudyTable>[] => [
|
|
{ type: "globalIndex", width: 56, label: "序号" },
|
|
{ type: "selection", width: 48, fixed: "left" },
|
|
{ prop: "trial_name", label: "所属试验", minWidth: 140, showOverflowTooltip: true },
|
|
{ prop: "study_name", label: "研究点名称", minWidth: 140, showOverflowTooltip: true },
|
|
{ prop: "site_id", label: "基地ID", minWidth: 100 },
|
|
{ prop: "year", label: "年份", minWidth: 100 },
|
|
{ prop: "block_count", label: "区组数", minWidth: 100 },
|
|
{ prop: "design_type", label: "设计类型", minWidth: 140, showOverflowTooltip: true },
|
|
{
|
|
prop: "created_time",
|
|
label: "创建时间",
|
|
width: 168,
|
|
sortable: true,
|
|
showOverflowTooltip: true,
|
|
},
|
|
{
|
|
prop: "updated_time",
|
|
label: "更新时间",
|
|
width: 168,
|
|
sortable: true,
|
|
showOverflowTooltip: true,
|
|
},
|
|
{
|
|
prop: "created_by",
|
|
label: "创建人",
|
|
minWidth: 100,
|
|
formatter: (row: TrialStudyTable) => row.created_by?.name ?? "—",
|
|
},
|
|
{
|
|
prop: "updated_by",
|
|
label: "更新人",
|
|
minWidth: 100,
|
|
formatter: (row: TrialStudyTable) => row.updated_by?.name ?? "—",
|
|
},
|
|
{
|
|
prop: "operation",
|
|
label: "操作",
|
|
width: 180,
|
|
fixed: "right",
|
|
align: "center",
|
|
formatter: (row: TrialStudyTable) => formatTrialStudyOperationCell(row),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
const TrialStudyCrudCols = toCrudCols(columns);
|
|
|
|
const exportQueryParams = computed(() => {
|
|
return stripPaginationParams(searchParams as Record<string, unknown>);
|
|
});
|
|
|
|
const TrialStudyImportContentConfig = computed<IContentConfig>(() => ({
|
|
permPrefix: "module_bre:trial_study",
|
|
cols: TrialStudyCrudCols.value,
|
|
indexAction: async () => ({}),
|
|
importTemplate: () => TrialStudyAPI.downloadTemplateTrialStudy(),
|
|
}));
|
|
|
|
const TrialStudyExportContentConfig = computed(() => ({
|
|
permPrefix: "module_bre:trial_study",
|
|
cols: TrialStudyCrudCols.value,
|
|
exportsBlobAction: async (params: IObject) => {
|
|
const merged = {
|
|
...(exportQueryParams.value as unknown as Record<string, unknown>),
|
|
...params,
|
|
} as unknown as TrialStudyPageQuery;
|
|
const res = await TrialStudyAPI.exportTrialStudy(merged);
|
|
return res.data as Blob;
|
|
},
|
|
}));
|
|
|
|
const { dialogVisible } = useCrudDialog();
|
|
|
|
const detailFormData = ref<TrialStudyTable>({});
|
|
|
|
const TrialStudyDetailItems: import("@/components/others/fa-descriptions/index.vue").DescriptionsItem[] = [
|
|
{ label: "所属试验", prop: "trial_name" },
|
|
{ label: "研究点名称", prop: "study_name" },
|
|
{ label: "基地ID", prop: "site_id" },
|
|
{ label: "年份", prop: "year" },
|
|
{ label: "区组数", prop: "block_count" },
|
|
{ label: "设计类型", prop: "design_type" },
|
|
{ label: "备注", prop: "remark" },
|
|
{ label: "UUID", prop: "uuid" },
|
|
{ label: "创建人", prop: "created_by.name" },
|
|
{ label: "更新人", prop: "updated_by.name" },
|
|
{ label: "创建时间", prop: "created_time" },
|
|
{ label: "更新时间", prop: "updated_time" },
|
|
];
|
|
|
|
const TrialStudyDialogFormItems = computed<FormItem[]>(() => [
|
|
{
|
|
key: "trial_id",
|
|
label: "所属试验",
|
|
type: "select",
|
|
props: {
|
|
placeholder: "请选择所属试验",
|
|
options: trialOptions.value,
|
|
clearable: true,
|
|
filterable: true,
|
|
},
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "study_name",
|
|
label: "研究点名称",
|
|
type: "input",
|
|
props: { placeholder: "请输入研究点名称", maxlength: 100 },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "site_id",
|
|
label: "基地ID",
|
|
type: "number",
|
|
props: { placeholder: "请输入基地ID" },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "year",
|
|
label: "年份",
|
|
type: "number",
|
|
props: { placeholder: "请输入年份" },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "block_count",
|
|
label: "区组数",
|
|
type: "number",
|
|
props: { placeholder: "请输入区组数" },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "design_type",
|
|
label: "设计类型",
|
|
type: "input",
|
|
props: { placeholder: "请输入设计类型", maxlength: 100 },
|
|
span: 12,
|
|
},
|
|
{
|
|
key: "remark",
|
|
label: "备注",
|
|
type: "input",
|
|
props: { type: "textarea", rows: 3, placeholder: "请输入备注" },
|
|
span: 24,
|
|
},
|
|
]);
|
|
|
|
const formData = ref<TrialStudyForm>(createInitialFormData());
|
|
|
|
const rules = reactive({
|
|
trial_id: [{ required: true, message: "请选择所属试验", trigger: "change" }],
|
|
study_name: [{ required: true, message: "请输入研究点名称", trigger: "blur" }],
|
|
});
|
|
|
|
const dataFormRef = ref<InstanceType<typeof FaForm> | null>(null);
|
|
const TrialStudyFormRenderKey = ref(0);
|
|
|
|
const crud = useCrudForm<TrialStudyForm>({
|
|
formData,
|
|
initialFormData: createInitialFormData(),
|
|
dialogVisible,
|
|
dataFormRef,
|
|
formRenderKey: TrialStudyFormRenderKey,
|
|
detailApi: TrialStudyAPI.getTrialStudyDetail,
|
|
createApi: TrialStudyAPI.createTrialStudy,
|
|
updateApi: TrialStudyAPI.updateTrialStudy,
|
|
titles: { create: "新增试验执行", update: "修改试验执行", detail: "试验执行详情" },
|
|
detailFormData,
|
|
onCreateSuccess: async () => {
|
|
await refreshCreate();
|
|
},
|
|
onUpdateSuccess: async () => {
|
|
await refreshUpdate();
|
|
},
|
|
});
|
|
|
|
const { submitLoading } = crud;
|
|
|
|
const { importVisible, exportVisible, openImport, openExport } = useImportExport();
|
|
|
|
const handleSearch = async (params: TrialStudySearchFormParams) => {
|
|
await searchBarRef.value?.validate();
|
|
replaceSearchParams({
|
|
trial_id: params.trial_id,
|
|
study_name: params.study_name,
|
|
site_id: params.site_id,
|
|
created_id: params.created_id ?? undefined,
|
|
updated_id: params.updated_id ?? undefined,
|
|
created_time:
|
|
Array.isArray(params.created_time) && params.created_time.length === 2
|
|
? params.created_time
|
|
: undefined,
|
|
updated_time:
|
|
Array.isArray(params.updated_time) && params.updated_time.length === 2
|
|
? params.updated_time
|
|
: undefined,
|
|
} as Record<string, unknown>);
|
|
await getData();
|
|
};
|
|
|
|
const onResetSearch = async () => {
|
|
searchForm.value = {
|
|
trial_id: undefined,
|
|
study_name: undefined,
|
|
site_id: undefined,
|
|
created_id: undefined,
|
|
updated_id: undefined,
|
|
created_time: [],
|
|
updated_time: [],
|
|
};
|
|
await resetSearchParams();
|
|
};
|
|
|
|
function buildTrialStudyRowActions(row: TrialStudyTable): TableOperationAction[] {
|
|
const all: TableOperationAction[] = [
|
|
{
|
|
key: "detail",
|
|
label: "详情",
|
|
artType: "view",
|
|
perm: "module_bre:trial_study:detail",
|
|
run: () => void crud.handleOpenDialog("detail", row.id),
|
|
},
|
|
{
|
|
key: "edit",
|
|
label: "编辑",
|
|
artType: "edit",
|
|
icon: "ri:edit-2-line",
|
|
perm: "module_bre:trial_study:update",
|
|
run: () => void crud.handleOpenDialog("update", row.id),
|
|
},
|
|
{
|
|
key: "delete",
|
|
label: "删除",
|
|
artType: "delete",
|
|
icon: "ri:delete-bin-4-line",
|
|
perm: "module_bre:trial_study:delete",
|
|
run: () => deleteTrialStudyRow(row),
|
|
},
|
|
];
|
|
return all;
|
|
}
|
|
|
|
function formatTrialStudyOperationCell(row: TrialStudyTable) {
|
|
return renderTableOperationCell(buildTrialStudyRowActions(row), {
|
|
wrapperClass: "inline-flex flex-wrap items-center justify-end gap-1",
|
|
});
|
|
}
|
|
|
|
async function handleAdd() {
|
|
createLoading.value = true;
|
|
try {
|
|
await crud.handleOpenDialog("create");
|
|
} finally {
|
|
createLoading.value = false;
|
|
}
|
|
}
|
|
|
|
const deleteTrialStudyRow = async (row: TrialStudyTable) => {
|
|
if (!row.id) return;
|
|
try {
|
|
await confirmDelete(`确定删除「${row.study_name ?? row.id}」吗?此操作不可恢复!`);
|
|
await TrialStudyAPI.deleteTrialStudy([row.id!]);
|
|
faTableRef.value?.elTableRef?.clearSelection();
|
|
await refreshRemove();
|
|
} catch {
|
|
// 用户取消
|
|
}
|
|
};
|
|
|
|
async function handleBatchDelete() {
|
|
const ids = selectedIds.value;
|
|
if (ids.length === 0) return;
|
|
try {
|
|
await confirmBatchDelete(ids.length);
|
|
batchDeleting.value = true;
|
|
await TrialStudyAPI.deleteTrialStudy(ids);
|
|
faTableRef.value?.elTableRef?.clearSelection();
|
|
await refreshRemove();
|
|
} catch {
|
|
// 用户取消
|
|
} finally {
|
|
batchDeleting.value = false;
|
|
}
|
|
}
|
|
|
|
async function handleCrudImportUpload(uploadFormData: FormData) {
|
|
try {
|
|
const res = await TrialStudyAPI.importTrialStudy(uploadFormData);
|
|
if (res.data.code === ResultEnum.SUCCESS) {
|
|
ElMessage.success(res.data.msg || "导入成功");
|
|
importVisible.value = false;
|
|
await refreshData();
|
|
}
|
|
} catch (error: unknown) {
|
|
if (import.meta.env.DEV) console.error("[Import]", error);
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
loadTrialOptions();
|
|
});
|
|
</script>
|