From 2e77330d87341624c88301562fd137b58f9a101a Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 25 十二月 2025 10:57:35 +0800
Subject: [PATCH] 1.海川开心-录入日期都默认当天,封装公用组件和方法

---
 src/views/qualityManagement/rawMaterialInspection/components/formDia.vue |  278 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 258 insertions(+), 20 deletions(-)

diff --git a/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue b/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue
index 5d2bcbc..d26eaf2 100644
--- a/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue
+++ b/src/views/qualityManagement/rawMaterialInspection/components/formDia.vue
@@ -2,19 +2,115 @@
   <div>
     <el-dialog
         v-model="dialogFormVisible"
-        :title="operationType === 'add' ? '鏂板鍏ヨ亴' : '缂栬緫浜哄憳'"
+        :title="operationType === 'add' ? '鏂板鍘熸潗鏂欐楠�' : '缂栬緫鍘熸潗鏂欐楠�'"
         width="70%"
         @close="closeDia"
     >
+      <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="supplier">
+              <el-select
+                  v-model="form.supplier"
+                  placeholder="璇烽�夋嫨"
+                  clearable
+									filterable
+              >
+                <el-option
+                    v-for="item in supplierList"
+                    :key="item.id"
+                    :label="item.supplierName"
+                    :value="item.supplierName"
+                />
+              </el-select>
+            </el-form-item>
+          </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-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>
+          </el-col>
+					<el-col :span="12">
+						<el-form-item label="鍗曚綅锛�" prop="unit">
+							<el-input v-model="form.unit" placeholder="璇疯緭鍏�" clearable/>
+						</el-form-item>
+					</el-col>
+        </el-row>
+        <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"/>
+            </el-form-item>
+          </el-col>
+					<el-col :span="12">
+						<el-form-item label="妫�娴嬬粨鏋滐細" prop="checkResult">
+							<el-select v-model="form.checkResult">
+								<el-option label="鍚堟牸" value="鍚堟牸"/>
+								<el-option label="涓嶅悎鏍�" value="涓嶅悎鏍�"/>
+							</el-select>
+						</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="閫夋嫨浜哄憳"
+								style="width: 100%;"
+								filterable
+								clearable
+							>
+								<el-option
+									v-for="user in userList"
+									:key="user.nickName"
+									:label="user.nickName"
+									:value="user.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>
+      </el-form>
       <PIMTable
           rowKey="id"
           :column="tableColumn"
           :tableData="tableData"
           :tableLoading="tableLoading"
-          height="600"
+          height="400"
       >
         <template #slot="{ row }">
-          <el-input v-model="row.staffName" clearable/>
+          <el-input v-model="row.testValue" clearable/>
         </template>
       </PIMTable>
       <template #footer>
@@ -28,63 +124,191 @@
 </template>
 
 <script setup>
-import {ref} from "vue";
-import {getStaffJoinInfo, staffJoinAdd, staffJoinUpdate} from "@/api/personnelManagement/onboarding.js";
-import {Search} from "@element-plus/icons-vue";
-const { proxy } = getCurrentInstance()
-const emit = defineEmits(['close'])
+import {ref, computed} from "vue";
+import {getOptions} from "@/api/procurementManagement/procurementLedger.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 {userListNoPageByTenantId} from "@/api/system/user.js";
+import dayjs from "dayjs";
+import useUserStore from "@/store/modules/user.js";
 
+const {proxy} = getCurrentInstance()
+const emit = defineEmits(['close'])
+const userList = ref([])
+const userStore = useUserStore()
+const currentUserName = computed(() => userStore.nickName || userStore.name || "")
+const getToday = () => dayjs().format("YYYY-MM-DD")
 const dialogFormVisible = ref(false);
 const operationType = ref('')
+const data = reactive({
+  form: {
+    checkTime: "",
+    supplier: "",
+    checkName: "",
+    productName: "",
+    productId: "",
+    model: "",
+		modelId: "",
+    unit: "",
+    quantity: "",
+    checkCompany: "",
+    checkResult: "",
+  },
+  rules: {
+    checkTime: [{required: true, message: "璇疯緭鍏�", trigger: "blur"},],
+    supplier: [{required: true, message: "璇疯緭鍏�", trigger: "blur"}],
+    checkName: [{required: true, message: "璇疯緭鍏�", trigger: "blur"}],
+    productId: [{required: true, message: "璇疯緭鍏�", trigger: "blur"}],
+    model: [{required: false, message: "璇疯緭鍏�", trigger: "blur"}],
+    unit: [{required: false, message: "璇疯緭鍏�", trigger: "blur"}],
+    quantity: [{required: true, message: "璇疯緭鍏�", trigger: "blur"}],
+    checkCompany: [{required: false, message: "璇疯緭鍏�", trigger: "blur"}],
+    checkResult: [{required: true, message: "璇烽�夋嫨妫�娴嬬粨鏋�", trigger: "change"}],
+  },
+});
 const tableColumn = ref([
   {
     label: "鎸囨爣",
-    prop: "contractTerm",
+    prop: "parameterItem",
   },
   {
     label: "鍗曚綅",
-    prop: "contractStartTime",
+    prop: "unit",
   },
   {
     label: "鏍囧噯鍊�",
-    prop: "contractEndTime",
+    prop: "standardValue",
   },
   {
     label: "鍐呮帶鍊�",
-    prop: "contractEndTime",
+    prop: "controlValue",
   },
   {
     label: "妫�楠屽��",
-    prop: "contractEndTime",
+    prop: "testValue",
     dataType: 'slot',
     slot: 'slot',
   },
 ]);
 const tableData = ref([]);
 const tableLoading = ref(false);
+const modelOptions = ref([]);
+
+const {form, rules} = toRefs(data);
+const supplierList = ref([]);
+const productOptions = ref([]);
+const currentProductId = ref(0);
 
 // 鎵撳紑寮规
 const openDialog = (type, row) => {
   operationType.value = type;
   dialogFormVisible.value = true;
-  if (operationType.value === 'edit') {
-    getStaffJoinInfo(row.id).then(res => {
-      // tableData.value = res.data
-    })
+  getOptions().then((res) => {
+    supplierList.value = res.data;
+  });
+	userListNoPageByTenantId().then((res) => {
+		userList.value = res.data;
+	});
+	form.value = {}
+  getProductOptions();
+  if (operationType.value === 'edit' && row) {
+    form.value = {...row}
+    currentProductId.value = row.productId || 0
+    // 鍔犺浇褰撳墠浜у搧涓嬬殑瑙勬牸鍒楄〃锛屽苟鏍规嵁鍚庣杩斿洖鐨� model 鍙嶆煡骞惰缃� modelId锛屽疄鐜拌鏍间笅鎷夋鍙嶆樉
+    if (currentProductId.value) {
+      modelList({ id: currentProductId.value }).then((res) => {
+        modelOptions.value = res;
+        const target = res.find((item) => item.model === row.model);
+        if (target) {
+          form.value.modelId = target.id;
+        }
+      });
+    }
+    getQualityInspectParamList(row.id)
+  }
+  // 榛樿妫�楠屽憳涓哄綋鍓嶇櫥褰曚汉锛屾娴嬫棩鏈熼粯璁や负褰撳ぉ锛堢┖鏃跺~鍏咃級
+  if (currentUserName.value && !form.value.checkName) {
+    form.value.checkName = currentUserName.value;
+  }
+  if (!form.value.checkTime) {
+    form.value.checkTime = getToday();
   }
 }
+const getProductOptions = () => {
+  productTreeList({productName: '璐ㄩ噺'}).then((res) => {
+    productOptions.value = convertIdToValue(res);
+  });
+};
+const getModels = (value) => {
+  currentProductId.value = value
+  form.value.productName = findNodeById(productOptions.value, value);
+	modelList({ id: value }).then((res) => {
+		modelOptions.value = res;
+	});
+  if (currentProductId) {
+    getList();
+  }
+};
+const getProductModel = (value) => {
+	const index = modelOptions.value.findIndex((item) => item.id === value);
+	if (index !== -1) {
+		form.value.unit = modelOptions.value[index].unit;
+		form.value.model = modelOptions.value[index].model;
+	} else {
+		form.value.unit = null;
+	}
+};
+const findNodeById = (nodes, productId) => {
+  for (let i = 0; i < nodes.length; i++) {
+    if (nodes[i].value === productId) {
+      return nodes[i].label; // 鎵惧埌鑺傜偣锛岃繑鍥炶鑺傜偣
+    }
+    if (nodes[i].children && nodes[i].children.length > 0) {
+      const foundNode = findNodeById(nodes[i].children, productId);
+      if (foundNode) {
+        return foundNode; // 鍦ㄥ瓙鑺傜偣涓壘鍒帮紝杩斿洖璇ヨ妭鐐�
+      }
+    }
+  }
+  return null; // 娌℃湁鎵惧埌鑺傜偣锛岃繑鍥瀗ull
+};
+
+function convertIdToValue(data) {
+  return data.map((item) => {
+    const {id, children, ...rest} = item;
+    const newItem = {
+      ...rest,
+      value: id, // 灏� id 鏀逛负 value
+    };
+    if (children && children.length > 0) {
+      newItem.children = convertIdToValue(children);
+    }
+
+    return newItem;
+  });
+}
+
 // 鎻愪氦浜у搧琛ㄥ崟
 const submitForm = () => {
   proxy.$refs.formRef.validate(valid => {
     if (valid) {
-      form.value.staffState = 0
+      form.value.inspectType = 0
+			if (operationType.value === "add") {
+				tableData.value.forEach((item) => {
+					delete item.id
+				})
+			}
+      const data = {...form.value, qualityInspectParams: tableData.value}
       if (operationType.value === "add") {
-        staffJoinAdd(form.value).then(res => {
+        qualityInspectAdd(data).then(res => {
           proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
           closeDia();
         })
       } else {
-        staffJoinUpdate(form.value).then(res => {
+        qualityInspectUpdate(data).then(res => {
           proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
           closeDia();
         })
@@ -92,8 +316,22 @@
     }
   })
 }
+
+const getList = () => {
+  qualityInspectDetailByProductId(currentProductId.value).then(res => {
+    tableData.value = res.data;
+  })
+}
+
+const getQualityInspectParamList = (id) => {
+  qualityInspectParamInfo(id).then(res => {
+    tableData.value = res.data;
+  })
+}
 // 鍏抽棴寮规
 const closeDia = () => {
+  proxy.resetForm("formRef");
+  tableData.value = []
   dialogFormVisible.value = false;
   emit('close')
 };

--
Gitblit v1.9.3