feat(mes-qc): 迁移 ele 来料检验及检测结果、缺陷记录组件
parent
cea628b1a1
commit
fe71f18d21
|
|
@ -6,6 +6,7 @@ import type { MesQcIndicatorResultApi } from '#/api/mes/qc/indicatorresult';
|
|||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import {
|
||||
Form as AForm,
|
||||
|
|
@ -62,19 +63,9 @@ const [Form, formApi] = useVbenForm({
|
|||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
/** 解析字典选项字符串:value=label;value=label */
|
||||
function parseValueOptions(spec?: string) {
|
||||
if (!spec) {
|
||||
return [];
|
||||
}
|
||||
return spec
|
||||
.split(';')
|
||||
.map((part) => part.trim())
|
||||
.filter(Boolean)
|
||||
.map((part) => {
|
||||
const [value, label] = part.split('=');
|
||||
return { value: value ?? '', label: label ?? value ?? '' };
|
||||
});
|
||||
/** 获取字典选项(valueSpecification 为系统字典类型名) */
|
||||
function getValueOptions(dictType?: string) {
|
||||
return dictType ? getDictOptions(dictType, 'string') : [];
|
||||
}
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
|
|
@ -205,7 +196,7 @@ const [Modal, modalApi] = useVbenModal({
|
|||
v-else-if="item.valueType === MesQcResultValueType.DICT"
|
||||
v-model:value="item.value"
|
||||
allow-clear
|
||||
:options="parseValueOptions(item.valueSpecification)"
|
||||
:options="getValueOptions(item.valueSpecification)"
|
||||
placeholder="请选择"
|
||||
/>
|
||||
<Input
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesQcDefectRecordApi } from '#/api/mes/qc/defectrecord';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
/** 表单类型 */
|
||||
export type FormType = 'create' | 'update';
|
||||
|
||||
/** 新增/修改缺陷记录的表单 */
|
||||
export function useDefectRecordInlineFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '缺陷描述',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-2',
|
||||
componentProps: {
|
||||
placeholder: '请输入缺陷描述',
|
||||
rows: 2,
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'level',
|
||||
label: '缺陷等级',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.MES_DEFECT_LEVEL, 'number'),
|
||||
placeholder: '请选择缺陷等级',
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
fieldName: 'quantity',
|
||||
label: '缺陷数量',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
min: 1,
|
||||
placeholder: '请输入缺陷数量',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-2',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 缺陷记录列表的字段 */
|
||||
export function useDefectRecordInlineGridColumns(): VxeTableGridOptions<MesQcDefectRecordApi.DefectRecord>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'name',
|
||||
title: '缺陷描述',
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
field: 'level',
|
||||
title: '缺陷等级',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_DEFECT_LEVEL },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'quantity',
|
||||
title: '缺陷数量',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
<script lang="ts" setup>
|
||||
import type { FormType } from './data';
|
||||
|
||||
import type { MesQcDefectRecordApi } from '#/api/mes/qc/defectrecord';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createDefectRecord,
|
||||
getDefectRecord,
|
||||
updateDefectRecord,
|
||||
} from '#/api/mes/qc/defectrecord';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useDefectRecordInlineFormSchema } from './data';
|
||||
|
||||
interface CtxData {
|
||||
formType: FormType;
|
||||
id?: number;
|
||||
lineId: number;
|
||||
qcId: number;
|
||||
qcType: number;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'DefectRecordInlineForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formType = ref<FormType>('create');
|
||||
const formData = ref<MesQcDefectRecordApi.DefectRecord>();
|
||||
|
||||
const getTitle = computed(() =>
|
||||
formType.value === 'update'
|
||||
? $t('ui.actionTitle.edit', ['缺陷记录'])
|
||||
: $t('ui.actionTitle.create', ['缺陷记录']),
|
||||
);
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 90,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useDefectRecordInlineFormSchema(),
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (!formData.value) {
|
||||
return;
|
||||
}
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const values =
|
||||
(await formApi.getValues()) as MesQcDefectRecordApi.DefectRecord;
|
||||
const payload: MesQcDefectRecordApi.DefectRecord = {
|
||||
...values,
|
||||
lineId: formData.value.lineId,
|
||||
qcId: formData.value.qcId,
|
||||
qcType: formData.value.qcType,
|
||||
};
|
||||
try {
|
||||
if (formType.value === 'update') {
|
||||
await updateDefectRecord({ ...payload, id: formData.value.id });
|
||||
ElMessage.success($t('common.updateSuccess'));
|
||||
} else {
|
||||
await createDefectRecord(payload);
|
||||
ElMessage.success($t('common.createSuccess'));
|
||||
}
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<CtxData>();
|
||||
formType.value = data.formType;
|
||||
if (!data.id) {
|
||||
// 新增:保留来自父级的上下文,并默认数量为 1
|
||||
formData.value = {
|
||||
lineId: data.lineId,
|
||||
qcId: data.qcId,
|
||||
qcType: data.qcType,
|
||||
};
|
||||
await formApi.setValues({ quantity: 1 });
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getDefectRecord(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-2/5">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesQcDefectRecordApi } from '#/api/mes/qc/defectrecord';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteDefectRecord,
|
||||
getDefectRecordPage,
|
||||
} from '#/api/mes/qc/defectrecord';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useDefectRecordInlineGridColumns } from './data';
|
||||
import DefectRecordInlineForm from './defect-record-inline-form.vue';
|
||||
|
||||
defineOptions({ name: 'DefectRecordInlineList' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
interface CtxData {
|
||||
formType?: string;
|
||||
lineId: number;
|
||||
qcId: number;
|
||||
qcType: number;
|
||||
}
|
||||
|
||||
const ctxData = ref<CtxData>();
|
||||
const isReadonly = computed(() => ctxData.value?.formType === 'detail');
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
emit('success');
|
||||
}
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: DefectRecordInlineForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 新增缺陷 */
|
||||
function handleCreate() {
|
||||
if (!ctxData.value) {
|
||||
return;
|
||||
}
|
||||
formModalApi
|
||||
.setData({
|
||||
formType: 'create',
|
||||
lineId: ctxData.value.lineId,
|
||||
qcId: ctxData.value.qcId,
|
||||
qcType: ctxData.value.qcType,
|
||||
})
|
||||
.open();
|
||||
}
|
||||
|
||||
/** 编辑缺陷 */
|
||||
function handleEdit(row: MesQcDefectRecordApi.DefectRecord) {
|
||||
if (!ctxData.value) {
|
||||
return;
|
||||
}
|
||||
formModalApi
|
||||
.setData({
|
||||
formType: 'update',
|
||||
id: row.id,
|
||||
lineId: ctxData.value.lineId,
|
||||
qcId: ctxData.value.qcId,
|
||||
qcType: ctxData.value.qcType,
|
||||
})
|
||||
.open();
|
||||
}
|
||||
|
||||
/** 删除缺陷 */
|
||||
async function handleDelete(row: MesQcDefectRecordApi.DefectRecord) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
});
|
||||
try {
|
||||
await deleteDefectRecord(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: useDefectRecordInlineGridColumns(),
|
||||
height: 320,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
if (!ctxData.value) {
|
||||
return { list: [], total: 0 };
|
||||
}
|
||||
return await getDefectRecordPage({
|
||||
lineId: ctxData.value.lineId,
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
qcId: ctxData.value.qcId,
|
||||
qcType: ctxData.value.qcType,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
isHover: true,
|
||||
keyField: 'id',
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesQcDefectRecordApi.DefectRecord>,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
showCancelButton: false,
|
||||
showConfirmButton: false,
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
ctxData.value = undefined;
|
||||
return;
|
||||
}
|
||||
ctxData.value = modalApi.getData<CtxData>();
|
||||
await gridApi.query();
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="缺陷记录" class="w-3/5">
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid class="mx-4">
|
||||
<template v-if="!isReadonly" #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
auth: ['mes:qc-defect:create'],
|
||||
icon: ACTION_ICON.ADD,
|
||||
label: '新增缺陷',
|
||||
onClick: handleCreate,
|
||||
type: 'primary',
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
auth: ['mes:qc-defect:update'],
|
||||
icon: ACTION_ICON.EDIT,
|
||||
ifShow: !isReadonly,
|
||||
label: $t('common.edit'),
|
||||
link: true,
|
||||
onClick: handleEdit.bind(null, row),
|
||||
type: 'primary',
|
||||
},
|
||||
{
|
||||
auth: ['mes:qc-defect:delete'],
|
||||
icon: ACTION_ICON.DELETE,
|
||||
ifShow: !isReadonly,
|
||||
label: $t('common.delete'),
|
||||
link: true,
|
||||
popConfirm: {
|
||||
confirm: handleDelete.bind(null, row),
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
},
|
||||
type: 'danger',
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { default as DefectRecordInlineForm } from './defect-record-inline-form.vue';
|
||||
export { default as DefectRecordInlineList } from './defect-record-inline-list.vue';
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesQcIndicatorResultApi } from '#/api/mes/qc/indicatorresult';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||||
import { MesAutoCodeRuleCode } from '#/views/mes/utils/constants';
|
||||
|
||||
/** 表单类型 */
|
||||
export type FormType = 'create' | 'update';
|
||||
|
||||
/** 新增/修改检测结果的表单 */
|
||||
export function useQcIndicatorResultFormSchema(
|
||||
formApi?: VbenFormApi,
|
||||
): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '样品编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入样品编号',
|
||||
},
|
||||
rules: 'required',
|
||||
suffix: () =>
|
||||
h(
|
||||
ElButton,
|
||||
{
|
||||
onClick: async () => {
|
||||
try {
|
||||
const code = await generateAutoCode(
|
||||
MesAutoCodeRuleCode.QC_INDICATOR_RESULT_CODE,
|
||||
);
|
||||
await formApi?.setFieldValue('code', code);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
{ default: () => '生成' },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'sn',
|
||||
label: '物资 SN',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入物资 SN',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-2',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 检测结果列表的字段 */
|
||||
export function useQcIndicatorResultGridColumns(): VxeTableGridOptions<MesQcIndicatorResultApi.IndicatorResult>['columns'] {
|
||||
return [
|
||||
{ field: 'code', title: '样品编号', width: 200 },
|
||||
{ field: 'sn', title: '物资SN', minWidth: 200 },
|
||||
{ field: 'remark', title: '备注', minWidth: 200 },
|
||||
{
|
||||
title: '操作',
|
||||
width: 150,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { default as QcIndicatorResultForm } from './qc-indicator-result-form.vue';
|
||||
export { default as QcIndicatorResultList } from './qc-indicator-result-list.vue';
|
||||
|
|
@ -0,0 +1,225 @@
|
|||
<script lang="ts" setup>
|
||||
import type { FormType } from './data';
|
||||
|
||||
import type { MesQcIndicatorResultApi } from '#/api/mes/qc/indicatorresult';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import {
|
||||
ElDivider,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElInput,
|
||||
ElInputNumber,
|
||||
ElMessage,
|
||||
ElOption,
|
||||
ElSelect,
|
||||
} from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createIndicatorResult,
|
||||
getIndicatorResultDetail,
|
||||
updateIndicatorResult,
|
||||
} from '#/api/mes/qc/indicatorresult';
|
||||
import { $t } from '#/locales';
|
||||
import { MesQcResultValueType } from '#/views/mes/utils/constants';
|
||||
|
||||
import { useQcIndicatorResultFormSchema } from './data';
|
||||
|
||||
interface CtxData {
|
||||
formType: FormType;
|
||||
id?: number;
|
||||
qcId: number;
|
||||
qcType: number;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'QcIndicatorResultForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formType = ref<FormType>('create');
|
||||
const items = ref<MesQcIndicatorResultApi.IndicatorResultDetail[]>([]);
|
||||
const ctxData = ref<CtxData>();
|
||||
|
||||
const getTitle = computed(() =>
|
||||
formType.value === 'update'
|
||||
? $t('ui.actionTitle.edit', ['检验结果'])
|
||||
: $t('ui.actionTitle.create', ['检验结果']),
|
||||
);
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 100,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
/** 获取字典选项(valueSpecification 为系统字典类型名) */
|
||||
function getValueOptions(dictType?: string) {
|
||||
return dictType ? getDictOptions(dictType, 'string') : [];
|
||||
}
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (!ctxData.value) {
|
||||
return;
|
||||
}
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const head =
|
||||
(await formApi.getValues()) as MesQcIndicatorResultApi.IndicatorResult;
|
||||
const submitItems = items.value.map((item) => {
|
||||
const submit: MesQcIndicatorResultApi.IndicatorResultDetail = {
|
||||
id: item.id,
|
||||
indicatorId: item.indicatorId,
|
||||
remark: item.remark,
|
||||
};
|
||||
if (
|
||||
item.valueType === MesQcResultValueType.FLOAT ||
|
||||
item.valueType === MesQcResultValueType.INTEGER
|
||||
) {
|
||||
submit.value =
|
||||
item.valueNumber == null ? undefined : String(item.valueNumber);
|
||||
} else {
|
||||
submit.value = item.value;
|
||||
}
|
||||
return submit;
|
||||
});
|
||||
const payload: MesQcIndicatorResultApi.IndicatorResult = {
|
||||
...head,
|
||||
items: submitItems,
|
||||
qcId: ctxData.value.qcId,
|
||||
qcType: ctxData.value.qcType,
|
||||
};
|
||||
try {
|
||||
if (formType.value === 'update') {
|
||||
await updateIndicatorResult(payload);
|
||||
ElMessage.success($t('common.updateSuccess'));
|
||||
} else {
|
||||
await createIndicatorResult(payload);
|
||||
ElMessage.success($t('common.createSuccess'));
|
||||
}
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
ctxData.value = undefined;
|
||||
items.value = [];
|
||||
return;
|
||||
}
|
||||
formApi.setState({ schema: useQcIndicatorResultFormSchema(formApi) });
|
||||
// 加载数据
|
||||
const data = modalApi.getData<CtxData>();
|
||||
ctxData.value = data;
|
||||
formType.value = data.formType;
|
||||
modalApi.lock();
|
||||
try {
|
||||
const detail = await getIndicatorResultDetail(
|
||||
data.qcId,
|
||||
data.qcType,
|
||||
data.id,
|
||||
);
|
||||
// 回填数值字段(用于 InputNumber 绑定)
|
||||
items.value = (detail.items ?? []).map((item) => ({
|
||||
...item,
|
||||
valueNumber:
|
||||
(item.valueType === MesQcResultValueType.FLOAT ||
|
||||
item.valueType === MesQcResultValueType.INTEGER) &&
|
||||
item.value != null
|
||||
? Number(item.value)
|
||||
: undefined,
|
||||
}));
|
||||
// 设置到 values
|
||||
await formApi.setValues({
|
||||
id: detail.id,
|
||||
code: detail.code,
|
||||
remark: detail.remark,
|
||||
sn: detail.sn,
|
||||
});
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-3/5">
|
||||
<div class="px-4">
|
||||
<Form />
|
||||
<ElDivider>检测值</ElDivider>
|
||||
<!-- 检测值控件由每行 valueType 驱动,逐行渲染:FLOAT/INTEGER 走 ElInputNumber,DICT 走 ElSelect 并按 valueSpecification 解析选项 -->
|
||||
<ElForm label-width="120px">
|
||||
<div
|
||||
v-for="(item, index) in items"
|
||||
:key="item.indicatorId ?? index"
|
||||
class="mb-2"
|
||||
>
|
||||
<ElFormItem
|
||||
:label="`检测项${index + 1}:${item.indicatorName ?? ''}`"
|
||||
>
|
||||
<ElInputNumber
|
||||
v-if="
|
||||
item.valueType === MesQcResultValueType.FLOAT ||
|
||||
item.valueType === MesQcResultValueType.INTEGER
|
||||
"
|
||||
v-model="item.valueNumber"
|
||||
class="!w-full"
|
||||
controls-position="right"
|
||||
:precision="
|
||||
item.valueType === MesQcResultValueType.FLOAT ? 4 : 0
|
||||
"
|
||||
placeholder="请输入"
|
||||
/>
|
||||
<ElInput
|
||||
v-else-if="item.valueType === MesQcResultValueType.TEXT"
|
||||
v-model="item.value"
|
||||
:rows="2"
|
||||
type="textarea"
|
||||
placeholder="请输入检测值"
|
||||
/>
|
||||
<ElSelect
|
||||
v-else-if="item.valueType === MesQcResultValueType.DICT"
|
||||
v-model="item.value"
|
||||
clearable
|
||||
class="!w-full"
|
||||
placeholder="请选择"
|
||||
>
|
||||
<ElOption
|
||||
v-for="opt in getValueOptions(item.valueSpecification)"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
<ElInput
|
||||
v-else-if="item.valueType === MesQcResultValueType.FILE"
|
||||
v-model="item.value"
|
||||
placeholder="请输入文件地址"
|
||||
/>
|
||||
<ElInput v-else v-model="item.value" placeholder="请输入" />
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</ElForm>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesQcIndicatorResultApi } from '#/api/mes/qc/indicatorresult';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteIndicatorResult,
|
||||
getIndicatorResultPage,
|
||||
} from '#/api/mes/qc/indicatorresult';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useQcIndicatorResultGridColumns } from './data';
|
||||
import QcIndicatorResultForm from './qc-indicator-result-form.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
qcId: number;
|
||||
qcType: number;
|
||||
readonly?: boolean;
|
||||
}>();
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: QcIndicatorResultForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 新增检测结果 */
|
||||
function handleCreate() {
|
||||
formModalApi
|
||||
.setData({
|
||||
formType: 'create',
|
||||
qcId: props.qcId,
|
||||
qcType: props.qcType,
|
||||
})
|
||||
.open();
|
||||
}
|
||||
|
||||
/** 编辑检测结果 */
|
||||
function handleEdit(row: MesQcIndicatorResultApi.IndicatorResult) {
|
||||
formModalApi
|
||||
.setData({
|
||||
formType: 'update',
|
||||
id: row.id,
|
||||
qcId: props.qcId,
|
||||
qcType: props.qcType,
|
||||
})
|
||||
.open();
|
||||
}
|
||||
|
||||
/** 删除检测结果 */
|
||||
async function handleDelete(row: MesQcIndicatorResultApi.IndicatorResult) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.code]),
|
||||
});
|
||||
try {
|
||||
await deleteIndicatorResult(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.code]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: useQcIndicatorResultGridColumns(),
|
||||
height: 360,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
if (!props.qcId) {
|
||||
return { list: [], total: 0 };
|
||||
}
|
||||
return await getIndicatorResultPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
qcId: props.qcId,
|
||||
qcType: props.qcType,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesQcIndicatorResultApi.IndicatorResult>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="检测结果">
|
||||
<template v-if="!readonly" #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '新增',
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
onClick: handleCreate,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
ifShow: !readonly,
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
ifShow: !readonly,
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.code]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,515 @@
|
|||
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesQcIqcApi } from '#/api/mes/qc/iqc';
|
||||
import type { MesQcIqcLineApi } from '#/api/mes/qc/iqc/line';
|
||||
|
||||
import { h, markRaw } from 'vue';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
import MdItemSelect from '#/views/mes/md/item/components/md-item-select.vue';
|
||||
import MdVendorSelect from '#/views/mes/md/vendor/components/md-vendor-select.vue';
|
||||
import { MesAutoCodeRuleCode } from '#/views/mes/utils/constants';
|
||||
|
||||
/** 表单类型 */
|
||||
export type FormType = 'create' | 'detail' | 'update';
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'sourceDocId',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'sourceLineId',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '检验单编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入检验单编号',
|
||||
},
|
||||
rules: 'required',
|
||||
suffix: () =>
|
||||
h(
|
||||
ElButton,
|
||||
{
|
||||
onClick: async () => {
|
||||
try {
|
||||
const code = await generateAutoCode(
|
||||
MesAutoCodeRuleCode.QC_IQC_CODE,
|
||||
);
|
||||
await formApi?.setFieldValue('code', code);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
{ default: () => '生成' },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '检验单名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入检验单名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'sourceDocType',
|
||||
label: '来源单据类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
options: getDictOptions(DICT_TYPE.MES_QC_SOURCE_DOC_TYPE, 'number'),
|
||||
placeholder: '来源单据类型',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['sourceDocType'],
|
||||
show: (values) => !!values.sourceDocType,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'sourceDocCode',
|
||||
label: '来源单据编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
placeholder: '来源单据编号',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['sourceDocType', 'sourceDocId'],
|
||||
show: (values) => !!values.sourceDocType && !!values.sourceDocId,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'itemId',
|
||||
label: '产品物料',
|
||||
component: markRaw(MdItemSelect),
|
||||
componentProps: {
|
||||
placeholder: '请选择产品物料',
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
dependencies: {
|
||||
triggerFields: ['id', 'sourceDocId'],
|
||||
componentProps: (values) => ({
|
||||
disabled: !!values.id || !!values.sourceDocId,
|
||||
placeholder: '请选择产品物料',
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'vendorId',
|
||||
label: '供应商',
|
||||
component: markRaw(MdVendorSelect),
|
||||
componentProps: {
|
||||
placeholder: '请选择供应商',
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
dependencies: {
|
||||
triggerFields: ['sourceDocId'],
|
||||
componentProps: (values) => ({
|
||||
disabled: !!values.sourceDocId,
|
||||
placeholder: '请选择供应商',
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'vendorBatch',
|
||||
label: '供应商批次号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商批次号',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'receivedQuantity',
|
||||
label: '本次接收数量',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
min: 0,
|
||||
placeholder: '请输入本次接收数量',
|
||||
precision: 2,
|
||||
},
|
||||
rules: 'required',
|
||||
dependencies: {
|
||||
triggerFields: ['sourceDocId'],
|
||||
componentProps: (values) => ({
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
disabled: !!values.sourceDocId,
|
||||
min: 0,
|
||||
placeholder: '请输入本次接收数量',
|
||||
precision: 2,
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'qualifiedQuantity',
|
||||
label: '合格品数量',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
min: 0,
|
||||
placeholder: '请输入合格品数量',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'unqualifiedQuantity',
|
||||
label: '不合格品数量',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
min: 0,
|
||||
placeholder: '请输入不合格品数量',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'receiveDate',
|
||||
label: '来料日期',
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
format: 'YYYY-MM-DD',
|
||||
placeholder: '请选择来料日期',
|
||||
type: 'date',
|
||||
valueFormat: 'x',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'inspectorUserId',
|
||||
label: '检测人员',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: getSimpleUserList,
|
||||
clearable: true,
|
||||
labelField: 'nickname',
|
||||
placeholder: '请选择检测人员',
|
||||
valueField: 'id',
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
fieldName: 'inspectDate',
|
||||
label: '检测日期',
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
format: 'YYYY-MM-DD',
|
||||
placeholder: '请选择检测日期',
|
||||
type: 'date',
|
||||
valueFormat: 'x',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'checkResult',
|
||||
label: '检测结果',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.MES_QC_CHECK_RESULT, 'number'),
|
||||
placeholder: '请选择检测结果',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '检验单编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入检验单编号',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'vendorId',
|
||||
label: '供应商',
|
||||
component: markRaw(MdVendorSelect),
|
||||
componentProps: {
|
||||
placeholder: '请选择供应商',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'vendorBatch',
|
||||
label: '供应商批次',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入供应商批次号',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'itemId',
|
||||
label: '产品物料',
|
||||
component: markRaw(MdItemSelect),
|
||||
componentProps: {
|
||||
placeholder: '请选择产品物料',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'checkResult',
|
||||
label: '检测结果',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.MES_QC_CHECK_RESULT, 'number'),
|
||||
placeholder: '请选择检测结果',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'receiveDate',
|
||||
label: '来料日期',
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
type: 'daterange',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'inspectDate',
|
||||
label: '检测日期',
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
type: 'daterange',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'inspectorUserId',
|
||||
label: '检测人员',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: getSimpleUserList,
|
||||
clearable: true,
|
||||
labelField: 'nickname',
|
||||
placeholder: '请选择检测人员',
|
||||
valueField: 'id',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesQcIqcApi.Iqc>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'code',
|
||||
title: '来料检验单编号',
|
||||
width: 160,
|
||||
slots: { default: 'code' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '来料检验单名称',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'vendorNickname',
|
||||
title: '供应商简称',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'vendorBatch',
|
||||
title: '供应商批次号',
|
||||
width: 130,
|
||||
},
|
||||
{
|
||||
field: 'itemCode',
|
||||
title: '产品物料编码',
|
||||
width: 130,
|
||||
},
|
||||
{
|
||||
field: 'itemName',
|
||||
title: '产品物料名称',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'receivedQuantity',
|
||||
title: '接收数量',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
field: 'checkQuantity',
|
||||
title: '检测数量',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
field: 'unqualifiedQuantity',
|
||||
title: '不合格数',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
field: 'checkResult',
|
||||
title: '检测结果',
|
||||
width: 110,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_QC_CHECK_RESULT },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'receiveDate',
|
||||
title: '来料日期',
|
||||
width: 120,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'inspectDate',
|
||||
title: '检测日期',
|
||||
width: 120,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'inspectorNickname',
|
||||
title: '检测人员',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '单据状态',
|
||||
width: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_ORDER_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 180,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 来料检验行子表的字段 */
|
||||
export function useLineGridColumns(): VxeTableGridOptions<MesQcIqcLineApi.IqcLine>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'indicatorName',
|
||||
title: '检测项名称',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
field: 'indicatorType',
|
||||
title: '检测项类型',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_INDICATOR_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'tool',
|
||||
title: '检测工具',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'checkMethod',
|
||||
title: '检测要求',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'standardValue',
|
||||
title: '标准值',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
field: 'unitMeasureName',
|
||||
title: '单位',
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
field: 'maxThreshold',
|
||||
title: '误差上限',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
field: 'minThreshold',
|
||||
title: '误差下限',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
field: 'criticalQuantity',
|
||||
title: '致命缺陷数',
|
||||
width: 110,
|
||||
},
|
||||
{
|
||||
field: 'majorQuantity',
|
||||
title: '严重缺陷数',
|
||||
width: 110,
|
||||
},
|
||||
{
|
||||
field: 'minorQuantity',
|
||||
title: '轻微缺陷数',
|
||||
width: 110,
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 110,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesQcIqcApi } from '#/api/mes/qc/iqc';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteIqc, exportIqc, getIqcPage } from '#/api/mes/qc/iqc';
|
||||
import { $t } from '#/locales';
|
||||
import { MesQcStatusEnum } from '#/views/mes/utils/constants';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建来料检验单 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ formType: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 查看来料检验单 */
|
||||
function handleDetail(row: MesQcIqcApi.Iqc) {
|
||||
formModalApi.setData({ formType: 'detail', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 编辑来料检验单 */
|
||||
function handleEdit(row: MesQcIqcApi.Iqc) {
|
||||
formModalApi.setData({ formType: 'update', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 删除来料检验单 */
|
||||
async function handleDelete(row: MesQcIqcApi.Iqc) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.code]),
|
||||
});
|
||||
try {
|
||||
await deleteIqc(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.code]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportIqc(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '来料检验单.xls', source: data });
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getIqcPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesQcIqcApi.Iqc>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【质量】来料检验(IQC)"
|
||||
url="https://doc.iocoder.cn/mes/qc/iqc/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
|
||||
<Grid table-title="来料检验单列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['来料检验单']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:qc-iqc:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['mes:qc-iqc:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #code="{ row }">
|
||||
<ElButton link type="primary" @click="handleDetail(row)">
|
||||
{{ row.code }}
|
||||
</ElButton>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:qc-iqc:update'],
|
||||
ifShow: row.status === MesQcStatusEnum.DRAFT,
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:qc-iqc:delete'],
|
||||
ifShow: row.status === MesQcStatusEnum.DRAFT,
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.code]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: $t('common.detail'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.VIEW,
|
||||
auth: ['mes:qc-iqc:query'],
|
||||
onClick: handleDetail.bind(null, row),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,237 @@
|
|||
<script lang="ts" setup>
|
||||
import type { FormType } from '../data';
|
||||
|
||||
import type { MesQcIqcApi } from '#/api/mes/qc/iqc';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { confirm, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
ElButton,
|
||||
ElDescriptions,
|
||||
ElDescriptionsItem,
|
||||
ElMessage,
|
||||
ElTabPane,
|
||||
ElTabs,
|
||||
} from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createIqc,
|
||||
finishIqc,
|
||||
getIqc,
|
||||
updateIqc,
|
||||
} from '#/api/mes/qc/iqc';
|
||||
import { $t } from '#/locales';
|
||||
import { MesQcStatusEnum, MesQcTypeEnum } from '#/views/mes/utils/constants';
|
||||
|
||||
import { QcIndicatorResultList } from '../../indicatorresult/components';
|
||||
import { useFormSchema } from '../data';
|
||||
import LineList from './line-list.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formType = ref<FormType>('create');
|
||||
const formData = ref<MesQcIqcApi.Iqc>();
|
||||
const subTabsName = ref('line');
|
||||
const originalSnapshot = ref(''); // 表单原始数据快照,用于 finish 时跳过未变更的保存请求
|
||||
const isDetail = computed(() => formType.value === 'detail');
|
||||
const canFinish = computed(
|
||||
() =>
|
||||
formType.value === 'update' &&
|
||||
formData.value?.status === MesQcStatusEnum.DRAFT,
|
||||
);
|
||||
const getTitle = computed(() => {
|
||||
if (formType.value === 'detail') {
|
||||
return $t('ui.actionTitle.view', ['来料检验单']);
|
||||
}
|
||||
return formType.value === 'update'
|
||||
? $t('ui.actionTitle.edit', ['来料检验单'])
|
||||
: $t('ui.actionTitle.create', ['来料检验单']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 110,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 子表变更后刷新主表头数据(缺陷统计等) */
|
||||
async function handleRefresh() {
|
||||
if (!formData.value?.id) {
|
||||
return;
|
||||
}
|
||||
formData.value = await getIqc(formData.value.id);
|
||||
}
|
||||
|
||||
/** 提交表单 */
|
||||
async function handleSubmit(): Promise<boolean> {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
const data = (await formApi.getValues()) as MesQcIqcApi.Iqc;
|
||||
if (formData.value?.id) {
|
||||
await updateIqc({ ...data, id: formData.value.id });
|
||||
formData.value = { ...formData.value, ...data };
|
||||
} else {
|
||||
const id = await createIqc(data);
|
||||
formData.value = {
|
||||
...data,
|
||||
id: id as unknown as number,
|
||||
status: MesQcStatusEnum.DRAFT,
|
||||
};
|
||||
await formApi.setFieldValue('id', formData.value.id);
|
||||
await formApi.setFieldValue('status', formData.value.status);
|
||||
formType.value = 'update';
|
||||
}
|
||||
// 刷新快照(已带上 id / status),下次 finish 用于判断是否需要再保存
|
||||
originalSnapshot.value = JSON.stringify(await formApi.getValues());
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 完成检验单:表单有修改时先保存,再调用完成接口 */
|
||||
async function handleFinish() {
|
||||
const id = formData.value?.id;
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
await confirm({
|
||||
content: '是否完成来料检验单编制?【完成后将不能更改】',
|
||||
});
|
||||
modalApi.lock();
|
||||
try {
|
||||
const current = JSON.stringify(await formApi.getValues());
|
||||
if (current !== originalSnapshot.value) {
|
||||
const data = (await formApi.getValues()) as MesQcIqcApi.Iqc;
|
||||
await updateIqc({ ...data, id });
|
||||
formData.value = { ...formData.value, ...data };
|
||||
originalSnapshot.value = current;
|
||||
}
|
||||
await finishIqc(id);
|
||||
ElMessage.success('完成成功');
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (isDetail.value) {
|
||||
await modalApi.close();
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
const ok = await handleSubmit();
|
||||
if (!ok) {
|
||||
return;
|
||||
}
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
originalSnapshot.value = '';
|
||||
return;
|
||||
}
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
subTabsName.value = 'line';
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{
|
||||
formType: FormType;
|
||||
id?: number;
|
||||
prefill?: MesQcIqcApi.Iqc;
|
||||
}>();
|
||||
formType.value = data.formType;
|
||||
formApi.setDisabled(formType.value === 'detail');
|
||||
modalApi.setState({ showConfirmButton: formType.value !== 'detail' });
|
||||
if (data?.id) {
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getIqc(data.id);
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
} else if (data?.prefill) {
|
||||
// 预填模式:来自待检任务
|
||||
formData.value = { ...data.prefill };
|
||||
await formApi.setValues(data.prefill);
|
||||
}
|
||||
// 记录初始快照,后续 finish 用于判断是否需要再保存
|
||||
originalSnapshot.value = JSON.stringify(await formApi.getValues());
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-4/5">
|
||||
<Form class="mx-4" />
|
||||
<!-- 缺陷统计(只读) -->
|
||||
<div v-if="formData?.id" class="mx-4 mt-4">
|
||||
<ElDescriptions title="缺陷情况" :column="3" border size="small">
|
||||
<ElDescriptionsItem label="致命缺陷数">
|
||||
{{ formData.criticalQuantity ?? 0 }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="严重缺陷数">
|
||||
{{ formData.majorQuantity ?? 0 }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="轻微缺陷数">
|
||||
{{ formData.minorQuantity ?? 0 }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="致命缺陷率">
|
||||
{{ formData.criticalRate ?? 0 }}%
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="严重缺陷率">
|
||||
{{ formData.majorRate ?? 0 }}%
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="轻微缺陷率">
|
||||
{{ formData.minorRate ?? 0 }}%
|
||||
</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
</div>
|
||||
<ElTabs v-if="formData?.id" v-model="subTabsName" class="mx-4 mt-4">
|
||||
<ElTabPane label="检验项" name="line">
|
||||
<LineList
|
||||
:form-type="formType"
|
||||
:iqc-id="formData.id"
|
||||
@refresh="handleRefresh"
|
||||
/>
|
||||
</ElTabPane>
|
||||
<ElTabPane label="检测结果" name="result">
|
||||
<QcIndicatorResultList
|
||||
:qc-id="formData.id"
|
||||
:qc-type="MesQcTypeEnum.IQC"
|
||||
:readonly="isDetail"
|
||||
/>
|
||||
</ElTabPane>
|
||||
</ElTabs>
|
||||
<template #prepend-footer>
|
||||
<div class="flex flex-auto items-center gap-2">
|
||||
<ElButton v-if="canFinish" type="primary" @click="handleFinish">
|
||||
完成
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesQcIqcLineApi } from '#/api/mes/qc/iqc/line';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getIqcLinePage } from '#/api/mes/qc/iqc/line';
|
||||
import { MesQcTypeEnum } from '#/views/mes/utils/constants';
|
||||
|
||||
import { DefectRecordInlineList } from '../../defectrecord/components';
|
||||
import { useLineGridColumns } from '../data';
|
||||
|
||||
const props = defineProps<{
|
||||
formType?: string;
|
||||
iqcId: number;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{ refresh: [] }>();
|
||||
|
||||
const [DefectModal, defectModalApi] = useVbenModal({
|
||||
connectedComponent: DefectRecordInlineList,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 缺陷记录变更后,刷新本表格并通知父组件刷新主表统计 */
|
||||
function handleDefectChanged() {
|
||||
handleRefresh();
|
||||
emit('refresh');
|
||||
}
|
||||
|
||||
/** 打开缺陷记录弹窗 */
|
||||
function handleOpenDefect(row: MesQcIqcLineApi.IqcLine) {
|
||||
defectModalApi
|
||||
.setData({
|
||||
formType: props.formType,
|
||||
lineId: row.id,
|
||||
qcId: props.iqcId,
|
||||
qcType: MesQcTypeEnum.IQC,
|
||||
})
|
||||
.open();
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: useLineGridColumns(),
|
||||
height: 360,
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
if (!props.iqcId) {
|
||||
return { list: [], total: 0 };
|
||||
}
|
||||
return await getIqcLinePage({
|
||||
iqcId: props.iqcId,
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesQcIqcLineApi.IqcLine>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<DefectModal @success="handleDefectChanged" />
|
||||
<Grid table-title="检验项">
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '缺陷列表',
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.VIEW,
|
||||
onClick: handleOpenDefect.bind(null, row),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
</template>
|
||||
Loading…
Reference in New Issue