From dea83e911b593d564bb326492869fdfb1ba51a76 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期一, 30 三月 2026 18:47:09 +0800
Subject: [PATCH] 入库管理修改

---
 src/views/inventoryManagement/receiptManagement/index.vue |  378 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 372 insertions(+), 6 deletions(-)

diff --git a/src/views/inventoryManagement/receiptManagement/index.vue b/src/views/inventoryManagement/receiptManagement/index.vue
index d93f2ae..be59711 100644
--- a/src/views/inventoryManagement/receiptManagement/index.vue
+++ b/src/views/inventoryManagement/receiptManagement/index.vue
@@ -23,7 +23,9 @@
       </div>
       <div>
         <el-button type="primary"
-                   @click="openForm('add')">鏂板鍏ュ簱</el-button>
+                   @click="openFormadd('add')">璁㈠崟鍏ュ簱</el-button>
+        <el-button type="primary"
+                   @click="openDirectForm('add')">鏂板鍏ュ簱</el-button>
         <el-button @click="handleOut">瀵煎嚭</el-button>
         <el-button type="danger"
                    plain
@@ -231,6 +233,72 @@
         </div>
       </template>
     </el-dialog>
+    <!-- 鐩存帴鏂板鍏ュ簱瀵硅瘽妗� -->
+    <el-dialog v-model="directDialogVisible"
+               title="鏂板鍏ュ簱"
+               width="70%"
+               @close="closeDirectDia">
+      <el-form :model="directForm"
+               label-width="140px"
+               label-position="top"
+               :rules="directRules"
+               ref="directFormRef">
+        <el-form :model="directQuery"
+                 class="mb-2">
+          <el-form-item label="浜у搧澶х被">
+            <el-select v-model="directQuery.productCategory"
+                       placeholder="璇烽�夋嫨浜у搧澶х被"
+                       clearable
+                       filterable
+                       @change="handleProductCategoryChange">
+              <el-option v-for="item in productList"
+                         :key="item.id"
+                         :label="item.productName"
+                         :value="item.productName" />
+            </el-select>
+          </el-form-item>
+          <el-form-item label="瑙勬牸鍨嬪彿">
+            <el-select v-model="directQuery.productModelId"
+                       placeholder="璇峰厛閫夋嫨浜у搧澶х被"
+                       clearable
+                       filterable
+                       :disabled="!directQuery.productCategory">
+              <el-option v-for="item in productModelList"
+                         :key="item.id"
+                         :label="item.model"
+                         :value="item.id" />
+            </el-select>
+          </el-form-item>
+          <el-form-item label="鍏ュ簱鏁伴噺">
+            <el-input v-model="directQuery.inboundQuantity"
+                      placeholder="杈撳叆鍏ュ簱鏁伴噺"
+                      clearable />
+          </el-form-item>
+          <el-form-item label="棰勮鏁伴噺">
+            <el-input v-model="directQuery.warnNum"
+                      placeholder="杈撳叆棰勮鏁伴噺"
+                      clearable />
+          </el-form-item>
+          <el-form-item label="缂鸿揣鏁伴噺">
+            <el-input v-model="directQuery.outStockQuantity"
+                      placeholder="杈撳叆缂鸿揣鏁伴噺"
+                      clearable />
+          </el-form-item>
+          <el-form-item label="缂鸿揣鎯呭喌">
+            <el-input v-model="directQuery.shortageDescription"
+                      placeholder="杈撳叆缂鸿揣鎯呭喌"
+                      clearable />
+          </el-form-item>
+        </el-form>
+      </el-form>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button type="primary"
+                     @click="submitDirectForm">纭</el-button>
+          <el-button @click="closeDirectDia">鍙栨秷</el-button>
+        </div>
+      </template>
+    </el-dialog>
   </div>
 </template>
 
@@ -245,8 +313,10 @@
     addSutockIn,
     delStockIn,
     selectProductRecordListByPuechaserId,
+    addProduct,
   } from "@/api/inventoryManagement/stockIn.js";
   import { purchaseListPage } from "@/api/procurementManagement/procurementLedger.js";
+  import { productTreeList, modelList } from "@/api/basicData/product.js";
 
   const userStore = useUserStore();
   const { proxy } = getCurrentInstance();
@@ -304,8 +374,56 @@
         { required: true, message: "璇疯緭鍏ュ叆搴撴壒娆�", trigger: "blur" },
       ],
     },
+    // 鐩存帴鏂板鍏ュ簱鐩稿叧
+    directDialogVisible: false,
+    directForm: {
+      id: null,
+      productId: null,
+      productModel: "",
+      inboundQuantity: 0,
+      warnNum: 0,
+      outStockQuantity: 0,
+      shortageDescription: "",
+    },
+    directRules: {
+      supplierId: [
+        { required: true, message: "璇烽�夋嫨渚涘簲鍟�", trigger: "change" },
+      ],
+      inboundTime: [
+        { required: true, message: "璇烽�夋嫨鍏ュ簱鏃堕棿", trigger: "change" },
+      ],
+      inboundBatch: [
+        { required: true, message: "璇疯緭鍏ュ叆搴撴壒娆�", trigger: "blur" },
+      ],
+    },
+    directQuery: {
+      productId: null,
+      productModelId: null,
+      inboundQuantity: 0,
+      warnNum: 0,
+      outStockQuantity: 0,
+      shortageDescription: "",
+    },
+    directProductList: [],
+    directLoading: false,
+    directSelectedRows: [],
+    // 浜у搧鐩稿叧
+    productList: [],
+    productModelList: [],
   });
-  const { searchForm, form, rules } = toRefs(data);
+  const {
+    searchForm,
+    form,
+    rules,
+    directDialogVisible,
+    directForm,
+    directRules,
+    directQuery,
+    directProductList,
+    directLoading,
+    directSelectedRows,
+    productModelList,
+  } = toRefs(data);
 
   const formatPurchaseOption = (item = {}) => {
     const contract = item.purchaseContractNumber || "--";
@@ -441,9 +559,7 @@
       loadingProducts.value = false;
     }
   };
-
-  // 鎵撳紑寮规
-  const openForm = async (type, row) => {
+  const openFormadd = async (type, row) => {
     operationType.value = type;
     dialogFormVisible.value = true;
     selectedRows.value = [];
@@ -491,6 +607,215 @@
         loadingProducts.value = false;
       }
     }
+  };
+  // 鎵撳紑璁㈠崟鍏ュ簱寮规
+  const openForm = async (type, row) => {
+    if (row.salesLedgerProductId) {
+      operationType.value = type;
+      dialogFormVisible.value = true;
+      selectedRows.value = [];
+      await loadPurchaseOptions();
+
+      if (type === "add") {
+        // 鏂板鏃跺垵濮嬪寲琛ㄥ崟
+        form.value = {
+          id: null,
+          purchaseContractNumber: "",
+          supplierId: null,
+          supplierName: "",
+          inboundTime: "",
+          inboundBatch: "",
+          recorderId: userStore.userId,
+          recorderName: userStore.name,
+          entryDate: getCurrentDate(),
+          remark: "",
+        };
+        productList.value = []; // 娓呯┖浜у搧鍒楄〃
+      } else {
+        form.value = JSON.parse(JSON.stringify(row));
+        try {
+          loadingProducts.value = true;
+          // 鏍规嵁鍚堝悓鍙峰姞杞藉搴旂殑浜у搧鍒楄〃锛堝亣璁� getProductByContract 鏄彲鐢ㄦ帴鍙o級
+          const res = await selectProductRecordListByPuechaserId({
+            purchaseContractNumber: form.value.purchaseContractNumber,
+            id: row.id,
+          });
+          productList.value = res.data.map(item => ({
+            ...item,
+            quantityStock: Number(
+              item.quantityStock ?? item.inboundQuantity ?? row.inboundNum ?? 0
+            ),
+            originalQuantityStock: Number(
+              item.quantityStock ?? item.inboundQuantity ?? row.inboundNum ?? 0
+            ),
+          }));
+          selectedRows.value = productList.value;
+        } catch (error) {
+          console.error("鍔犺浇浜у搧澶辫触:", error);
+          proxy.$modal.msgError("鍔犺浇浜у搧澶辫触");
+          productList.value = [];
+        } finally {
+          loadingProducts.value = false;
+        }
+      }
+    } else {
+      // 鐩存帴鏂板鍏ュ簱
+      openDirectForm(type, row);
+    }
+  };
+
+  // 鎵撳紑鐩存帴鏂板鍏ュ簱寮规
+  const openDirectForm = (type, row) => {
+    directDialogVisible.value = true;
+    directSelectedRows.value = [];
+    directQuery.value = {
+      productId: null,
+      productModelId: null,
+      inboundQuantity: 0,
+      warnNum: 0,
+      outStockQuantity: 0,
+      shortageDescription: "",
+    };
+    directProductList.value = [];
+    directForm.value = {
+      id: null,
+      supplierId: null,
+      supplierName: "",
+      inboundTime: "",
+      inboundBatch: "",
+      recorderId: userStore.userId,
+      recorderName: userStore.name,
+      entryDate: getCurrentDate(),
+      remark: "",
+    };
+    if (type === "edit" && row) {
+      // 缂栬緫妯″紡锛屽洖鏄炬暟鎹�
+      directForm.value = { ...row };
+      // 鍥炴樉浜у搧澶х被
+      const selectedProduct = productList.value.find(
+        item => item.productName === row.productCategory
+      );
+      if (selectedProduct) {
+        directQuery.value.productId = selectedProduct.id;
+        // 鏍规嵁浜у搧澶х被鍔犺浇瑙勬牸鍨嬪彿鍒楄〃骞跺洖鏄�
+        loadProductModelList(selectedProduct.id).then(() => {
+          // 鍥炴樉瑙勬牸鍨嬪彿
+          directQuery.value.productCategory = row.productCategory || "";
+          directQuery.value.productModelId = row.productModelId;
+          // 鍥炴樉鍏朵粬瀛楁
+          directQuery.value.inboundQuantity =
+            row.inboundNum || row.inboundQuantity;
+          directQuery.value.warnNum = row.warnNum || 0;
+          directQuery.value.outStockQuantity = row.outStockQuantity || 0;
+          directQuery.value.shortageDescription = row.shortageDescription || "";
+        });
+      }
+    }
+  };
+
+  // 鍔犺浇浜у搧澶х被鍒楄〃
+  const loadProductList = async () => {
+    try {
+      const res = await productTreeList();
+      productList.value = res;
+    } catch (error) {
+      console.error("鍔犺浇浜у搧澶х被澶辫触:", error);
+      proxy.$modal.msgError("鍔犺浇浜у搧澶х被澶辫触");
+    }
+  };
+
+  // 澶勭悊浜у搧澶х被鍙樺寲
+  const handleProductCategoryChange = value => {
+    directQuery.value.specificationModel = "";
+    productModelList.value = [];
+    if (value) {
+      // 鏍规嵁浜у搧澶х被鍔犺浇瑙勬牸鍨嬪彿鍒楄〃
+      const selectedProduct = productList.value.find(
+        item => item.productName === value
+      );
+      if (selectedProduct) {
+        loadProductModelList(selectedProduct.id);
+      }
+    }
+  };
+
+  // 鍔犺浇浜у搧鍨嬪彿鍒楄〃
+  const loadProductModelList = async productId => {
+    try {
+      const res = await modelList({ id: productId });
+      productModelList.value = res;
+    } catch (error) {
+      console.error("鍔犺浇瑙勬牸鍨嬪彿澶辫触:", error);
+      proxy.$modal.msgError("鍔犺浇瑙勬牸鍨嬪彿澶辫触");
+    }
+  };
+
+  // 鐩存帴鏂板鍏ュ簱鎼滅储浜у搧
+  const onDirectSearch = async () => {
+    try {
+      directLoading.value = true;
+      // 杩欓噷闇�瑕佽皟鐢ㄤ骇鍝佹悳绱PI锛屾殏鏃舵ā鎷熸暟鎹�
+      // 瀹為檯椤圭洰涓簲璇ヨ皟鐢ㄧ湡瀹炵殑浜у搧鏌ヨ鎺ュ彛
+      directProductList.value = [
+        {
+          id: 1,
+          productCategory: "鐢靛瓙浜у搧",
+          specificationModel: "A-100",
+          unit: "涓�",
+          quantityStock: 0,
+          outStockQuantity: 0,
+          shortageDescription: "",
+          taxRate: 13,
+          taxInclusiveUnitPrice: 100,
+        },
+        {
+          id: 2,
+          productCategory: "鐢靛瓙浜у搧",
+          specificationModel: "A-200",
+          unit: "涓�",
+          quantityStock: 0,
+          outStockQuantity: 0,
+          shortageDescription: "",
+          taxRate: 13,
+          taxInclusiveUnitPrice: 200,
+        },
+        {
+          id: 3,
+          productCategory: "鍔炲叕鐢ㄥ搧",
+          specificationModel: "B-100",
+          unit: "濂�",
+          quantityStock: 0,
+          outStockQuantity: 0,
+          shortageDescription: "",
+          taxRate: 13,
+          taxInclusiveUnitPrice: 50,
+        },
+      ];
+    } catch (error) {
+      console.error("鎼滅储浜у搧澶辫触:", error);
+      proxy.$modal.msgError("鎼滅储浜у搧澶辫触");
+      directProductList.value = [];
+    } finally {
+      directLoading.value = false;
+    }
+  };
+
+  // 鐩存帴鏂板鍏ュ簱閲嶇疆鎼滅储
+  const onDirectReset = () => {
+    directQuery.value = {
+      productId: null,
+      productModelId: null,
+      inboundQuantity: 0,
+      warnNum: 0,
+      outStockQuantity: 0,
+      shortageDescription: "",
+    };
+    directProductList.value = [];
+  };
+
+  // 澶勭悊鐩存帴鏂板鍏ュ簱浜у搧閫夋嫨
+  const handleDirectSelectionChange = selection => {
+    directSelectedRows.value = selection.filter(item => item.id);
   };
 
   const updatePro = async () => {
@@ -583,10 +908,50 @@
     }
   };
 
-  // 鍏抽棴寮规
+  // 鍏抽棴璁㈠崟鍏ュ簱寮规
   const closeDia = () => {
     proxy.$refs.formRef.resetFields();
     dialogFormVisible.value = false;
+  };
+
+  // 鍏抽棴鐩存帴鏂板鍏ュ簱寮规
+  const closeDirectDia = () => {
+    if (proxy.$refs.directFormRef) {
+      proxy.$refs.directFormRef.resetFields();
+    }
+    directDialogVisible.value = false;
+  };
+
+  // 鎻愪氦鐩存帴鏂板鍏ュ簱琛ㄥ崟
+  const submitDirectForm = async () => {
+    // 楠岃瘉鑷冲皯閫夋嫨浜嗕竴涓骇鍝�
+    console.log(directQuery.value, "directQuery.value");
+    if (!directQuery.value.productModelId) {
+      proxy.$modal.msgWarning("璇峰厛閫夋嫨浜у搧鍙婅鏍煎瀷鍙�");
+      return;
+    }
+    await proxy.$refs.directFormRef.validate();
+    if (directQuery.value.inboundQuantity <= 0) {
+      proxy.$modal.msgError("鏈鍏ュ簱鏁伴噺闇�澶т簬0");
+      return;
+    }
+
+    // 鍑嗗鎻愪氦鏁版嵁
+    const submitData = {
+      ...directQuery.value,
+      // 濡傛灉鏄紪杈戞ā寮忥紝娣诲姞id
+      ...(directForm.value.id && { id: directForm.value.id }),
+    };
+
+    addProduct(submitData).then(res => {
+      if (res.code === 200) {
+        proxy.$modal.msgSuccess("鎿嶄綔鎴愬姛");
+        closeDirectDia();
+        getList(); // 鍒锋柊鍒楄〃
+      } else {
+        proxy.$modal.msgError(res.msg || "鎿嶄綔澶辫触");
+      }
+    });
   };
   // 琛ㄦ牸閫夋嫨鏁版嵁
   const handleSelectionChange = selection => {
@@ -679,6 +1044,7 @@
 
   onMounted(() => {
     getList();
+    loadProductList();
   });
 </script>
 

--
Gitblit v1.9.3