From d95c8b4acaa7741fdeee630940011b3621a0582a Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期二, 07 四月 2026 14:18:39 +0800
Subject: [PATCH] fix: 修复表格列格式化逻辑和汇总计算错误
---
src/views/qualityManagement/rawMaterialInspection/components/formDia.vue | 149 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 127 insertions(+), 22 deletions(-)
diff --git a/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue b/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue
index 5ea1e47..537b24b 100644
--- a/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue
+++ b/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue
@@ -26,23 +26,33 @@
</el-col>
<el-col :span="12">
<el-form-item label="浜у搧鍚嶇О锛�" prop="productId">
- <el-tree-select
- v-model="form.productId"
- placeholder="璇烽�夋嫨"
- clearable
- check-strictly
- @change="getModels"
- :data="productOptions"
- :render-after-expand="false"
- style="width: 100%"
- />
+ <el-tree-select v-model="form.productId" placeholder="璇烽�夋嫨" clearable check-strictly
+ @change="getModels" :data="productOptions" :render-after-expand="false" style="width: 100%" />
</el-form-item>
</el-col>
- </el-row>
- <el-row :gutter="30">
<el-col :span="12">
- <el-form-item label="瑙勬牸鍨嬪彿锛�" prop="model">
- <el-input v-model="form.model" placeholder="璇疯緭鍏�" clearable/>
+ <el-form-item label="瑙勬牸鍨嬪彿锛�" prop="productModelId">
+ <el-select v-model="form.productModelId" placeholder="璇烽�夋嫨" clearable @change="getProductModel" style="width: 100%">
+ <el-option v-for="item in modelOptions" :key="item.id" :label="item.model" :value="item.id" />
+ </el-select>
+ </el-form-item>
+ </el-col>
+ <el-col :span="12">
+ <el-form-item label="鎸囨爣閫夋嫨锛�" prop="testStandardId">
+ <el-select
+ v-model="form.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>
@@ -121,13 +131,13 @@
</template>
<script setup>
-import {ref} from "vue";
+import {ref, reactive, toRefs, getCurrentInstance, nextTick} from "vue";
import {getOptions} from "@/api/procurementManagement/procurementLedger.js";
-import {productTreeList} from "@/api/basicData/product.js";
+import {modelList, productTreeList} from "@/api/basicData/product.js";
import {qualityInspectAdd, qualityInspectUpdate} from "@/api/qualityManagement/rawMaterialInspection.js";
import {ElMessageBox} from "element-plus";
import {qualityInspectParamDel, qualityInspectParamInfo} from "@/api/qualityManagement/qualityInspectParam.js";
-import {qualityInspectDetailByProductId} from "@/api/qualityManagement/metricMaintenance.js";
+import {qualityInspectDetailByProductId, getQualityTestStandardParamByTestStandardId} from "@/api/qualityManagement/metricMaintenance.js";
const {proxy} = getCurrentInstance()
const emit = defineEmits(['close'])
@@ -141,7 +151,9 @@
checkName: "",
productName: "",
productId: "",
+ productModelId: "",
model: "",
+ testStandardId: "",
unit: "",
quantity: "",
checkCompany: "",
@@ -152,7 +164,9 @@
supplier: [{required: true, message: "璇疯緭鍏�", trigger: "blur"}],
checkName: [{required: false, message: "璇疯緭鍏�", trigger: "blur"}],
productId: [{required: true, message: "璇疯緭鍏�", trigger: "blur"}],
+ productModelId: [{required: true, message: "璇烽�夋嫨瑙勬牸鍨嬪彿", trigger: "change"}],
model: [{required: false, message: "璇疯緭鍏�", trigger: "blur"}],
+ testStandardId: [{required: true, message: "璇烽�夋嫨鎸囨爣", trigger: "change"}],
unit: [{required: false, message: "璇疯緭鍏�", trigger: "blur"}],
quantity: [{required: true, message: "璇疯緭鍏�", trigger: "blur"}],
checkCompany: [{required: false, message: "璇疯緭鍏�", trigger: "blur"}],
@@ -189,7 +203,9 @@
const {form, rules} = toRefs(data);
const supplierList = ref([]);
const productOptions = ref([]);
+const modelOptions = ref([]);
const currentProductId = ref(0);
+const testStandardOptions = ref([]); // 鎸囨爣閫夋嫨涓嬫媺妗嗘暟鎹�
// 鎵撳紑寮规
const openDialog = (type, row) => {
@@ -199,11 +215,51 @@
supplierList.value = res.data;
});
form.value = {}
+ testStandardOptions.value = [];
+ tableData.value = [];
+ modelOptions.value = [];
getProductOptions();
if (operationType.value === 'edit') {
+ // 鍏堜繚瀛� testStandardId锛岄伩鍏嶈娓呯┖
+ const savedTestStandardId = row.testStandardId;
form.value = {...row}
currentProductId.value = row.productId || 0
- getQualityInspectParamList(row.id)
+ // 缂栬緫妯″紡涓嬶紝鍏堝姞杞芥寚鏍囬�夐」锛岀劧鍚庡姞杞藉弬鏁板垪琛�
+ if (currentProductId.value) {
+ // 鍔犺浇瑙勬牸鍨嬪彿閫夐」
+ modelList({ id: currentProductId.value }).then((res) => {
+ modelOptions.value = res;
+ });
+ // 鍏堝姞杞芥寚鏍囬�夐」
+ let params = {
+ productId: currentProductId.value,
+ inspectType: 0
+ }
+ qualityInspectDetailByProductId(params).then(res => {
+ testStandardOptions.value = res.data || [];
+ // 浣跨敤 nextTick 鍜� setTimeout 纭繚閫夐」宸茬粡娓叉煋鍒� DOM
+ nextTick(() => {
+ setTimeout(() => {
+ if (savedTestStandardId) {
+ // 纭繚绫诲瀷鍖归厤锛坕tem.id 鍙兘鏄暟瀛楁垨瀛楃涓诧級
+ const matchedOption = testStandardOptions.value.find(item =>
+ item.id == savedTestStandardId || String(item.id) === String(savedTestStandardId)
+ );
+ if (matchedOption) {
+ form.value.testStandardId = matchedOption.id;
+ } else {
+ console.warn('鏈壘鍒板尮閰嶇殑鎸囨爣閫夐」锛宼estStandardId:', savedTestStandardId, '鍙敤閫夐」:', testStandardOptions.value);
+ form.value.testStandardId = savedTestStandardId;
+ }
+ }
+ // 缂栬緫鏃跺缁堝姞杞戒繚瀛樼殑妫�楠屽弬鏁�
+ getQualityInspectParamList(row.id);
+ }, 100);
+ });
+ });
+ } else {
+ getQualityInspectParamList(row.id);
+ }
}
}
const getProductOptions = () => {
@@ -214,8 +270,24 @@
const getModels = (value) => {
currentProductId.value = value
form.value.productName = findNodeById(productOptions.value, value);
- if (currentProductId) {
+ modelOptions.value = [];
+ form.value.productModelId = "";
+ form.value.model = "";
+ if (currentProductId.value) {
+ modelList({ id: value }).then((res) => {
+ modelOptions.value = res;
+ });
getList();
+ }
+};
+const getProductModel = (value) => {
+ const index = modelOptions.value.findIndex((item) => item.id === value);
+ if (index !== -1) {
+ form.value.model = modelOptions.value[index].model;
+ form.value.unit = modelOptions.value[index].unit;
+ } else {
+ form.value.model = "";
+ form.value.unit = "";
}
};
const findNodeById = (nodes, productId) => {
@@ -275,8 +347,39 @@
}
const getList = () => {
- qualityInspectDetailByProductId(currentProductId.value).then(res => {
- tableData.value = res.data;
+ if (!currentProductId.value) {
+ testStandardOptions.value = [];
+ tableData.value = [];
+ return;
+ }
+ let params = {
+ productId: currentProductId.value,
+ inspectType: 0
+ }
+ qualityInspectDetailByProductId(params).then(res => {
+ // 淇濆瓨涓嬫媺妗嗛�夐」鏁版嵁
+ testStandardOptions.value = res.data || [];
+ // 娓呯┖琛ㄦ牸鏁版嵁锛岀瓑寰呯敤鎴烽�夋嫨鎸囨爣
+ tableData.value = [];
+ // 娓呯┖鎸囨爣閫夋嫨
+ form.value.testStandardId = '';
+ })
+}
+
+// 鎸囨爣閫夋嫨鍙樺寲澶勭悊
+const handleTestStandardChange = (testStandardId) => {
+ if (!testStandardId) {
+ tableData.value = [];
+ return;
+ }
+ tableLoading.value = true;
+ getQualityTestStandardParamByTestStandardId(testStandardId).then(res => {
+ tableData.value = res.data || [];
+ }).catch(error => {
+ console.error('鑾峰彇鏍囧噯鍙傛暟澶辫触:', error);
+ tableData.value = [];
+ }).finally(() => {
+ tableLoading.value = false;
})
}
@@ -288,7 +391,9 @@
// 鍏抽棴寮规
const closeDia = () => {
proxy.resetForm("formRef");
- tableData.value = []
+ tableData.value = [];
+ testStandardOptions.value = [];
+ form.value.testStandardId = '';
dialogFormVisible.value = false;
emit('close')
};
--
Gitblit v1.9.3