From 94c0a729da1b88ab4a0067f1e14a00264e0447cf Mon Sep 17 00:00:00 2001
From: chenlu <1320612696@qq.com>
Date: 星期一, 15 十二月 2025 17:04:05 +0800
Subject: [PATCH] bom管理中空胶计算调整

---
 north-glass-erp/northglass-erp/src/views/sd/bom/OrderBOM.vue |   87 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 73 insertions(+), 14 deletions(-)

diff --git a/north-glass-erp/northglass-erp/src/views/sd/bom/OrderBOM.vue b/north-glass-erp/northglass-erp/src/views/sd/bom/OrderBOM.vue
index 2fdef27..7ecad75 100644
--- a/north-glass-erp/northglass-erp/src/views/sd/bom/OrderBOM.vue
+++ b/north-glass-erp/northglass-erp/src/views/sd/bom/OrderBOM.vue
@@ -478,6 +478,9 @@
   selectOrderList()
 }
 
+//鎬讳环
+const totalPriceSum = ref()
+
 //椤甸潰璺宠浆鏇存柊鎴栬�呭垹闄よ鍗�
 const getTableRow =  (row,type) => {
   switch (type) {
@@ -493,23 +496,82 @@
                 orderBomDetails.value=res.data.data
                 orderBomData.value.productName.forEach((product, i) => {
                   const details = orderBomDetails.value[i]?.data || []
+                  const perimeter = Number(product.perimeter || 0)
+
+                  // hollow锛氶噸绠� consume銆乵aterialPric
+                  details.forEach(d => {
+                    if (d.detail_type === 'hollow') {
+                      const glueDepth = Number(d.glueDepth || 0)
+                      const thickness = Number(d.thickness || 0)
+                      const price = Number(d.price || 0)
+
+                      // consume 淇濇寔涓烘暟瀛�
+                      const consume = (glueDepth / 100) * (thickness / 100) * perimeter
+                      d.consume = Number(consume.toFixed(2))   // 闇�瑕佷繚鐣�2浣嶅氨杞洖 number
+
+                      // materialPric 涔熶繚鎸佷负鏁板瓧
+                      d.materialPric = Number((d.consume * price).toFixed(2))
+                    }
+                  })
 
                   // 鐢熸垚 parts
                   const parts = product.product_name.split(/[*+]/)
                   parts.push("鍏跺畠")
 
                   product.product_parts = parts.map((p, idx) => {
-                    // 鎵惧嚭鎵�鏈� product_layer == idx+1 鐨� detail
-                    const assignedDetails = details.filter(d => d.product_layer === idx + 1)
-
-                    return {
-                      name: p,
-                      details: assignedDetails
-                    }
+                    const assignedDetails = details.filter(d => Number(d.product_layer) === idx + 1)
+                    return { name: p, details: assignedDetails }
                   })
-                  // 璁$畻鎬讳环
-                  product.totalPrice = details.reduce((sum, d) => sum + (d.materialPric || 0) , 0)
+
+                  // 姣忎釜 product 鐨勬�讳环锛堜繚璇佹暟瀛楃浉鍔狅級
+                  product.totalPrice = details.reduce(
+                      (sum, d) => sum + Number(d.materialPric || 0),
+                      0
+                  )
                 })
+
+                //  鎴愬搧鍚堣锛氫粠 details 姹囨��
+                const totalMap = new Map()
+
+                orderBomDetails.value.forEach(block => {
+                  const details = block?.data || []
+                  details.forEach(d => {
+                    const consume = Number(d.consume || 0)
+                    const price = Number(d.price || 0)
+                    const key = `${Number(d.material_id)}|${String(d.detail_type || '')}|${price}`
+
+                    if (!totalMap.has(key)) {
+                      totalMap.set(key, {
+                        material_id: d.material_id,
+                        material: d.material,
+                        detail_type: d.detail_type,
+                        price,
+                        unit: d.unit,
+                        type: d.type,
+                        consume: 0,
+                        materialPrice: 0
+                      })
+                    }
+
+                    const row = totalMap.get(key)
+                    row.consume += consume
+                  })
+                })
+
+                const totalSumDatilsData = Array.from(totalMap.values()).map(r => ({
+                  ...r,
+                  consume: Number(r.consume.toFixed(2)),
+                  materialPrice: Number(r.materialPrice.toFixed(2))
+                }))
+
+                bomSum.value.sumDatilsData = totalSumDatilsData
+
+                // 姹囨�绘�婚噾棰�
+                totalPriceSum.value = orderBomData.value.productName.reduce(
+                    (sum, p) => sum + Number(p.totalPrice || 0),
+                    0
+                )
+
                 dialogTableVisible.value = true
               }
             })
@@ -581,10 +643,7 @@
   }
 }
 
-//鎬讳环
-const totalPrice = computed(() => {
-  return bomSum.value.sumDatilsData.reduce((sum, d) => sum + d.materialPrice, 0)
-})
+
 </script>
 
 <template>
@@ -729,7 +788,7 @@
 
         <!-- footer -->
         <template #footer>
-          鍚堣 楼{{ totalPrice }}
+          鍚堣 楼{{ totalPriceSum }}
         </template>
       </el-card>
 

--
Gitblit v1.8.0