<template>
|
<div>
|
<el-dialog
|
v-model="dialogVisible"
|
title="快速检验"
|
width="70%"
|
@close="closeDialog"
|
>
|
<el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
|
<el-row :gutter="30">
|
<el-col :span="12">
|
<el-form-item label="检测结果:" prop="checkResult">
|
<el-select v-model="form.checkResult" placeholder="请选择检测结果" style="width: 100%" @change="handleCheckResultChange">
|
<el-option label="合格" value="合格" />
|
<el-option label="不合格" value="不合格" />
|
<el-option label="部分合格" value="部分合格" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="指标选择:" prop="testStandardId">
|
<el-select v-model="form.testStandardId" placeholder="请选择指标" style="width: 100%" @change="handleTestStandardChange">
|
<el-option
|
v-for="item in testStandardOptions"
|
:key="item.id"
|
:label="item.standardName || item.standardNo"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<template v-if="form.checkResult">
|
<el-row :gutter="30">
|
<el-col :span="12">
|
<el-form-item label="数量:" prop="quantity">
|
<el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.quantity" placeholder="请输入数量" clearable :precision="2" @change="handleQuantityChange"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="检测单位:" prop="checkCompany">
|
<el-input v-model="form.checkCompany" placeholder="请输入检测单位" clearable/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="30">
|
<el-col :span="12">
|
<el-form-item label="合格数量:" prop="qualifiedQuantity">
|
<el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.qualifiedQuantity" placeholder="请输入合格数量" clearable :precision="2" @change="handleQualifiedQuantityChange"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="不合格数量:" prop="unqualifiedQuantity">
|
<el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.unqualifiedQuantity" placeholder="请输入不合格数量" clearable :precision="2" @change="handleUnqualifiedQuantityChange"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="30">
|
<el-col :span="12">
|
<el-form-item label="入库比例(%):" prop="stockInRatio">
|
<el-input-number :step="0.01" :min="0" :max="100" style="width: 100%" v-model="form.stockInRatio" placeholder="请输入入库比例" clearable :precision="2" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="30">
|
<el-col :span="12">
|
<el-form-item label="检验员:" prop="checkName">
|
<el-select v-model="form.checkName" placeholder="请选择检验员" clearable style="width: 100%">
|
<el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" :value="item.nickName"/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="检测日期:" prop="checkTime">
|
<el-date-picker
|
v-model="form.checkTime"
|
type="date"
|
placeholder="请选择检测日期"
|
value-format="YYYY-MM-DD"
|
format="YYYY-MM-DD"
|
clearable
|
style="width: 100%"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</template>
|
</el-form>
|
<PIMTable
|
rowKey="id"
|
:column="tableColumn"
|
:tableData="tableData"
|
:tableLoading="tableLoading"
|
height="400"
|
>
|
<template #slot="{ row }">
|
<el-input v-model="row.testValue" clearable/>
|
</template>
|
</PIMTable>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="submitForm">确认</el-button>
|
<el-button @click="closeDialog">取消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, reactive, toRefs, getCurrentInstance, nextTick } from "vue";
|
import { userListNoPage } from "@/api/system/user.js";
|
import { batchQuickInspect } from "@/api/qualityManagement/rawMaterialInspection.js";
|
import { qualityInspectDetailByProductId, getQualityTestStandardParamByTestStandardId } from "@/api/qualityManagement/metricMaintenance.js";
|
|
const { proxy } = getCurrentInstance();
|
const emit = defineEmits(['close', 'success']);
|
|
const dialogVisible = ref(false);
|
const userList = ref([]);
|
const selectedIds = ref([]);
|
const selectedRows = ref([]);
|
const testStandardOptions = ref([]);
|
const inspectType = ref(0); // 原材料检验类型
|
|
const data = reactive({
|
form: {
|
checkResult: '',
|
testStandardId: '',
|
quantity: undefined,
|
qualifiedQuantity: undefined,
|
unqualifiedQuantity: undefined,
|
stockInRatio: 100.00,
|
checkCompany: '',
|
checkName: '',
|
checkTime: '',
|
},
|
rules: {
|
checkResult: [{ required: true, message: "请选择检测结果", trigger: "change" }],
|
testStandardId: [{ required: true, message: "请选择指标", trigger: "change" }],
|
quantity: [{ required: true, message: "请输入数量", trigger: "blur" }],
|
qualifiedQuantity: [{ required: true, message: "请输入合格数量", trigger: "blur" }],
|
unqualifiedQuantity: [{ required: true, message: "请输入不合格数量", trigger: "blur" }],
|
checkCompany: [{ required: true, message: "请输入检测单位", trigger: "blur" }],
|
checkName: [{ required: true, message: "请选择检验员", trigger: "change" }],
|
checkTime: [{ required: true, message: "请选择检测日期", trigger: "change" }],
|
stockInRatio: [
|
{
|
validator: (rule, value, callback) => {
|
if (value !== null && value !== undefined && value !== '') {
|
if (value < 0 || value > 100) {
|
callback(new Error('入库比例范围0~100'));
|
} else {
|
callback();
|
}
|
} else {
|
callback();
|
}
|
},
|
trigger: 'blur'
|
}
|
],
|
},
|
});
|
const { form, rules } = toRefs(data);
|
|
const tableColumn = ref([
|
{
|
label: "指标",
|
prop: "parameterItem",
|
},
|
{
|
label: "单位",
|
prop: "unit",
|
},
|
{
|
label: "标准值",
|
prop: "standardValue",
|
},
|
{
|
label: "内控值",
|
prop: "controlValue",
|
},
|
{
|
label: "检验值",
|
prop: "testValue",
|
dataType: 'slot',
|
slot: 'slot',
|
},
|
]);
|
const tableData = ref([]);
|
const tableLoading = ref(false);
|
|
// 打开弹框
|
const openDialog = async (ids, rows) => {
|
selectedIds.value = ids;
|
selectedRows.value = rows;
|
dialogVisible.value = true;
|
|
// 加载用户列表
|
const userListsRes = await userListNoPage();
|
userList.value = userListsRes.data;
|
|
// 加载指标选项(根据第一个选中行的产品ID)
|
if (rows && rows.length > 0 && rows[0].productId) {
|
const params = {
|
productId: rows[0].productId,
|
inspectType: 0
|
};
|
const res = await qualityInspectDetailByProductId(params);
|
testStandardOptions.value = res.data || [];
|
} else {
|
testStandardOptions.value = [];
|
}
|
|
// 重置表单
|
form.value = {
|
checkResult: '',
|
testStandardId: '',
|
quantity: undefined,
|
qualifiedQuantity: undefined,
|
unqualifiedQuantity: undefined,
|
stockInRatio: 100.00,
|
checkCompany: '',
|
checkName: '',
|
checkTime: '',
|
};
|
tableData.value = [];
|
|
await nextTick();
|
proxy.$refs.formRef?.clearValidate();
|
};
|
|
// 指标选择变化处理
|
const handleTestStandardChange = async (testStandardId) => {
|
if (!testStandardId) {
|
tableData.value = [];
|
return;
|
}
|
tableLoading.value = true;
|
try {
|
const res = await getQualityTestStandardParamByTestStandardId(testStandardId);
|
tableData.value = (res.data || []).map(item => ({
|
...item,
|
id: null,
|
testValue: ''
|
}));
|
} catch (error) {
|
console.error('获取标准参数失败:', error);
|
tableData.value = [];
|
} finally {
|
tableLoading.value = false;
|
}
|
};
|
|
// 检测结果变化处理
|
const handleCheckResultChange = (value) => {
|
if (value === '合格') {
|
// 合格时,合格数量等于数量,不合格数量为0
|
form.value.qualifiedQuantity = form.value.quantity || 0;
|
form.value.unqualifiedQuantity = 0;
|
} else if (value === '不合格') {
|
// 不合格时,合格数量为0,不合格数量等于数量
|
form.value.qualifiedQuantity = 0;
|
form.value.unqualifiedQuantity = form.value.quantity || 0;
|
}
|
};
|
|
// 数量变化处理
|
const handleQuantityChange = (value) => {
|
if (form.value.checkResult === '合格') {
|
form.value.qualifiedQuantity = value || 0;
|
form.value.unqualifiedQuantity = 0;
|
} else if (form.value.checkResult === '不合格') {
|
form.value.qualifiedQuantity = 0;
|
form.value.unqualifiedQuantity = value || 0;
|
}
|
};
|
|
// 合格数量变化处理
|
const handleQualifiedQuantityChange = (value) => {
|
const quantity = form.value.quantity || 0;
|
if (value > quantity) {
|
proxy.$modal.msgWarning("合格数量不能大于总数量");
|
form.value.qualifiedQuantity = quantity;
|
form.value.unqualifiedQuantity = 0;
|
} else {
|
form.value.unqualifiedQuantity = Number((quantity - value).toFixed(2));
|
}
|
updateCheckResult();
|
};
|
|
// 不合格数量变化处理
|
const handleUnqualifiedQuantityChange = (value) => {
|
const quantity = form.value.quantity || 0;
|
if (value > quantity) {
|
proxy.$modal.msgWarning("不合格数量不能大于总数量");
|
form.value.unqualifiedQuantity = quantity;
|
form.value.qualifiedQuantity = 0;
|
} else {
|
form.value.qualifiedQuantity = Number((quantity - value).toFixed(2));
|
}
|
updateCheckResult();
|
};
|
|
// 根据合格/不合格数量更新检测结果
|
const updateCheckResult = () => {
|
const qualified = form.value.qualifiedQuantity || 0;
|
const unqualified = form.value.unqualifiedQuantity || 0;
|
const quantity = form.value.quantity || 0;
|
|
if (qualified === quantity && unqualified === 0) {
|
form.value.checkResult = '合格';
|
} else if (unqualified === quantity && qualified === 0) {
|
form.value.checkResult = '不合格';
|
} else if (qualified > 0 && unqualified > 0) {
|
form.value.checkResult = '部分合格';
|
}
|
};
|
|
// 提交表单
|
const submitForm = () => {
|
proxy.$refs.formRef.validate((valid) => {
|
if (valid) {
|
const data = {
|
ids: selectedIds.value,
|
inspectType: inspectType.value,
|
...form.value,
|
paramList: tableData.value
|
};
|
batchQuickInspect(data).then(res => {
|
proxy.$modal.msgSuccess(res.msg || "快速检验完成");
|
emit('success');
|
closeDialog();
|
});
|
}
|
});
|
};
|
|
// 关闭弹框
|
const closeDialog = () => {
|
dialogVisible.value = false;
|
emit('close');
|
};
|
|
defineExpose({
|
openDialog,
|
});
|
</script>
|
|
<style scoped>
|
</style>
|