|
@@ -1,5 +1,5 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, watch } from 'vue';
|
|
|
+import { computed, ref, watch } from 'vue';
|
|
|
import { message } from 'ant-design-vue';
|
|
|
import { debounce } from 'lodash-es';
|
|
|
|
|
@@ -7,13 +7,14 @@ import SvgIcon from '@/components/SvgIcon.vue';
|
|
|
import { useRequest } from '@/hooks/request';
|
|
|
import { useViewVisible } from '@/hooks/view-visible';
|
|
|
import { t } from '@/i18n';
|
|
|
-import { addProtocolParam, getProtocolStandardParamList } from '@/api';
|
|
|
+import { addProtocolParam, getProtocolStandardParamList, updateProtocolParam } from '@/api';
|
|
|
|
|
|
-import type { Key } from 'ant-design-vue/es/table/interface';
|
|
|
+import type { Key, RowSelectionType } from 'ant-design-vue/es/table/interface';
|
|
|
import type { PageParams, ProtocolStandardParam } from '@/types';
|
|
|
|
|
|
interface Props {
|
|
|
protocolId?: number;
|
|
|
+ paramId?: number;
|
|
|
}
|
|
|
|
|
|
const props = defineProps<Props>();
|
|
@@ -22,6 +23,7 @@ const emit = defineEmits<{
|
|
|
refreshList: [];
|
|
|
}>();
|
|
|
|
|
|
+const isAddParams = ref(true);
|
|
|
const paramList = ref<ProtocolStandardParam[]>([]);
|
|
|
const paramTotal = ref(0);
|
|
|
const paramNameOrCode = ref('');
|
|
@@ -38,6 +40,10 @@ const pageParams = ref<PageParams>({
|
|
|
|
|
|
const { isLoading, handleRequest } = useRequest();
|
|
|
|
|
|
+const setIsAddParams = (isAdd: boolean) => {
|
|
|
+ isAddParams.value = isAdd;
|
|
|
+};
|
|
|
+
|
|
|
const getStandardParams = () => {
|
|
|
handleRequest(async () => {
|
|
|
const { records, total } = await getProtocolStandardParamList({
|
|
@@ -73,6 +79,10 @@ const handlePageChange = (page: number, pageSize: number) => {
|
|
|
const selectedParamIds = ref<number[]>([]);
|
|
|
const selectedParams = ref<ProtocolStandardParam[]>([]);
|
|
|
|
|
|
+const selectionType = computed<RowSelectionType>(() => {
|
|
|
+ return isAddParams.value ? 'checkbox' : 'radio';
|
|
|
+});
|
|
|
+
|
|
|
const handleParamSelectChange = (selectedRowKeys: Key[], selectedRows: ProtocolStandardParam[]) => {
|
|
|
selectedParamIds.value = selectedRowKeys as number[];
|
|
|
selectedParams.value = selectedRows;
|
|
@@ -97,17 +107,24 @@ const handleOk = () => {
|
|
|
}
|
|
|
|
|
|
handleAddParamRequest(async () => {
|
|
|
- for (const item of selectedParams.value) {
|
|
|
- await addProtocolParam({
|
|
|
- baseInfoId: props.protocolId,
|
|
|
- paramCode: item.platformParamCode,
|
|
|
- paramName: item.platformParamName,
|
|
|
- unit: item.unit,
|
|
|
- module: item.module,
|
|
|
+ if (isAddParams.value) {
|
|
|
+ for (const item of selectedParams.value) {
|
|
|
+ await addProtocolParam({
|
|
|
+ baseInfoId: props.protocolId,
|
|
|
+ ...item,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ message.success(t('setupProtocol.addStandardParamsSuccessful'));
|
|
|
+ } else {
|
|
|
+ await updateProtocolParam({
|
|
|
+ ...selectedParams.value[0],
|
|
|
+ id: props.paramId,
|
|
|
});
|
|
|
+
|
|
|
+ message.success(t('setupProtocol.updateStandardParamsSuccessful'));
|
|
|
}
|
|
|
|
|
|
- message.success(t('setupProtocol.addStandardParamsSuccessful'));
|
|
|
hideView();
|
|
|
emit('refreshList');
|
|
|
});
|
|
@@ -125,6 +142,7 @@ const handleClose = () => {
|
|
|
defineExpose({
|
|
|
showView,
|
|
|
hideView,
|
|
|
+ setIsAddParams,
|
|
|
});
|
|
|
</script>
|
|
|
|
|
@@ -158,6 +176,7 @@ defineExpose({
|
|
|
:data-source="paramList"
|
|
|
row-key="id"
|
|
|
:row-selection="{
|
|
|
+ type: selectionType,
|
|
|
selectedRowKeys: selectedParamIds,
|
|
|
preserveSelectedRowKeys: true,
|
|
|
onChange: handleParamSelectChange,
|