快检实验标准新增

This commit is contained in:
2026-05-25 16:01:14 +08:00
parent 837a85f7ba
commit 589961397c
19 changed files with 1933 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
<template>
<BasicModal v-bind="$attrs" title="选择实验方法" :width="960" @register="registerModal" @ok="handleOk">
<BasicTable @register="registerTable" />
</BasicModal>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable } from '/@/components/Table';
import type { FormSchema } from '/@/components/Table';
import { list as methodList, queryById as queryMethodById } from '../../mesXslRubberQuickTestMethod/MesXslRubberQuickTestMethod.api';
import { columns as methodColumns } from '../../mesXslRubberQuickTestMethod/MesXslRubberQuickTestMethod.data';
import { useMessage } from '/@/hooks/web/useMessage';
const emit = defineEmits(['register', 'select']);
const { createMessage } = useMessage();
const selectSearchSchema: FormSchema[] = [
{ label: '方法编号', field: 'methodCode', component: 'JInput', colProps: { span: 8 } },
{ label: '实验方法名称', field: 'methodName', component: 'JInput', colProps: { span: 8 } },
];
const selectedRow = ref<Recordable | null>(null);
const [registerTable, { reload, getSelectRowKeys, getSelectRows, setSelectedRowKeys, clearSelectedRowKeys }] = useTable({
api: methodList,
columns: methodColumns.slice(0, 4),
rowKey: 'id',
useSearchForm: true,
formConfig: {
labelWidth: 100,
schemas: selectSearchSchema,
},
pagination: { pageSize: 10 },
canResize: false,
showIndexColumn: false,
immediate: true,
rowSelection: {
type: 'radio',
columnWidth: 48,
onChange: (_keys, rows) => {
selectedRow.value = rows?.[0] ?? null;
},
},
clickToRowSelect: true,
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
selectedRow.value = null;
clearSelectedRowKeys?.();
setModalProps({ confirmLoading: false });
const methodId = data?.testMethodId as string | undefined;
if (methodId) {
setSelectedRowKeys?.([methodId]);
try {
const raw = await queryMethodById({ id: methodId });
const row = (raw as Recordable)?.methodName != null ? raw : (raw as Recordable)?.result;
if (row) {
selectedRow.value = row;
}
} catch {
// ignore
}
}
reload();
});
async function handleOk() {
const keys = (getSelectRowKeys?.() || []) as string[];
let row = selectedRow.value || ((getSelectRows?.() || []) as Recordable[])[0];
if (!row && keys.length) {
try {
const raw = await queryMethodById({ id: keys[0] });
row = (raw as Recordable)?.methodName != null ? raw : (raw as Recordable)?.result;
} catch {
// ignore
}
}
if (!row?.id) {
createMessage.warning('请选择一条实验方法');
return;
}
emit('select', {
testMethodId: row.id,
testMethodName: row.methodName || '',
methodCode: row.methodCode || '',
});
closeModal();
}
</script>

View File

@@ -0,0 +1,104 @@
<template>
<BasicModal v-bind="$attrs" title="选择发行编号(原材料检验标准)" :width="960" @register="registerModal" @ok="handleOk">
<BasicTable @register="registerTable" />
</BasicModal>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable } from '/@/components/Table';
import type { FormSchema } from '/@/components/Table';
import { list as mixerPsList, queryById as queryMixerPsById } from '../../mesXslMixerPsCompile/MesXslMixerPsCompile.api';
import { columns as mixerPsColumns } from '../../mesXslMixerPsCompile/MesXslMixerPsCompile.data';
import { useMessage } from '/@/hooks/web/useMessage';
const emit = defineEmits(['register', 'select']);
const { createMessage } = useMessage();
/** 密炼PS类型原材料检验标准 */
const PS_TYPE_RAW_INSPECT_STD = 'raw_inspect_std';
const selectSearchSchema: FormSchema[] = [
{ label: 'PS编码', field: 'psCode', component: 'JInput', colProps: { span: 8 } },
{ label: '标题', field: 'title', component: 'JInput', colProps: { span: 8 } },
];
const selectedRow = ref<Recordable | null>(null);
const [registerTable, { reload, getSelectRowKeys, getSelectRows, setSelectedRowKeys, clearSelectedRowKeys }] = useTable({
api: mixerPsList,
columns: mixerPsColumns.slice(0, 7),
rowKey: 'id',
useSearchForm: true,
formConfig: {
labelWidth: 90,
schemas: selectSearchSchema,
},
pagination: { pageSize: 10 },
canResize: false,
showIndexColumn: false,
immediate: true,
beforeFetch: (params) => ({
...params,
psType: PS_TYPE_RAW_INSPECT_STD,
}),
rowSelection: {
type: 'radio',
columnWidth: 48,
onChange: (_keys, rows) => {
selectedRow.value = rows?.[0] ?? null;
},
},
clickToRowSelect: true,
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
selectedRow.value = null;
clearSelectedRowKeys?.();
setModalProps({ confirmLoading: false });
const psId = data?.psCompileId as string | undefined;
if (psId) {
setSelectedRowKeys?.([psId]);
try {
const raw = await queryMixerPsById({ id: psId });
const row = (raw as Recordable)?.psCode != null ? raw : (raw as Recordable)?.result;
if (row) {
selectedRow.value = row;
}
} catch {
// ignore
}
}
reload();
});
async function handleOk() {
const keys = (getSelectRowKeys?.() || []) as string[];
let row = selectedRow.value || ((getSelectRows?.() || []) as Recordable[])[0];
if (!row && keys.length) {
try {
const raw = await queryMixerPsById({ id: keys[0] });
row = (raw as Recordable)?.psCode != null ? raw : (raw as Recordable)?.result;
} catch {
// ignore
}
}
if (!row?.id) {
createMessage.warning('请选择一条密炼PS');
return;
}
if (row.psType && row.psType !== PS_TYPE_RAW_INSPECT_STD) {
createMessage.warning('仅可选择类型为原材料检验标准的密炼PS');
return;
}
emit('select', {
psCompileId: row.id,
issueNumber: row.psCode || '',
issueDate: row.issueDate || undefined,
issueDeptId: row.sendDeptId || undefined,
issueDeptName: row.sendDeptId_dictText || undefined,
});
closeModal();
}
</script>

View File

@@ -0,0 +1,290 @@
<template>
<BasicModal
v-bind="$attrs"
destroyOnClose
:title="title"
width="1100px"
@register="registerModal"
@ok="handleSubmit"
>
<BasicForm @register="registerForm">
<template #testMethodPicker="{ model, field }">
<a-input-group compact style="display: flex; width: 100%">
<a-input v-model:value="model[field]" read-only placeholder="请选择实验方法" style="flex: 1" />
<a-button type="primary" :disabled="isDetail" @click="openMethodSelect">选择</a-button>
</a-input-group>
</template>
<template #rubberMaterialPicker="{ model, field }">
<a-input-group compact style="display: flex; width: 100%">
<a-input v-model:value="model[field]" read-only placeholder="请选择胶料信息" style="flex: 1" />
<a-button type="primary" :disabled="isDetail" @click="openMaterialSelect">选择</a-button>
</a-input-group>
</template>
<template #issueNumberPicker="{ model, field }">
<a-input-group compact style="display: flex; width: 100%">
<a-input v-model:value="model[field]" read-only placeholder="请选择发行编号" style="flex: 1" />
<a-button type="primary" :disabled="isDetail" @click="openPsSelect">选择</a-button>
<a-button v-if="model.issueNumber && !isDetail" @click="clearIssueNumber(model)">清除</a-button>
</a-input-group>
</template>
<template #issueDeptPicker="{ model, field }">
<a-input-group compact style="display: flex; width: 100%">
<a-input v-model:value="model[field]" read-only placeholder="请选择发行部门" style="flex: 1" />
<a-button type="primary" :disabled="isDetail" @click="openDeptSelect">选择</a-button>
<a-button v-if="model.issueDeptId && !isDetail" @click="clearIssueDept(model)">清除</a-button>
</a-input-group>
</template>
</BasicForm>
<a-divider orientation="left">标准明细由实验方法带出数据点不可增删</a-divider>
<JVxeTable
v-if="tableReady"
ref="lineTableRef"
toolbar
row-number
keep-source
:insert-row="false"
:remove-btn="false"
:max-height="380"
:loading="lineLoading"
:columns="lineJVxeColumns"
:dataSource="lineDataSource"
:disabled="isDetail"
:toolbar-config="{ btn: [] }"
:add-btn-cfg="{ enabled: false }"
/>
<MesXslRubberQuickTestMethodSelectModal @register="registerMethodModal" @select="onMethodSelect" />
<MesMaterialSelectModal @register="registerMaterialModal" @select="onMaterialSelect" />
<MesXslRubberQuickTestStdMixerPsSelectModal @register="registerPsModal" @select="onPsSelect" />
<DeptSelectModal @register="registerDeptModal" @getSelectResult="onIssueDeptSelect" />
</BasicModal>
</template>
<script lang="ts" setup>
import { computed, ref, unref } from 'vue';
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import type { JVxeTableInstance } from '/@/components/jeecg/JVxeTable/types';
import { useMessage } from '/@/hooks/web/useMessage';
import { formSchema, lineJVxeColumns } from '../MesXslRubberQuickTestStd.data';
import { saveOrUpdate, queryById, queryLineListByStdId } from '../MesXslRubberQuickTestStd.api';
import { queryLineListByMethodId } from '../../mesXslRubberQuickTestMethod/MesXslRubberQuickTestMethod.api';
import MesXslRubberQuickTestMethodSelectModal from './MesXslRubberQuickTestMethodSelectModal.vue';
import MesXslRubberQuickTestStdMixerPsSelectModal from './MesXslRubberQuickTestStdMixerPsSelectModal.vue';
import MesMaterialSelectModal from '/@/views/mes/material/modules/MesMaterialSelectModal.vue';
import DeptSelectModal from '/@/components/Form/src/jeecg/components/modal/DeptSelectModal.vue';
const emit = defineEmits(['register', 'success']);
const { createMessage } = useMessage();
const isUpdate = ref(false);
const isDetail = ref(false);
const tableReady = ref(false);
const lineLoading = ref(false);
const lineDataSource = ref<Recordable[]>([]);
const lineTableRef = ref<JVxeTableInstance>();
const lastMethodId = ref<string>('');
const [registerForm, { resetFields, setFieldsValue, validate, setProps, getFieldsValue }] = useForm({
labelWidth: 120,
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { span: 12 },
});
const [registerMethodModal, { openModal: openMethodModal }] = useModal();
const [registerMaterialModal, { openModal: openMaterialModal }] = useModal();
const [registerPsModal, { openModal: openPsModal }] = useModal();
const [registerDeptModal, { openModal: openDeptModal }] = useModal();
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
tableReady.value = false;
lineDataSource.value = [];
lastMethodId.value = '';
await resetFields();
setModalProps({ confirmLoading: false, showCancelBtn: data?.showFooter, showOkBtn: data?.showFooter });
isUpdate.value = !!data?.isUpdate;
isDetail.value = !data?.showFooter;
setProps({ disabled: !data?.showFooter });
if (unref(isUpdate) && data?.record?.id) {
lineLoading.value = true;
try {
const mainRaw = await queryById({ id: data.record.id });
const m = (mainRaw as any)?.id != null ? mainRaw : (mainRaw as any)?.result ?? mainRaw;
const linesRaw = await queryLineListByStdId({ id: data.record.id });
const list = Array.isArray(linesRaw) ? linesRaw : (linesRaw as any)?.result ?? [];
await setFieldsValue({ ...m });
lineDataSource.value = list || [];
lastMethodId.value = m?.testMethodId || '';
} finally {
lineLoading.value = false;
}
} else {
await setFieldsValue({ enableStatus: '1', auditStatus: '0' });
}
tableReady.value = true;
});
const title = computed(() =>
!unref(isUpdate) ? '新增胶料快检实验标准' : unref(isDetail) ? '实验标准详情' : '编辑胶料快检实验标准',
);
function methodLineToStdRow(ml: Recordable, existing?: Recordable): Recordable {
return {
dataPointId: ml.dataPointId,
pointName: ml.pointName,
lowerLimit: existing?.lowerLimit ?? null,
lowerWarn: existing?.lowerWarn ?? null,
targetValue: existing?.targetValue ?? null,
upperWarn: existing?.upperWarn ?? null,
upperLimit: existing?.upperLimit ?? null,
};
}
async function loadLinesFromMethod(methodId: string, mergeExisting = true) {
if (!methodId) {
lineDataSource.value = [];
return;
}
lineLoading.value = true;
try {
const linesRaw = await queryLineListByMethodId({ id: methodId });
const methodLines = Array.isArray(linesRaw) ? linesRaw : (linesRaw as any)?.result ?? [];
const existingMap = new Map<string, Recordable>();
if (mergeExisting) {
const current = (lineTableRef.value as any)?.getTableData?.() || lineDataSource.value || [];
for (const row of current as Recordable[]) {
if (row?.dataPointId) {
existingMap.set(String(row.dataPointId), row);
}
}
}
lineDataSource.value = (methodLines || []).map((ml: Recordable) =>
methodLineToStdRow(ml, existingMap.get(String(ml.dataPointId))),
);
} finally {
lineLoading.value = false;
}
}
function openMethodSelect() {
const vals = getFieldsValue();
openMethodModal(true, { testMethodId: vals?.testMethodId || '' });
}
async function onMethodSelect(payload: Recordable) {
const methodId = payload?.testMethodId || '';
await setFieldsValue({
testMethodId: methodId,
testMethodName: payload?.testMethodName || '',
});
if (methodId !== lastMethodId.value) {
lastMethodId.value = methodId;
await loadLinesFromMethod(methodId, false);
}
}
function openMaterialSelect() {
const vals = getFieldsValue();
openMaterialModal(true, { materialId: vals?.rubberMaterialId || '' });
}
async function onMaterialSelect(payload: Recordable) {
await setFieldsValue({
rubberMaterialId: payload.materialId || '',
rubberMaterialName: payload.materialName || '',
});
}
function openPsSelect() {
const vals = getFieldsValue();
openPsModal(true, { psCompileId: vals?.psCompileId || '' });
}
async function onPsSelect(payload: Recordable) {
await setFieldsValue({
psCompileId: payload.psCompileId || '',
issueNumber: payload.issueNumber || '',
issueDate: payload.issueDate || undefined,
issueDeptId: payload.issueDeptId || undefined,
issueDeptName: payload.issueDeptName || undefined,
});
}
function clearIssueNumber(model: Recordable) {
model.psCompileId = '';
model.issueNumber = '';
}
function openDeptSelect() {
openDeptModal(true, { isUpdate: false });
}
function resolveIssueDeptSelection(options: Recordable[] = [], values: Recordable[] = []) {
const opt = options?.[0] || {};
let id = '';
let name = opt.label != null ? String(opt.label) : '';
if (opt.value != null && opt.value !== '') {
if (typeof opt.value === 'string' || typeof opt.value === 'number') {
id = String(opt.value);
} else if (typeof opt.value === 'object') {
const row = opt.value as Recordable;
id = String(row.id ?? row.key ?? row.value ?? '');
if (!name) {
name = String(row.departName ?? row.title ?? row.label ?? '');
}
}
}
const rawValue = values?.[0];
if (!id && rawValue != null && rawValue !== '') {
id = String(rawValue);
}
return { id, name };
}
async function onIssueDeptSelect(options: Recordable[], values: Recordable[]) {
const { id, name } = resolveIssueDeptSelection(options, values);
await setFieldsValue({
issueDeptId: id,
issueDeptName: name,
});
}
function clearIssueDept(model: Recordable) {
model.issueDeptId = '';
model.issueDeptName = '';
}
async function handleSubmit() {
try {
const values = await validate();
if (!values?.testMethodId) {
createMessage.warning('请选择实验方法');
return;
}
const lineRef = lineTableRef.value as any;
const tableData = (lineRef?.getTableData?.() || lineDataSource.value || []) as Recordable[];
const lineList = tableData
.filter((r) => r && r.dataPointId)
.map((r) => ({
dataPointId: r.dataPointId,
pointName: r.pointName,
lowerLimit: r.lowerLimit,
lowerWarn: r.lowerWarn,
targetValue: r.targetValue,
upperWarn: r.upperWarn,
upperLimit: r.upperLimit,
}));
if (!lineList.length) {
createMessage.warning('请先选择实验方法以带出数据点明细');
return;
}
setModalProps({ confirmLoading: true });
await saveOrUpdate({ ...values, lineList }, unref(isUpdate));
closeModal();
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script>