From a0a35be4065d75b80ba4a9a51da7031e03166766 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 21 一月 2026 17:47:45 +0800
Subject: [PATCH] 湟水峡 1.成品入库添加编辑功能

---
 src/views/productionManagement/productionOrder/index.vue |  222 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 208 insertions(+), 14 deletions(-)

diff --git a/src/views/productionManagement/productionOrder/index.vue b/src/views/productionManagement/productionOrder/index.vue
index 51b42ac..c6a3d13 100644
--- a/src/views/productionManagement/productionOrder/index.vue
+++ b/src/views/productionManagement/productionOrder/index.vue
@@ -41,7 +41,9 @@
         </el-form-item>
       </el-form>
       <div>
+        <el-button type="primary" @click="openCreateOrder">鏂板璁㈠崟</el-button>
         <el-button @click="handleOut">瀵煎嚭</el-button>
+        <el-button type="danger" plain :disabled="selectedRows.length === 0" @click="handleBatchDelete">鎵归噺鍒犻櫎</el-button>
       </div>
     </div>
     <div class="table_list">
@@ -50,6 +52,8 @@
                 :tableData="tableData"
                 :page="page"
                 :tableLoading="tableLoading"
+                :isSelection="true"
+                @selection-change="handleSelectionChange"
                 @pagination="pagination">
         <template #completionStatus="{ row }">
           <el-progress
@@ -85,20 +89,79 @@
         </span>
       </template>
     </el-dialog>
+    <el-dialog v-model="orderFormVisible"
+               title="鏂板鐢熶骇璁㈠崟"
+               width="520px"
+               @close="() => proxy?.resetForm?.('orderFormRef')">
+      <el-form ref="orderFormRef"
+               :model="orderForm"
+               :rules="orderRules"
+               label-width="120px"
+               label-position="top">
+        <el-form-item label="浜у搧澶х被" prop="productId">
+          <el-tree-select v-model="orderForm.productId"
+                          placeholder="璇烽�夋嫨"
+                          clearable
+                          check-strictly
+                          :data="productOptions"
+                          :render-after-expand="false"
+                          style="width: 100%"
+                          @change="getModels" />
+        </el-form-item>
+        <el-form-item label="瑙勬牸鍨嬪彿" prop="productModelId">
+          <el-select v-model="orderForm.productModelId"
+                     placeholder="璇烽�夋嫨"
+                     clearable
+                     style="width: 100%"
+                     @change="getProductModel">
+            <el-option v-for="item in modelOptions"
+                       :key="item.id"
+                       :label="item.model"
+                       :value="item.id" />
+          </el-select>
+        </el-form-item>
+        <el-form-item label="鍗曚綅" prop="unit">
+          <el-input v-model="orderForm.unit"
+                    placeholder="璇疯緭鍏�"
+                    clearable />
+        </el-form-item>
+        <el-row :gutter="12">
+          <el-col :span="12">
+            <el-form-item label="鏁伴噺" prop="quantity">
+              <el-input-number v-model="orderForm.quantity"
+                               :step="0.1"
+                               :min="0"
+                               :precision="2"
+                               placeholder="璇疯緭鍏�"
+                               style="width: 100%"
+                               @change="calculateFromQuantity" />
+            </el-form-item>
+          </el-col>
+        </el-row>
+      </el-form>
+      <template #footer>
+        <span class="dialog-footer">
+          <el-button type="primary" @click="submitCreateOrder">纭� 璁�</el-button>
+          <el-button @click="orderFormVisible = false">鍙� 娑�</el-button>
+        </span>
+      </template>
+    </el-dialog>
   </div>
 </template>
 
 <script setup>
-  import { onMounted, ref } from "vue";
+  import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue";
   import { ElMessageBox } from "element-plus";
   import dayjs from "dayjs";
   import { useRouter } from "vue-router";
   import {
     productOrderListPage,
+    addProductOrder,
     listProcessRoute,
     bindingRoute,
-    listProcessBom,
+    deleteProductOrder,
   } from "@/api/productionManagement/productionOrder.js";
+  import { productTreeList, modelList } from "@/api/basicData/product.js";
   import { listMain as getOrderProcessRouteMain } from "@/api/productionManagement/productProcessRoute.js";
   const { proxy } = getCurrentInstance();
 
@@ -111,22 +174,12 @@
       width: '120px',
     },
     {
-      label: "閿�鍞悎鍚屽彿",
-      prop: "salesContractNo",
-      width: '150px',
-    },
-    {
-      label: "瀹㈡埛鍚嶇О",
-      prop: "customerName",
-      width: '200px',
-    },
-    {
-      label: "浜у搧鍚嶇О",
+      label: "浜у搧澶х被",
       prop: "productCategory",
       width: '120px',
     },
     {
-      label: "瑙勬牸",
+      label: "瑙勬牸鍨嬪彿",
       prop: "specificationModel",
       width: '120px',
     },
@@ -196,6 +249,7 @@
   ]);
   const tableData = ref([]);
   const tableLoading = ref(false);
+  const selectedRows = ref([]);
   const page = reactive({
     current: 1,
     size: 100,
@@ -212,6 +266,30 @@
     },
   });
   const { searchForm } = toRefs(data);
+
+  // 鏂板璁㈠崟寮规鏁版嵁
+  const orderFormVisible = ref(false);
+  const orderFormRef = ref(null);
+  const orderFormState = reactive({
+    orderForm: {
+      productId: null,
+      productCategory: "",
+      productModelId: "",
+      specificationModel: "",
+      unit: "",
+      quantity: null,
+    },
+    orderRules: {
+      productId: [{ required: true, message: "璇烽�夋嫨浜у搧澶х被", trigger: "change" }],
+      productModelId: [{ required: true, message: "璇烽�夋嫨瑙勬牸鍨嬪彿", trigger: "change" }],
+      specificationModel: [{ required: true, message: "璇烽�夋嫨瑙勬牸鍨嬪彿", trigger: "change" }],
+      unit: [{ required: true, message: "璇疯緭鍏ュ崟浣�", trigger: "blur" }],
+      quantity: [{ required: true, message: "璇疯緭鍏ユ暟閲�", trigger: "blur" }],
+    },
+  });
+  const { orderForm, orderRules } = toRefs(orderFormState);
+  const productOptions = ref([]);
+  const modelOptions = ref([]);
 
   const toProgressPercentage = val => {
     const n = Number(val);
@@ -378,8 +456,124 @@
       });
   };
 
+  // 琛ㄦ牸閫夋嫨鏁版嵁
+  const handleSelectionChange = (selection) => {
+    selectedRows.value = selection || [];
+  };
+
+  // 鎵归噺鍒犻櫎
+  const handleBatchDelete = async () => {
+    if (selectedRows.value.length === 0) {
+      proxy.$modal.msgWarning("璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁");
+      return;
+    }
+    const ids = selectedRows.value.map(item => item.productModelId).filter(Boolean);
+    if (ids.length === 0) {
+      proxy.$modal.msgWarning("閫変腑鏁版嵁缂哄皯ID锛屾棤娉曞垹闄�");
+      return;
+    }
+    try {
+      await ElMessageBox.confirm("閫変腑鐨勫唴瀹瑰皢琚垹闄わ紝鏄惁纭鍒犻櫎锛�", "鎻愮ず", {
+        confirmButtonText: "纭",
+        cancelButtonText: "鍙栨秷",
+        type: "warning",
+      });
+      await deleteProductOrder(ids);
+      proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛");
+      selectedRows.value = [];
+      getList();
+    } catch (e) {
+      // 鍙栨秷鎴栧け璐�
+      if (e !== 'cancel' && e !== 'close') {
+        console.error("鎵归噺鍒犻櫎澶辫触锛�", e);
+        proxy.$modal.msgError("鍒犻櫎澶辫触锛岃閲嶈瘯");
+      }
+    }
+  };
+
   const handleConfirmRoute = () => {};
 
+  const openCreateOrder = async () => {
+    orderForm.value = {
+      productId: null,
+      productCategory: "",
+      productModelId: "",
+      specificationModel: "",
+      unit: "",
+      quantity: null,
+    };
+    await loadProductOptions();
+    orderFormVisible.value = true;
+  };
+
+  const loadProductOptions = async () => {
+    const tree = await productTreeList();
+    productOptions.value = Array.isArray(tree?.data) ? convertIdToValue(tree.data) : convertIdToValue(tree || []);
+  };
+
+  const convertIdToValue = data => {
+    return (data || []).map(item => {
+      const { id, children, ...rest } = item;
+      const newItem = { ...rest, value: id };
+      if (children && children.length > 0) {
+        newItem.children = convertIdToValue(children);
+      }
+      return newItem;
+    });
+  };
+
+  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;
+  };
+
+  const getModels = async value => {
+    orderForm.value.productId = value;
+    orderForm.value.productCategory = findNodeById(productOptions.value, value);
+    const res = await modelList({ id: value });
+    modelOptions.value = res || [];
+  };
+
+  const getProductModel = value => {
+    const index = modelOptions.value.findIndex(item => item.id === value);
+    if (index !== -1) {
+      orderForm.value.specificationModel = modelOptions.value[index].model;
+      orderForm.value.unit = modelOptions.value[index].unit;
+    } else {
+      orderForm.value.specificationModel = null;
+      orderForm.value.unit = null;
+    }
+  };
+
+  const calculateFromQuantity = () => {
+    // 鍗犱綅锛氭暟閲忓彉鏇存椂鍙湪姝ゆ墿灞曢�昏緫
+  };
+
+  const submitCreateOrder = async () => {
+    proxy.$refs["orderFormRef"]?.validate(async valid => {
+      if (!valid) return;
+      try {
+        await addProductOrder(orderForm.value);
+        proxy.$modal.msgSuccess("鏂板鎴愬姛");
+        orderFormVisible.value = false;
+        getList();
+      } catch (e) {
+        console.error("鏂板鐢熶骇璁㈠崟澶辫触", e);
+        proxy.$modal.msgError("鏂板澶辫触锛岃绋嶅悗閲嶈瘯");
+      }
+    });
+  };
+
   onMounted(() => {
     getList();
   });

--
Gitblit v1.9.3