From a00484ae729aed9a664050362fa2b8c6a4ce4fd6 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 12 六月 2025 10:29:11 +0800
Subject: [PATCH] 1.库存管理页面联调

---
 src/views/warehouseManagement/index.vue |  253 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 205 insertions(+), 48 deletions(-)

diff --git a/src/views/warehouseManagement/index.vue b/src/views/warehouseManagement/index.vue
index cac372d..8905e20 100644
--- a/src/views/warehouseManagement/index.vue
+++ b/src/views/warehouseManagement/index.vue
@@ -38,29 +38,32 @@
       </el-tabs>
       <!-- 鎿嶄綔鎸夐挳鍖� -->
       <el-space>
-        <el-button type="danger" :icon="Delete">鍒犻櫎</el-button>
+<!--        <el-button type="danger" :icon="Delete">鍒犻櫎</el-button>-->
         <el-button type="info" plain :icon="Download">瀵煎嚭</el-button>
-        <el-button type="success" plain :icon="Refresh" v-if="activeTab=== 'officialInventory'" @click="mergeRows">鍚堝苟</el-button>
+        <el-button type="success" plain :icon="Refresh" v-if="activeTab=== 'officialInventory'" @click="mergeRows('merge')">鍚堝苟</el-button>
       </el-space>
       <div>
-        <el-table :data="tableData" border @selection-change="selectionChange" style="width: 100%">
+        <el-table :data="tableData" border @selection-change="selectionChange" style="width: 100%" show-summary :summary-method="summarizeChildrenTable">
           <el-table-column type="selection" width="55" align="center" />
           <el-table-column label="搴忓彿" type="index" width="60" align="center" />
           <el-table-column prop="supplierName" label="渚涜揣鍟嗗悕绉�" width="180" sortable/>
           <el-table-column prop="coal" label="鐓ょ" sortable/>
           <el-table-column prop="unit" label="鍗曚綅" width="70"/>
           <el-table-column prop="inventoryQuantity" label="搴撳瓨鏁伴噺" sortable min-width="110"/>
-          <el-table-column prop="priceIncludingTax" label="鍗曚环锛堝惈绋庯級" sortable width="130"/>
-          <el-table-column prop="totalPriceIncludingTax" label="鎬讳环锛堝惈绋庯級" width="130" />
-          <el-table-column prop="costPerUnit" label="鎴愭湰鍗曚环" />
+          <el-table-column prop="priceIncludingTax" label="鍗曚环(鍚◣)" sortable width="130"/>
+          <el-table-column prop="totalPriceIncludingTax" label="鎬讳环(鍚◣)" width="130" />
+          <el-table-column prop="priceExcludingTax" label="鍗曚环(涓嶅惈绋�)" width="130" />
+          <el-table-column prop="totalPriceExcludingTax" label="鎬讳环(涓嶅惈绋�)" width="130" />
+          <el-table-column prop="pendingReplenishment" label="寰呰ˉ搴�" width="130" />
           <el-table-column label="鐓よ川" align="center" v-if="activeTab=== 'officialInventory'" width="600">
             <el-table-column v-for="col in columnTitle" :key="col.prop" :prop="col.prop" :label="col.label" align="center" sortable min-width="200"/>
           </el-table-column>
-          <el-table-column prop="registrant" label="鐧昏浜�" width="180"/>
-          <el-table-column prop="registrationTime" label="鐧昏鏃ユ湡" width="180"/>
-          <el-table-column fixed="right" label="鎿嶄綔" min-width="60" align="center" v-if="activeTab !== 'officialInventory'">
+          <el-table-column prop="registrantId" label="鐧昏浜�" width="180"/>
+          <el-table-column prop="registrationDate" label="鐧昏鏃ユ湡" width="180"/>
+          <el-table-column fixed="right" label="鎿嶄綔" min-width="60" align="center">
             <template #default="scope">
-              <el-button link type="primary" size="small" @click="reviewDia(scope.row)">瀹℃牳</el-button>
+              <el-button link type="primary" size="small" @click="reviewDia(scope.row)" v-if="activeTab !== 'officialInventory'">瀹℃牳</el-button>
+              <el-button link type="primary" size="small" @click="mergeRows('edit', scope.row)" v-else>缂栬緫</el-button>
             </template>
           </el-table-column>
         </el-table>
@@ -97,7 +100,7 @@
           </el-col>
           <el-col :span="12">
             <el-form-item label="搴撳瓨鏁伴噺" prop="inventoryQuantity">
-              <el-input v-model="form.inventoryQuantity" placeholder="璇疯緭鍏ュ簱瀛樻暟閲�" maxlength="30" />
+              <el-input v-model="form.inventoryQuantity" placeholder="璇疯緭鍏ュ簱瀛樻暟閲�" :max="inventoryQuantity" type="number"/>
             </el-form-item>
           </el-col>
         </el-row>
@@ -115,13 +118,20 @@
         </el-row>
         <el-row>
           <el-col :span="12">
-            <el-form-item label="鎴愭湰鍗曚环" prop="costPerUnit">
-              <el-input v-model="form.costPerUnit" placeholder="璇疯緭鍏ユ垚鏈崟浠�" maxlength="30" />
+            <el-form-item label="鍗曚环(涓嶅惈绋�)" prop="priceExcludingTax">
+              <el-input v-model="form.priceExcludingTax" placeholder="璇疯緭鍏ユ垚鏈崟浠�" maxlength="30" />
             </el-form-item>
           </el-col>
           <el-col :span="12">
+            <el-form-item label="鎬讳环(涓嶅惈绋�)" prop="totalPriceExcludingTax">
+              <el-input v-model="form.totalPriceExcludingTax" placeholder="璇疯緭鍏ユ垚鏈崟浠�" maxlength="30" />
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row>
+          <el-col :span="12">
             <el-form-item label="鐓よ川鏂规" prop="qualityPlan">
-              <el-select v-model="form.qualityPlan" placeholder="璇烽�夋嫨" @change="coalFieldListOption" clearable>
+              <el-select v-model="form.qualityPlan" placeholder="璇烽�夋嫨" @change="coalPlanByIdList" clearable>
                 <el-option
                     v-for="dict in qualityPlanOption"
                     :key="dict.id"
@@ -150,40 +160,60 @@
     </el-dialog>
     <!-- 鍚堝苟鏁版嵁寮规 -->
     <el-dialog title="鍚堝苟搴撳瓨" v-model="mergeVisible" width="800px">
-      <el-form :model="form" :rules="rules" ref="userRef" label-width="100px">
+      <el-form :model="mergeForm" :rules="mergeRules" ref="mergeRef" label-width="100px">
         <el-row>
           <el-col :span="12">
             <el-form-item label="渚涜揣鍟嗗悕绉�" prop="supplierName">
-              <el-input v-model="form.supplierName" placeholder="璇疯緭鍏ユ墜鏈哄彿鐮�" maxlength="30" />
+              <el-input v-model="mergeForm.supplierName" placeholder="璇疯緭鍏ヤ緵璐у晢鍚嶇О" maxlength="30" />
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="鐓ょ" prop="coal">
-              <el-input v-model="form.coal" placeholder="璇疯緭鍏ュ鍚�" maxlength="30" />
+              <el-input v-model="mergeForm.coal" placeholder="璇疯緭鍏ョ叅绉�" maxlength="30" />
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row>
+          <el-col :span="12">
+            <el-form-item label="鍗曚綅" prop="unit">
+              <el-input v-model="mergeForm.unit" placeholder="璇疯緭鍏ュ崟浣�" maxlength="30" />
+            </el-form-item>
+          </el-col>
+          <el-col :span="12">
+            <el-form-item label="搴撳瓨鏁伴噺" prop="inventoryQuantity">
+              <el-input v-model="mergeForm.inventoryQuantity" placeholder="璇疯緭鍏ュ簱瀛樻暟閲�" :max="inventoryQuantity" type="number"/>
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
           <el-col :span="12">
             <el-form-item label="鍗曚环(鍚◣)" prop="priceIncludingTax">
-              <el-input v-model="form.priceIncludingTax" placeholder="璇疯緭鍏ユ墜鏈哄彿鐮�" maxlength="30" />
+              <el-input v-model="mergeForm.priceIncludingTax" placeholder="璇疯緭鍏ュ崟浠�(鍚◣)" maxlength="30" />
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="鎬讳环(鍚◣)" prop="totalPriceIncludingTax">
-              <el-input v-model="form.totalPriceIncludingTax" placeholder="璇疯緭鍏ユ墜鏈哄彿鐮�" maxlength="30" />
+              <el-input v-model="mergeForm.totalPriceIncludingTax" placeholder="璇疯緭鍏ユ�讳环(鍚◣)" maxlength="30" />
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
           <el-col :span="12">
-            <el-form-item label="鎴愭湰鍗曚环" prop="costPerUnit">
-              <el-input v-model="form.costPerUnit" placeholder="璇疯緭鍏ュ鍚�" maxlength="30" />
+            <el-form-item label="鍗曚环(涓嶅惈绋�)" prop="priceExcludingTax">
+              <el-input v-model="mergeForm.priceExcludingTax" placeholder="璇疯緭鍏ュ崟浠�(涓嶅惈绋�)" maxlength="30" />
             </el-form-item>
           </el-col>
           <el-col :span="12">
-            <el-form-item label="鐓よ川" prop="userName">
-              <el-input v-model="form.userName" placeholder="璇疯緭鍏ユ墜鏈哄彿鐮�" maxlength="30" />
+            <el-form-item label="鎬讳环(涓嶅惈绋�)" prop="totalPriceExcludingTax">
+              <el-input v-model="mergeForm.totalPriceExcludingTax" placeholder="璇疯緭鍏ユ�讳环(涓嶅惈绋�)" maxlength="30" />
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-divider></el-divider>
+        <el-row>
+          <el-col :span="12" v-for="item in filteredList" :key="item.id">
+            <el-form-item :label="item.fieldName">
+              <el-input v-model="mergeForm[item.fields]" />
             </el-form-item>
           </el-col>
         </el-row>
@@ -204,26 +234,31 @@
 import Pagination from "@/components/Pagination/index.vue";
 import {
   addOrEditCoalValue,
-  coalFieldList,
+  coalFieldList, coalPlanById,
   coalPlanList, officialInventoryList,
   pendingInventoryList
 } from "@/api/warehouseManagement/index.js";
+import {editOfficial, merge} from "../../api/warehouseManagement/index.js";
 
 const { proxy } = getCurrentInstance()
 
 const tableData = ref([])
 const selectedRows = ref([])
-const columns = ref([])
 const qualityPlanOption = ref([])
 const filteredList = ref([])
 const tableLoading = ref(false);
 const total = ref(0);
 const pageNum = ref(1);
 const pageSize = ref(10);
+const inventoryQuantity = ref(0);
+const count = ref(0);
+const mean = ref(0);
+const totalPrice = ref(0);
 // 瀹℃牳寮规
 const reviewVisible = ref(false);
 // 鍚堝苟寮规
 const mergeVisible = ref(false)
+const operationType = ref('')
 const data = reactive({
   form: {
     supplierName: '',
@@ -232,11 +267,30 @@
     inventoryQuantity: '',
     priceIncludingTax: '',
     totalPriceIncludingTax: '',
-    costPerUnit: '',
+    priceExcludingTax: '',
+    totalPriceExcludingTax: '',
     qualityPlan: '',
-    planId: '',
+    pId: '',
+  },
+  mergeForm: {
+    supplierName: '',
+    coal: '',
+    unit: '',
+    inventoryQuantity: '',
+    priceIncludingTax: '',
+    totalPriceIncludingTax: '',
+    priceExcludingTax: '',
+    totalPriceExcludingTax: '',
+    qualityPlan: '',
+    pId: '',
   },
   rules: {
+    supplierName: [{ required: true, message: "璇疯緭鍏ヤ緵搴斿晢鍚嶇О", trigger: "blur" }],
+    coal: [{ required: true, message: "璇疯緭鍏ョ叅绉�", trigger: "blur" }],
+    unit: [{ required: true, message: "璇疯緭鍏ュ崟浣�", trigger: "blur" }],
+    qualityPlan: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
+  },
+  mergeRules: {
     supplierName: [{ required: true, message: "璇疯緭鍏ヤ緵搴斿晢鍚嶇О", trigger: "blur" }],
     coal: [{ required: true, message: "璇疯緭鍏ョ叅绉�", trigger: "blur" }],
     unit: [{ required: true, message: "璇疯緭鍏ュ崟浣�", trigger: "blur" }],
@@ -244,7 +298,7 @@
   }
 })
 
-const { form, rules } = toRefs(data)
+const { form, rules, mergeForm, mergeRules } = toRefs(data)
 // 褰撳墠鏍囩
 const activeTab = ref("pendingInbound");
 const tabName = ref("pendingInbound");
@@ -260,7 +314,7 @@
 })
 const columnTitle = ref([])
 onMounted(() => {
-  handleTabClick({ props: { name: "supplier" } });
+  handleTabClick({ props: { name: "pendingInbound" } });
 });
 // 鏍囩椤电偣鍑�
 const handleTabClick = (tab) => {
@@ -268,6 +322,9 @@
   tableData.value = [];
   getList();
 };
+const summarizeChildrenTable = (param) => {
+  return proxy.summarizeTable(param, ['inventoryQuantity', 'priceIncludingTax', 'totalPriceIncludingTax','priceExcludingTax','totalPriceExcludingTax']);
+}
 // 鐐瑰嚮鏌ヨ
 const handleQuery = () => {
   pageNum.value = 1
@@ -277,24 +334,37 @@
 const getList = () => {
   tableLoading.value = true;
   // 璧嬪�肩叅璐ㄨ〃澶村睍绀哄瓧娈�
-  columnTitle.value = [
-    {prop: 'value1', label: '鐧惧垎姣�1'},
-    {prop: 'value2', label: '鐧惧垎姣�2'},
-    {prop: 'value3', label: '鐧惧垎姣�3'},
-  ]
   if (tabName.value === "pendingInbound") {
-    pendingInventoryList({ ...queryParams }).then(res => {
+    pendingInventoryList({ ...queryParams, current: pageNum.value, size: pageSize.value }).then(res => {
       tableLoading.value = false;
       tableData.value = res.data.records;
       total.value = res.data.total;
     })
   } else {
-    officialInventoryList({ ...queryParams }).then(res => {
+    officialInventoryList({ ...queryParams, current: pageNum.value, size: pageSize.value }).then(res => {
       tableLoading.value = false;
-      tableData.value = res.data.records;
+      const result = flattenFields(res.data.records);
+      tableData.value = result;
       total.value = res.data.total;
+      coalFieldListOption()
     })
   }
+};
+// 鎵佸钩鍖栧鐞嗗嚱鏁�
+const flattenFields = (data) => {
+  return data.map(item => {
+    const mergedFields = item.fields.reduce((acc, obj) => {
+      const key = Object.keys(obj)[0];
+      acc[key] = obj[key];
+      return acc;
+    }, {});
+    
+    // 鍚堝苟涓诲璞′笌鎻愬彇鍑虹殑 fields 瀛楁
+    return {
+      ...item,
+      ...mergedFields
+    };
+  });
 };
 // 閲嶇疆鏌ヨ
 const resetQuery = () => {
@@ -312,8 +382,10 @@
 // 鎵撳紑瀹℃牳寮规
 const reviewDia = (row) => {
   reviewVisible.value = true
+  filteredList.value = []
   form.value = {...row}
-  form.value.planId = form.value.id
+  form.value.pId = row.id
+  inventoryQuantity.value = row.inventoryQuantity
   coalPlanListOptions()
 }
 // 鏌ヨ鐓よ川鏂规涓嬫媺妗�
@@ -323,28 +395,114 @@
   })
 }
 // 鏌ヨ鐓よ川鏂规瀛楁
-const coalFieldListOption = (id) => {
-  coalFieldList({id: id}).then(res => {
+const coalPlanByIdList = (id) => {
+  coalPlanById({id: id}).then(res => {
     filteredList.value = res.data
-    if (!id) {
+    if(!id) {
       filteredList.value = []
     }
   })
 }
+// 鏌ヨ鐓よ川瀛楁
+const coalFieldListOption = () => {
+  coalFieldList().then(res => {
+    filteredList.value = res.data
+    columnTitle.value = res.data.map(item => {
+      return {
+        prop: item.fields,
+        label: item.fieldName // 浣跨敤 fieldName 浣滀负 label
+      };
+    });
+  })
+}
 // 鍚堝苟搴撳瓨鏁版嵁鏂规硶
-const mergeRows = () => {
-  if (selectedRows.value.length < 2) {
-    proxy.$modal.msgWarning('璇疯嚦灏戦�夋嫨涓ゆ潯鏁版嵁')
-    return
+const mergeRows = (type,row) => {
+  coalFieldListOption();
+  mergeVisible.value = true;
+  operationType.value = type;
+  if (type === 'edit') {
+    mergeForm.value = {...row}
+  } else {
+    if (selectedRows.value.length < 2) {
+      proxy.$modal.msgWarning('璇疯嚦灏戦�夋嫨涓ゆ潯鏁版嵁')
+      return
+    }
+    filteredList.value.forEach(item => {
+      mergeForm.value[item.fields] = ''
+    })
+    const data = selectedRows.value
+    const selectedIds = selectedRows.value.map(row => row.id);
+    // 鍒濆鍖栧悎璁″拰鍧囧�煎彉閲�
+    let totalInventory = 0;
+    let totalPriceIncludingTax = 0;
+    let totalPriceExcludingTax = 0;
+    let priceIncludingTaxSum = 0;
+    let priceExcludingTaxSum = 0;
+    // 閬嶅巻鎵�鏈夐�変腑鏁版嵁锛岀疮鍔犺绠�
+    data.forEach(row => {
+      totalInventory += parseFloat(row.inventoryQuantity) || 0;
+      priceIncludingTaxSum += parseFloat(row.priceIncludingTax) || 0;
+      totalPriceIncludingTax += parseFloat(row.totalPriceIncludingTax) || 0;
+      priceExcludingTaxSum += parseFloat(row.priceExcludingTax) || 0;
+      totalPriceExcludingTax += parseFloat(row.totalPriceExcludingTax) || 0;
+    });
+    // 璁$畻骞冲潎鍊煎苟淇濈暀涓や綅灏忔暟
+    const avgPriceIncludingTax = Number((priceIncludingTaxSum / data.length).toFixed(2));
+    const avgTotalPriceIncludingTax = Number((totalPriceIncludingTax / data.length).toFixed(2));
+    const avgPriceExcludingTax = Number((priceExcludingTaxSum / data.length).toFixed(2));
+    const avgTotalPriceExcludingTax = Number((totalPriceExcludingTax / data.length).toFixed(2));
+    // 璁剧疆琛ㄥ崟鏄剧ず
+    mergeForm.value.inventoryQuantity = totalInventory;
+    mergeForm.value.priceIncludingTax = avgPriceIncludingTax;
+    mergeForm.value.totalPriceIncludingTax = avgTotalPriceIncludingTax;
+    mergeForm.value.priceExcludingTax = avgPriceExcludingTax;
+    mergeForm.value.totalPriceExcludingTax = avgTotalPriceExcludingTax;
+    mergeForm.value.ids = selectedIds;
   }
-  mergeVisible.value = true
 }
 // 鎻愪氦鍚堝苟琛ㄥ崟
 const submitForm = () => {
-
+  proxy.$refs.mergeRef.validate(valid => {
+    if (valid) {
+      delete mergeForm.value.createTime
+      delete mergeForm.value.updateTime
+      if (operationType.value === 'edit') {
+        mergeForm.value.fields = filteredList.value.reduce((acc, item) => {
+          const key = item.fields;
+          const value = mergeForm.value[key];
+          // 鍒ゆ柇鏄惁鏈夊�硷紙浣犲彲浠ユ牴鎹渶瑕佷慨鏀瑰垽鏂潯浠讹級
+          if (value !== null && value !== undefined && value !== '') {
+            acc.push({ [key]: value });
+          }
+          return acc;
+        }, []);
+        editOfficial(mergeForm.value).then(() => {
+          cancel()
+          proxy.$modal.msgSuccess('淇敼鎴愬姛')
+          handleQuery()
+        })
+      } else {
+        mergeForm.value.fields = filteredList.value.reduce((acc, item) => {
+          const key = item.fields;
+          const value = mergeForm.value[key];
+          // 鍒ゆ柇鏄惁鏈夊�硷紙浣犲彲浠ユ牴鎹渶瑕佷慨鏀瑰垽鏂潯浠讹級
+          if (value !== null && value !== undefined && value !== '') {
+            acc.push({ [key]: value });
+          }
+          return acc;
+        }, []);
+        merge(mergeForm.value).then(() => {
+          cancel()
+          proxy.$modal.msgSuccess('鍚堝苟鎴愬姛')
+          handleQuery()
+        })
+      }
+    }
+  })
 }
 // 鍏抽棴鍚堝苟琛ㄥ崟
 const cancel = () => {
+  proxy.$refs.mergeRef.resetFields();
   mergeVisible.value = false
 }
 // 鎻愪氦瀹℃牳琛ㄥ崟
@@ -354,7 +512,6 @@
       delete form.value.registrationTime
       delete form.value.createTime
       delete form.value.updateTime
-      delete form.value.id
       form.value.fieldValue = filteredList.value.map(item => ({
         [item.fields]: form.value[item.fields]
       }))

--
Gitblit v1.9.3