原材料送检记录
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<BasicModal
|
||||
v-bind="$attrs"
|
||||
destroyOnClose
|
||||
:title="title"
|
||||
width="1100px"
|
||||
@register="registerModal"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<a-descriptions bordered :column="2" size="small">
|
||||
<a-descriptions-item label="条码">{{ mainRecord.barcode || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="批次号">{{ mainRecord.batchNo || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="物料名称">{{ mainRecord.materialName || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="检验状态">{{ mainRecord.inspectStatus_dictText || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="送检时间">{{ mainRecord.inspectTime || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="判定时间">{{ mainRecord.resultTime || '-' }}</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
<a-divider orientation="left">检验明细</a-divider>
|
||||
<JVxeTable
|
||||
v-if="tableReady"
|
||||
ref="lineTableRef"
|
||||
row-number
|
||||
keep-source
|
||||
:max-height="400"
|
||||
:loading="lineLoading"
|
||||
:columns="tableColumns"
|
||||
:dataSource="lineDataSource"
|
||||
:disabled="!editable"
|
||||
/>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import type { JVxeTableInstance } from '/@/components/jeecg/JVxeTable/types';
|
||||
import { lineJVxeColumns } from '../MesXslRawMaterialInspectRecord.data';
|
||||
import { prepareResultEntry, queryById, queryLineListByRecordId, saveInspectResult } from '../MesXslRawMaterialInspectRecord.api';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
const { createMessage } = useMessage();
|
||||
const editable = ref(false);
|
||||
const tableReady = ref(false);
|
||||
const lineLoading = ref(false);
|
||||
const lineDataSource = ref<Recordable[]>([]);
|
||||
const lineTableRef = ref<JVxeTableInstance>();
|
||||
const recordId = ref('');
|
||||
const mainRecord = ref<Recordable>({});
|
||||
|
||||
const tableColumns = computed(() => {
|
||||
if (editable.value) {
|
||||
return lineJVxeColumns;
|
||||
}
|
||||
return lineJVxeColumns.map((c) => {
|
||||
if (c.key === 'inspectValue') {
|
||||
return { ...c, disabled: true };
|
||||
}
|
||||
return c;
|
||||
});
|
||||
});
|
||||
|
||||
function mapPassFlagText(list: Recordable[]) {
|
||||
return (list || []).map((row) => {
|
||||
const passFlag = String(row?.passFlag ?? '');
|
||||
let passText = '';
|
||||
if (passFlag === '0') passText = '待检';
|
||||
else if (passFlag === '1') passText = '合格';
|
||||
else if (passFlag === '2') passText = '不合格';
|
||||
return { ...row, passFlag_dictText: passText };
|
||||
});
|
||||
}
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||
tableReady.value = false;
|
||||
lineDataSource.value = [];
|
||||
editable.value = !!data?.editable;
|
||||
recordId.value = data?.record?.id || '';
|
||||
setModalProps({
|
||||
confirmLoading: false,
|
||||
showCancelBtn: true,
|
||||
showOkBtn: editable.value,
|
||||
okText: '保存',
|
||||
});
|
||||
if (!recordId.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
lineLoading.value = true;
|
||||
try {
|
||||
const mainRaw = await queryById({ id: recordId.value });
|
||||
mainRecord.value = (mainRaw as any)?.id != null ? (mainRaw as Recordable) : ((mainRaw as any)?.result ?? {});
|
||||
if (editable.value) {
|
||||
const linesRaw = await prepareResultEntry(recordId.value);
|
||||
const list = Array.isArray(linesRaw) ? linesRaw : ((linesRaw as any)?.result ?? []);
|
||||
lineDataSource.value = mapPassFlagText(list || []);
|
||||
} else {
|
||||
const linesRaw = await queryLineListByRecordId({ id: recordId.value });
|
||||
const list = Array.isArray(linesRaw) ? linesRaw : ((linesRaw as any)?.result ?? []);
|
||||
lineDataSource.value = mapPassFlagText(list || []);
|
||||
}
|
||||
} finally {
|
||||
lineLoading.value = false;
|
||||
tableReady.value = true;
|
||||
}
|
||||
});
|
||||
|
||||
const title = computed(() => (editable.value ? '录入检验结果' : '送检记录详情'));
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!editable.value) {
|
||||
closeModal();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const lineRef = lineTableRef.value as any;
|
||||
if (lineRef?.validateTable) {
|
||||
const err = await lineRef.validateTable();
|
||||
if (err) {
|
||||
createMessage.warning('请完善检验值');
|
||||
return;
|
||||
}
|
||||
}
|
||||
const tableData = (lineRef?.getTableData?.() || []) as Recordable[];
|
||||
const lineList = tableData.map((item) => ({
|
||||
id: item.id,
|
||||
inspectValue: item.inspectValue,
|
||||
}));
|
||||
setModalProps({ confirmLoading: true });
|
||||
await saveInspectResult({
|
||||
id: recordId.value,
|
||||
lineList,
|
||||
});
|
||||
createMessage.success('保存成功');
|
||||
closeModal();
|
||||
emit('success');
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user