| | |
| | | selectOrderList() |
| | | } |
| | | |
| | | //总价 |
| | | const totalPriceSum = ref() |
| | | |
| | | //页面跳转更新或者删除订单 |
| | | const getTableRow = (row,type) => { |
| | | switch (type) { |
| | |
| | | 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、materialPric |
| | | 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 |
| | | } |
| | | }) |
| | |
| | | } |
| | | } |
| | | |
| | | //总价 |
| | | const totalPrice = computed(() => { |
| | | return bomSum.value.sumDatilsData.reduce((sum, d) => sum + d.materialPrice, 0) |
| | | }) |
| | | |
| | | </script> |
| | | |
| | | <template> |
| | |
| | | |
| | | <!-- footer --> |
| | | <template #footer> |
| | | 合计 ¥{{ totalPrice }} |
| | | 合计 ¥{{ totalPriceSum }} |
| | | </template> |
| | | </el-card> |
| | | |
| | |
| | | Object produceId = row.get("produceId"); |
| | | Object tabId = row.get("tabId"); |
| | | Object layer = row.get("layer"); |
| | | if (tabId!=null){ |
| | | bomDataMapper.saveProductBOMMp(produceId,tabId,layer); |
| | | } |
| | | |
| | | bomDataMapper.saveProductBOMMp(produceId,tabId,layer); |
| | | } |
| | | } |
| | | } |
| | |
| | | </select> |
| | | |
| | | <select id="getBOMDetails"> |
| | | select bp.*,bb.*,(consume*price) as materialPric,od.quantity from sd.bom_product as bp |
| | | select bp.*,bb.*,(consume*price) as materialPric,od.quantity,pdd.detail_type, |
| | | IFNULL(JSON_UNQUOTE(JSON_EXTRACT(pdd.separation, '$.GlueDepth')),0) as glueDepth, |
| | | CAST(SUBSTRING_INDEX(IFNULL(JSON_UNQUOTE(JSON_EXTRACT(pdd.separation, '$.thickness')), '0mm'), 'mm', 1) AS DECIMAL(10, 2)) AS thickness |
| | | from sd.bom_product as bp |
| | | left join sd.bom_base as bb on bb.id=bp.base_id |
| | | left join ( select order_id,product_id,SUM(quantity) as quantity from sd.order_detail GROUP BY order_id,product_id |
| | | ) as od on od.product_id = bp.product_id |
| | | left join sd.product_detail as pdd on pdd.prod_id = bp.product_id and pdd.sort_num = bp.product_layer |
| | | where bp.product_id = #{productId} and od.order_id = #{orderId} ORDER BY product_layer |
| | | </select> |
| | | |
| | |
| | | sum(bb.consume) as consume, |
| | | sum(bb.price) as price, |
| | | sum(bb.consume * bb.price) AS materialPrice, |
| | | od.quantity |
| | | od.quantity, |
| | | pdd.detail_type, |
| | | IFNULL( JSON_UNQUOTE( JSON_EXTRACT( pdd.separation, '$.GlueDepth' )), 0 ) AS glueDepth, |
| | | CAST( |
| | | SUBSTRING_INDEX( IFNULL( JSON_UNQUOTE( JSON_EXTRACT( pdd.separation, '$.thickness' )), '0mm' ), 'mm', 1 ) AS DECIMAL ( 10, 2 )) AS thickness |
| | | FROM |
| | | sd.bom_product AS bp |
| | | LEFT JOIN sd.bom_base AS bb ON bb.id = bp.base_id |
| | | LEFT JOIN ( |
| | | select order_id,product_id,SUM(quantity) as quantity from sd.order_detail GROUP BY order_id,product_id |
| | | ) as od on od.product_id = bp.product_id |
| | | |
| | | LEFT JOIN sd.product_detail AS pdd ON pdd.prod_id = bp.product_id AND pdd.sort_num = bp.product_layer |
| | | WHERE od.order_id=#{orderId} |
| | | GROUP BY bb.material_id |
| | | ORDER BY bp.product_layer |