<template>
|
<div class="app-container">
|
<div class="search_form">
|
<div>
|
<span class="search_title">产品名称:</span>
|
<el-input
|
v-model="searchForm.productName"
|
style="width: 240px"
|
placeholder="请输入产品名称搜索"
|
@change="handleQuery"
|
clearable
|
:prefix-icon="Search"
|
/>
|
<span style="margin-left: 10px" class="search_title">检测日期:</span>
|
<el-date-picker v-model="searchForm.entryDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="daterange"
|
placeholder="请选择" clearable @change="changeDaterange" />
|
<el-button type="primary" @click="handleQuery" style="margin-left: 10px"
|
>搜索</el-button
|
>
|
</div>
|
<div>
|
<el-button type="primary" @click="openForm('add')">新增</el-button>
|
<el-button @click="handleOut">导出</el-button>
|
<el-button type="danger" plain @click="handleDelete">删除</el-button>
|
</div>
|
</div>
|
<div class="table_list">
|
<PIMTable
|
rowKey="id"
|
:column="tableColumn"
|
:tableData="tableData"
|
:page="page"
|
:isSelection="true"
|
@selection-change="handleSelectionChange"
|
:tableLoading="tableLoading"
|
@pagination="pagination"
|
:total="page.total"
|
></PIMTable>
|
</div>
|
<InspectionFormDia ref="inspectionFormDia" @close="handleQuery"></InspectionFormDia>
|
<FormDia ref="formDia" @close="handleQuery"></FormDia>
|
<files-dia ref="filesDia" @close="handleQuery"></files-dia>
|
<!-- 检验结果选择对话框 -->
|
<el-dialog v-model="quickCheckVisible" title="检验" width="40%" @close="closeQuickCheck">
|
<el-form :model="quickCheckForm" label-width="140px" label-position="top" ref="quickCheckRef">
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="检测结果:" required>
|
<el-radio-group v-model="quickCheckForm.checkResult">
|
<el-radio value="合格">合格</el-radio>
|
<el-radio value="不合格">不合格</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="检验员:" required>
|
<el-select v-model="quickCheckForm.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-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="检测日期:" required>
|
<el-date-picker
|
v-model="quickCheckForm.checkTime"
|
type="date"
|
placeholder="请选择日期"
|
value-format="YYYY-MM-DD"
|
format="YYYY-MM-DD"
|
clearable
|
style="width: 100%"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="指标选择:">
|
<el-select
|
v-model="quickCheckForm.testStandardId"
|
placeholder="请选择指标"
|
clearable
|
@change="handleTestStandardChange"
|
style="width: 100%"
|
>
|
<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>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="检测单位:">
|
<el-input v-model="quickCheckForm.checkCompany" placeholder="请输入" clearable style="width: 100%"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<!-- 检验值表格 -->
|
<el-form-item label="检验值:" v-if="quickCheckTableData.length > 0">
|
<PIMTable
|
rowKey="id"
|
:column="quickCheckTableColumn"
|
:tableData="quickCheckTableData"
|
:tableLoading="quickCheckTableLoading"
|
height="200"
|
>
|
<template #slot="{ row }">
|
<el-input v-model="row.testValue" clearable placeholder="请输入检验值"/>
|
</template>
|
</PIMTable>
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="handleQuickCheckConfirm">确认</el-button>
|
<el-button @click="closeQuickCheck">取消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
<el-dialog v-model="dialogFormVisible" title="编辑检验员" width="30%"
|
@close="closeDia">
|
<el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
|
<el-form-item label="检验员:" prop="checkName">
|
<el-select v-model="form.checkName" placeholder="请选择" clearable>
|
<el-option v-for="item in userList" :key="item.nickName" :label="item.nickName"
|
:value="item.nickName"/>
|
</el-select>
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="submitForm">确认</el-button>
|
<el-button @click="closeDia">取消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { Search } from "@element-plus/icons-vue";
|
import {onMounted, ref, reactive, toRefs, getCurrentInstance, nextTick} from "vue";
|
import InspectionFormDia from "@/views/qualityManagement/finalInspection/components/inspectionFormDia.vue";
|
import FormDia from "@/views/qualityManagement/finalInspection/components/formDia.vue";
|
import {ElMessageBox} from "element-plus";
|
import {
|
downloadQualityInspect,
|
qualityInspectDel,
|
qualityInspectDetail,
|
qualityInspectListPage, qualityInspectUpdate,
|
submitQualityInspect,
|
qualityInspectExportNew
|
} from "@/api/qualityManagement/rawMaterialInspection.js";
|
import {qualityInspectDetailByProductId, getQualityTestStandardParamByTestStandardId} from "@/api/qualityManagement/metricMaintenance.js";
|
import FilesDia from "@/views/qualityManagement/finalInspection/components/filesDia.vue";
|
import dayjs from "dayjs";
|
import {userListNoPage} from "@/api/system/user.js";
|
import useUserStore from "@/store/modules/user";
|
|
const data = reactive({
|
searchForm: {
|
productName: "",
|
entryDate: undefined, // 录入日期
|
entryDateStart: undefined,
|
entryDateEnd: undefined,
|
},
|
rules: {
|
checkName: [{required: true, message: "请选择", trigger: "change"}],
|
},
|
});
|
const { searchForm } = toRefs(data);
|
const tableColumn = ref([
|
{
|
label: "检测日期",
|
prop: "checkTime",
|
width: 120
|
},
|
{
|
label: "生产工单号",
|
prop: "workOrderNo",
|
width: 120
|
},
|
{
|
label: "检验员",
|
prop: "checkName",
|
},
|
{
|
label: "产品名称",
|
prop: "productName",
|
},
|
{
|
label: "规格型号",
|
prop: "model",
|
},
|
{
|
label: "单位",
|
prop: "unit",
|
},
|
{
|
label: "数量",
|
prop: "quantity",
|
width: 100
|
},
|
{
|
label: "检测单位",
|
prop: "checkCompany",
|
width: 120
|
},
|
{
|
label: "检测结果",
|
prop: "checkResult",
|
dataType: "tag",
|
formatType: (params) => {
|
if (params == '不合格') {
|
return "danger";
|
} else if (params == '合格') {
|
return "success";
|
} else {
|
return null;
|
}
|
},
|
},
|
{
|
label: "提交状态",
|
prop: "inspectState",
|
formatData: (params) => {
|
if (params) {
|
return "已提交";
|
} else {
|
return "未提交";
|
}
|
},
|
},
|
{
|
dataType: "action",
|
label: "操作",
|
align: "center",
|
fixed: "right",
|
width: 280,
|
operation: [
|
{
|
name: "检验",
|
type: "text",
|
clickFun: (row) => {
|
openQuickCheck(row);
|
},
|
disabled: (row) => {
|
// 已提交则禁用
|
if (row.inspectState == 1) return true;
|
// 如果检验员有值,只有当前登录用户能编辑
|
if (row.checkName) {
|
return row.checkName !== userStore.nickName;
|
}
|
return false;
|
}
|
},
|
{
|
name: "附件",
|
type: "text",
|
clickFun: (row) => {
|
openFilesFormDia(row);
|
},
|
},
|
{
|
name: "提交",
|
type: "text",
|
clickFun: (row) => {
|
submit(row.id);
|
},
|
disabled: (row) => {
|
// 已提交则禁用
|
if (row.inspectState == 1) return true;
|
// 如果检验员有值,只有当前登录用户能提交
|
if (row.checkName) {
|
return row.checkName !== userStore.nickName;
|
}
|
return false;
|
}
|
},
|
{
|
name: "分配检验员",
|
type: "text",
|
clickFun: (row) => {
|
if (!row.checkName) {
|
open(row)
|
} else {
|
proxy.$modal.msgError("检验员已存在");
|
}
|
},
|
disabled: (row) => {
|
return row.inspectState == 1 || row.checkName;
|
}
|
},
|
{
|
name: "下载",
|
type: "text",
|
clickFun: (row) => {
|
downLoadFile(row);
|
},
|
},
|
],
|
},
|
]);
|
const tableData = ref([]);
|
const selectedRows = ref([]);
|
const tableLoading = ref(false);
|
const currentRow = ref(null)
|
const page = reactive({
|
current: 1,
|
size: 100,
|
total: 0
|
});
|
const formDia = ref()
|
const filesDia = ref()
|
const inspectionFormDia = ref()
|
const { proxy } = getCurrentInstance()
|
const userStore = useUserStore()
|
const userList = ref([]);
|
const form = ref({
|
checkName: ""
|
});
|
const dialogFormVisible = ref(false);
|
const quickCheckVisible = ref(false);
|
const quickCheckForm = ref({
|
checkResult: "合格",
|
checkName: "",
|
checkTime: "",
|
testStandardId: "",
|
checkCompany: ""
|
});
|
const quickCheckRef = ref(null);
|
const testStandardOptions = ref([]); // 指标选择下拉框数据
|
const quickCheckTableColumn = ref([
|
{
|
label: "指标",
|
prop: "parameterItem",
|
},
|
{
|
label: "单位",
|
prop: "unit",
|
},
|
{
|
label: "标准值",
|
prop: "standardValue",
|
},
|
{
|
label: "内控值",
|
prop: "controlValue",
|
},
|
{
|
label: "检验值",
|
prop: "testValue",
|
dataType: 'slot',
|
slot: 'slot',
|
},
|
]);
|
const quickCheckTableData = ref([]);
|
const quickCheckTableLoading = ref(false);
|
|
const changeDaterange = (value) => {
|
searchForm.value.entryDateStart = undefined;
|
searchForm.value.entryDateEnd = undefined;
|
if (value) {
|
searchForm.value.entryDateStart = dayjs(value[0]).format("YYYY-MM-DD");
|
searchForm.value.entryDateEnd = dayjs(value[1]).format("YYYY-MM-DD");
|
}
|
getList();
|
};
|
// 查询列表
|
/** 搜索按钮操作 */
|
const handleQuery = () => {
|
page.current = 1;
|
getList();
|
};
|
const pagination = (obj) => {
|
page.current = obj.page;
|
page.size = obj.limit;
|
getList();
|
};
|
const getList = () => {
|
tableLoading.value = true;
|
const params = { ...searchForm.value, ...page };
|
params.entryDate = undefined
|
qualityInspectListPage({...params, inspectType: 2}).then(res => {
|
tableLoading.value = false;
|
tableData.value = res.data.records
|
page.total = res.data.total;
|
}).catch(err => {
|
tableLoading.value = false;
|
})
|
};
|
// 表格选择数据
|
const handleSelectionChange = (selection) => {
|
selectedRows.value = selection;
|
};
|
|
// 打开弹框
|
const openForm = (type, row) => {
|
nextTick(() => {
|
formDia.value?.openDialog(type, row)
|
})
|
};
|
// 打开新增检验弹框
|
const openInspectionForm = (type, row) => {
|
nextTick(() => {
|
inspectionFormDia.value?.openDialog(type, row)
|
})
|
};
|
// 打开附件弹框
|
const openFilesFormDia = (type, row) => {
|
nextTick(() => {
|
filesDia.value?.openDialog(type, row)
|
})
|
};
|
|
// 删除
|
const handleDelete = () => {
|
let ids = [];
|
if (selectedRows.value.length > 0) {
|
ids = selectedRows.value.map((item) => item.id);
|
} else {
|
proxy.$modal.msgWarning("请选择数据");
|
return;
|
}
|
ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "导出", {
|
confirmButtonText: "确认",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
qualityInspectDel(ids).then((res) => {
|
proxy.$modal.msgSuccess("删除成功");
|
getList();
|
});
|
})
|
.catch(() => {
|
proxy.$modal.msg("已取消");
|
});
|
};
|
// 导出
|
const handleOut = () => {
|
// 判断是否有选中数据
|
const hasSelected = selectedRows.value.length > 0;
|
|
const confirmMsg = hasSelected
|
? "选中的内容将被导出,是否确认导出?"
|
: "将导出全部数据,是否确认导出?";
|
|
ElMessageBox.confirm(confirmMsg, "导出", {
|
confirmButtonText: "确认",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
// 构建导出参数
|
const exportData = {
|
inspectType: 2,
|
productName: searchForm.value.productName || "",
|
entryDateStart: searchForm.value.entryDateStart || "",
|
entryDateEnd: searchForm.value.entryDateEnd || "",
|
};
|
|
// 如果有选中数据,添加ids
|
if (hasSelected) {
|
exportData.ids = selectedRows.value.map(item => item.id);
|
}
|
|
// 调用新导出接口
|
qualityInspectExportNew(exportData).then((blobData) => {
|
const blob = new Blob([blobData], {
|
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
});
|
const downloadUrl = window.URL.createObjectURL(blob);
|
const link = document.createElement('a');
|
link.href = downloadUrl;
|
link.download = '出厂检验.xlsx';
|
document.body.appendChild(link);
|
link.click();
|
document.body.removeChild(link);
|
window.URL.revokeObjectURL(downloadUrl);
|
}).catch((error) => {
|
proxy.$modal.msgError("导出失败");
|
});
|
})
|
.catch(() => {
|
proxy.$modal.msg("已取消");
|
});
|
};
|
|
// 提价
|
const submit = async (id) => {
|
const res = await submitQualityInspect({id: id})
|
if (res.code === 200) {
|
proxy.$modal.msgSuccess("提交成功");
|
getList();
|
}
|
}
|
|
// 关闭弹框
|
const closeDia = () => {
|
proxy.resetForm("formRef");
|
dialogFormVisible.value = false;
|
};
|
|
const submitForm = () => {
|
if (currentRow.value) {
|
const data = {
|
...form.value,
|
id: currentRow.value.id
|
}
|
qualityInspectUpdate(data).then(res => {
|
proxy.$modal.msgSuccess("提交成功");
|
closeDia();
|
getList();
|
})
|
}
|
};
|
|
const open = async (row) => {
|
let userLists = await userListNoPage();
|
// 筛选 roleIds 包含 106 的用户
|
userList.value = (userLists.data || []).filter(user => {
|
const roleIds = user.roleIds || [];
|
return roleIds.includes(106) || roleIds.includes('106');
|
});
|
currentRow.value = row
|
dialogFormVisible.value = true
|
}
|
|
const downLoadFile = (row) => {
|
downloadQualityInspect({ id: row.id }).then((blobData) => {
|
const blob = new Blob([blobData], {
|
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
})
|
const downloadUrl = window.URL.createObjectURL(blob)
|
|
const link = document.createElement('a')
|
link.href = downloadUrl
|
link.download = '出厂检验报告.docx'
|
document.body.appendChild(link)
|
link.click()
|
|
document.body.removeChild(link)
|
window.URL.revokeObjectURL(downloadUrl)
|
})
|
};
|
|
// 打开检验结果选择对话框
|
const openQuickCheck = async (row) => {
|
// 先调用详情接口获取完整数据(包含指标和检验值)
|
let detailData = row;
|
try {
|
const detailRes = await qualityInspectDetail(row.id);
|
if (detailRes.code === 200 && detailRes.data) {
|
detailData = detailRes.data;
|
}
|
} catch (e) {
|
console.error("获取检验详情失败", e);
|
}
|
currentRow.value = detailData;
|
|
// 加载用户列表,筛选 roleIds 包含 106 的用户
|
try {
|
const userLists = await userListNoPage();
|
userList.value = (userLists.data || []).filter(user => {
|
const roleIds = user.roleIds || [];
|
return roleIds.includes(106) || roleIds.includes('106');
|
});
|
} catch (e) {
|
console.error("加载检验员列表失败", e);
|
userList.value = [];
|
}
|
// 加载指标选项(根据产品ID)
|
if (detailData.productId) {
|
try {
|
const params = {
|
productId: detailData.productId,
|
inspectType: 2
|
};
|
const res = await qualityInspectDetailByProductId(params);
|
testStandardOptions.value = res.data || [];
|
} catch (e) {
|
console.error("加载指标选项失败", e);
|
testStandardOptions.value = [];
|
}
|
} else {
|
testStandardOptions.value = [];
|
}
|
// 设置默认值(优先使用详情数据,检验员默认为当前登录用户)
|
quickCheckForm.value = {
|
checkResult: detailData.checkResult || "合格",
|
checkName: detailData.checkName || userStore.nickName || "",
|
checkTime: detailData.checkTime || dayjs().format("YYYY-MM-DD"),
|
testStandardId: detailData.testStandardId || "",
|
checkCompany: detailData.checkCompany || ""
|
};
|
// 如果有检验参数数据,回显到表格
|
if (detailData.qualityInspectParams && detailData.qualityInspectParams.length > 0) {
|
quickCheckTableData.value = detailData.qualityInspectParams;
|
} else {
|
quickCheckTableData.value = [];
|
}
|
quickCheckVisible.value = true;
|
};
|
|
// 指标选择变化处理
|
const handleTestStandardChange = (testStandardId) => {
|
if (!testStandardId) {
|
quickCheckTableData.value = [];
|
return;
|
}
|
quickCheckTableLoading.value = true;
|
getQualityTestStandardParamByTestStandardId(testStandardId).then(res => {
|
quickCheckTableData.value = res.data || [];
|
}).catch(error => {
|
console.error('获取标准参数失败:', error);
|
quickCheckTableData.value = [];
|
}).finally(() => {
|
quickCheckTableLoading.value = false;
|
});
|
};
|
|
// 关闭检验结果选择对话框
|
const closeQuickCheck = () => {
|
quickCheckVisible.value = false;
|
quickCheckForm.value = {
|
checkResult: "合格",
|
checkName: "",
|
checkTime: "",
|
testStandardId: "",
|
checkCompany: ""
|
};
|
quickCheckTableData.value = [];
|
testStandardOptions.value = [];
|
};
|
|
// 确认检验结果
|
const handleQuickCheckConfirm = () => {
|
if (!quickCheckForm.value.checkResult) {
|
proxy.$modal.msgWarning("请选择检测结果");
|
return;
|
}
|
if (!quickCheckForm.value.checkName) {
|
proxy.$modal.msgWarning("请选择检验员");
|
return;
|
}
|
if (!quickCheckForm.value.checkTime) {
|
proxy.$modal.msgWarning("请选择检测日期");
|
return;
|
}
|
|
const checkNameToPass = quickCheckForm.value.checkName;
|
const checkResultToPass = quickCheckForm.value.checkResult;
|
const checkTimeToPass = quickCheckForm.value.checkTime;
|
const testStandardIdToPass = quickCheckForm.value.testStandardId;
|
const checkCompanyToPass = quickCheckForm.value.checkCompany;
|
const qualityInspectParamsToPass = [...quickCheckTableData.value];
|
|
if (quickCheckForm.value.checkResult === "合格") {
|
// 合格:直接提交
|
const data = {
|
id: currentRow.value.id,
|
checkResult: "合格",
|
checkName: checkNameToPass,
|
checkTime: checkTimeToPass,
|
testStandardId: testStandardIdToPass,
|
checkCompany: checkCompanyToPass,
|
inspectType: 2,
|
qualityInspectParams: qualityInspectParamsToPass
|
};
|
qualityInspectUpdate(data).then(res => {
|
proxy.$modal.msgSuccess("检验成功");
|
closeQuickCheck();
|
getList();
|
});
|
} else {
|
// 不合格:打开详细填写页面
|
closeQuickCheck();
|
nextTick(() => {
|
currentRow.value.checkTime = checkTimeToPass;
|
currentRow.value.checkCompany = checkCompanyToPass;
|
currentRow.value.testStandardId = testStandardIdToPass;
|
formDia.value?.openDialog("edit", currentRow.value, checkResultToPass, checkNameToPass, testStandardIdToPass, checkCompanyToPass, qualityInspectParamsToPass);
|
});
|
}
|
};
|
|
onMounted(() => {
|
getList();
|
});
|
</script>
|
|
<style scoped></style>
|