feat: implement dynamic inspection requirement logic based on material master data

This commit is contained in:
DXC
2026-03-17 11:56:04 +08:00
parent 368298a29d
commit c1c494893f
8 changed files with 273 additions and 14 deletions

View File

@ -146,6 +146,17 @@
</template>
</template>
<!-- 批量质检设置按钮 (需要 operation 权限) -->
<el-button
v-if="userStore.hasPermission('material_list:operation')"
type="danger"
plain
@click="openBatchInspectionDialog"
style="margin-right: 10px"
>
<el-icon style="margin-right: 5px"><CircleCheck /></el-icon>批量质检设置
</el-button>
<el-button v-if="userStore.hasPermission('material_list:operation')" type="primary" @click="handleAdd" style="margin-right: 10px">
<el-icon style="margin-right: 5px"><Plus /></el-icon>新增
</el-button>
@ -295,6 +306,13 @@
/>
</template>
</el-table-column>
<el-table-column v-if="columns.isInspectionRequired.visible" prop="isInspectionRequired" label="强制质检" min-width="100" align="center">
<template #default="scope">
<el-tag :type="scope.row.isInspectionRequired ? 'danger' : 'info'" size="small">
{{ scope.row.isInspectionRequired ? '是' : '否' }}
</el-tag>
</template>
</el-table-column>
<el-table-column v-if="userStore.hasPermission('material_list:operation')" label="操作" min-width="200" fixed="right" align="center">
<template #default="scope">
<el-button v-if="userStore.hasPermission('material_list:operation')" link type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
@ -526,13 +544,41 @@
</div>
</template>
</el-dialog>
<!-- 批量质检设置弹窗 -->
<el-dialog v-model="inspectionDialog.visible" title="批量质检设置" width="500px" append-to-body destroy-on-close>
<el-alert
:title="`已选择 ${inspectionDialog.selectedCount} 条物料进行批量质检设置`"
type="info"
:closable="false"
style="margin-bottom: 20px"
/>
<el-form label-width="180px">
<el-form-item label="是否强制要求入库上传检测报告">
<el-switch
v-model="inspectionForm.isInspectionRequired"
active-text=""
inactive-text=""
/>
</el-form-item>
<div style="color: #909399; font-size: 12px; margin-top: -10px;">
开启后,这些物料在采购入库时必须上传检测报告或外部链接
</div>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button @click="inspectionDialog.visible = false">取 消</el-button>
<el-button type="primary" @click="submitBatchInspection" :loading="inspectionLoading">确 定</el-button>
</div>
</template>
</el-dialog>
</el-card>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, nextTick, computed } from 'vue';
import { Plus, Document, Refresh, Setting, Rank, Camera, Link, Download, Bell } from '@element-plus/icons-vue';
import { Plus, Document, Refresh, Setting, Rank, Camera, Link, Download, Bell, CircleCheck } from '@element-plus/icons-vue';
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { useUserStore } from '@/stores/user';
@ -544,7 +590,8 @@ import {
delMaterialBase,
getMaterialBaseOptions,
exportAssetStatistics,
batchSetWarning
batchSetWarning,
batchSetInspection
} from '@/api/material_base';
import { uploadFile, deleteFile } from '@/api/common/upload';
import WebRtcCamera from '@/components/Camera/WebRtcCamera.vue';
@ -691,6 +738,17 @@ const warningRules = {
]
};
// 批量质检设置相关
const inspectionDialog = reactive({
visible: false,
selectedCount: 0,
selectedIds: [] as number[]
});
const inspectionLoading = ref(false);
const inspectionForm = reactive({
isInspectionRequired: false
});
const columns = reactive({
id: { visible: false },
companyName: { visible: true },
@ -703,7 +761,8 @@ const columns = reactive({
inventory: { visible: true },
available: { visible: true },
files: { visible: true },
isEnabled: { visible: true }
isEnabled: { visible: true },
isInspectionRequired: { visible: true }
});
// 列与权限Code的映射关系数据库中的code
@ -719,7 +778,8 @@ const permissionMap: Record<string, string> = {
inventory: 'material_list:inventoryCount',
available: 'material_list:availableCount',
files: 'material_list:files',
isEnabled: 'material_list:isEnabled'
isEnabled: 'material_list:isEnabled',
isInspectionRequired: 'material_list:operation'
};
// 根据用户权限初始化列显示状态
@ -1247,6 +1307,47 @@ const submitWarning = async () => {
}
};
// 打开批量质检设置对话框
const openBatchInspectionDialog = () => {
// 获取当前勾选的物料
const selected = tableRef.value?.getSelectionRows() || [];
if (selected.length === 0) {
ElMessage.warning('请先勾选需要设置质检的物料');
return;
}
inspectionDialog.selectedIds = selected.map((row: MaterialBaseVO) => row.id);
inspectionDialog.selectedCount = selected.length;
inspectionForm.isInspectionRequired = false; // 默认重置为否
inspectionDialog.visible = true;
};
// 提交批量质检设置
const submitBatchInspection = async () => {
if (inspectionDialog.selectedIds.length === 0) {
ElMessage.warning('请先勾选物料');
return;
}
inspectionLoading.value = true;
try {
await batchSetInspection({
ids: inspectionDialog.selectedIds,
isInspectionRequired: inspectionForm.isInspectionRequired
});
ElMessage.success('批量质检设置成功');
inspectionDialog.visible = false;
selectedItems.value = [];
tableRef.value?.clearSelection();
getList();
} catch (error: any) {
ElMessage.error(error?.msg || '设置失败');
} finally {
inspectionLoading.value = false;
}
};
// 表格行样式(根据预警状态)
const tableRowClassName = ({ row }: { row: MaterialBaseVO }) => {
// 只有拥有 view_warning 权限且有预警状态时才显示特殊样式