瀏覽代碼

fix:984【企业运营】营销管理的报价单支持新建导入bom清单查询物料价格

mlchen 1 周之前
父節點
當前提交
3dffd77da7

二進制
public/importTemplate/BOM导入模板.xls


+ 20 - 1
src/BIZComponents/inventoryTable.vue

@@ -1011,6 +1011,8 @@
         </template>
         <!-- 操作列 -->
         <template v-slot:action="scope">
+          <!-- 行内自定义操作:父组件传了 rowActions 插槽才渲染,未传时行为与本改动前完全一致 -->
+          <slot name="rowActions" :row="scope.row" :index="scope.$index"></slot>
           <el-popconfirm
             class="ele-action"
             title="确定要删除吗?"
@@ -1311,6 +1313,11 @@
         type: Boolean,
         default: false
       },
+      // 操作列宽度:传入 rowActions 插槽(如报价单的 BOM导入/BOM详情)时可放宽,不传沿用 120
+      rowActionWidth: {
+        type: Number,
+        default: 120
+      },
       isSupplier: {
         //供应商
         type: Boolean,
@@ -2063,7 +2070,7 @@
           {
             columnKey: 'action',
             label: '操作',
-            width: 120,
+            width: this.rowActionWidth,
             align: 'center',
             resizable: false,
             slot: 'action',
@@ -2834,6 +2841,18 @@
       },
       buildProductRow(item, oldRow, key) {
         const row = oldRow ? copyObj(oldRow) : copyObj(this.defaultForm);
+        // 切换产品(oldRow 存在):原 BOM 属于已换掉的产品,必须清空;
+        // 若该行单价是 BOM导入回填的(行上有 bomList),一并归零,避免新产品沿用旧成本价
+        if (oldRow) {
+          const hadBom = Array.isArray(row.bomList) && row.bomList.length > 0;
+          row.bomList = [];
+          row.rowKey = '';
+          if (hadBom) {
+            row.singlePrice = 0;
+            row.notaxSinglePrice = 0;
+            row.totalPrice = 0;
+          }
+        }
         const warrantyPeriodUnit = item.warrantyPeriodUnit
           ? item.warrantyPeriodUnit + ''
           : '';

+ 38 - 5
src/BIZComponents/inventoryTableDetails.vue

@@ -146,6 +146,16 @@
         </el-form-item>
       </template>
 
+      <template v-slot:bomAction="scope">
+        <el-link
+          type="primary"
+          :underline="false"
+          icon="el-icon-document"
+          @click.native="openBomDetail(scope.row)"
+        >
+          BOM详情<span v-if="rowBomCount(scope.row)">({{ rowBomCount(scope.row) }})</span>
+        </el-link>
+      </template>
       <!-- 表头工具栏 -->
       <template v-slot:toolbar>
         <div class="headbox">
@@ -192,6 +202,11 @@
       timeDialog
     },
     props: {
+      // 是否显示「操作」列(BOM详情):只有报价单详情传 true,其它单据不受影响
+      showBomDetail: {
+        default: false,
+        type: Boolean
+      },
       isDiscountTotalPrice: {
         default: false,
         type: Boolean
@@ -1021,11 +1036,22 @@
         ];
 
         // 合并所有列,统一应用列宽缓存(无缓存时保持默认宽度)
-        return this.applyColumnWidth(
-          [...baseColumns, ...additionalColumns, ...remainingColumns].filter(
-            (item) => !item.isNone
-          )
-        );
+        const mergedColumns = [
+          ...baseColumns,
+          ...additionalColumns,
+          ...remainingColumns
+        ].filter((item) => !item.isNone);
+        if (this.showBomDetail) {
+          mergedColumns.push({
+            width: 130,
+            columnKey: 'bomAction',
+            label: '操作',
+            slot: 'bomAction',
+            fixed: 'right',
+            align: 'center'
+          });
+        }
+        return this.applyColumnWidth(mergedColumns);
       }
     },
     created() {
@@ -1168,6 +1194,13 @@
           .format('YYYY-MM-DD');
       },
       //修改回显
+      rowBomCount(row) {
+        return row && Array.isArray(row.bomList) ? row.bomList.length : 0;
+      },
+      // 交给父组件(报价单详情)打开 BOM 详情弹窗
+      openBomDetail(row) {
+        this.$emit('showBomDetail', row);
+      },
       async putTableValue(data) {
         console.log(data, 'data');
         // 存储data中的type值,用于控制新增字段显示

+ 361 - 0
src/utils/quotationBom.js

@@ -0,0 +1,361 @@
+/**
+ * 报价单「BOM导入」纯逻辑:模板列定义、模版解析、取价规则、价格计算。
+ * 不依赖组件上下文(无 $/axios/window),便于单测与复用。
+ *
+ * 取价规则(需求原文):
+ *  1. 按物料编码(物品编码)调用 eom/goods/page 查出该物品的价格;
+ *  2. 价格查不到按 0;
+ *  3. 多个价格取接口返回的第一条;没有上架(t_eom_goods.goods_status != 1)
+ *     或该商品没有设置任何价格,一律按 0。
+ */
+
+/* 模版文件(放在 public/importTemplate 下,与项目其它导入模版同目录) */
+export const BOM_TEMPLATE_NAME = 'BOM导入模板';
+export const BOM_TEMPLATE_URL = '/eos/importTemplate/BOM导入模板.xls';
+
+/* 价格与金额统一保留 4 位小数,与后端 decimal(15,4)/decimal(18,4) 对齐 */
+export const BOM_PRICE_SCALE = 4;
+
+/*
+ * 与「BOM导入模板.xls」第 2 行表头一一对应;第 1 行是说明行,解析时自动跳过。
+ * 文字列用 minWidth(宽度不足时由表格均分剩余空间,避免右侧留白),
+ * 数字/标签列用固定 width;全部对齐方式与系统其它表格一致(居中 + 超出省略提示)。
+ */
+const textColumn = (prop, label, minWidth) => ({
+  prop: prop,
+  label: label,
+  minWidth: minWidth,
+  align: 'center',
+  showOverflowTooltip: true
+});
+
+const numberColumn = (prop, label, width) => ({
+  prop: prop,
+  label: label,
+  width: width,
+  align: 'center',
+  showOverflowTooltip: true
+});
+
+export const BOM_TEMPLATE_COLUMNS = [
+  textColumn('bomCategory', '物料分类', 180),
+  numberColumn('bomLevel', '级次', 70),
+  textColumn('parentMaterialCode', '父级物料编码', 140),
+  textColumn('materialCode', '物料编码', 150),
+  numberColumn('dosage', '用量', 80),
+  textColumn('name', '名称', 160),
+  textColumn('specification', '规格', 160),
+  textColumn('supplierInfo', '供应商信息', 130)
+];
+
+/* 详情弹窗展示列 = 模版列 + 价格列 */
+export const BOM_DETAIL_COLUMNS = BOM_TEMPLATE_COLUMNS.concat([
+  numberColumn('quantity', '数量', 90),
+  textColumn('taxPrice', '含税单价', 110),
+  numberColumn('taxRate', '税率(%)', 90),
+  textColumn('notaxPrice', '不含税单价', 120),
+  textColumn('totalPrice', '总价', 110)
+]);
+
+/* 模版必填列(带 * 的列),供应商信息非必填 */
+const REQUIRED_PROPS = [
+  'bomCategory',
+  'bomLevel',
+  'parentMaterialCode',
+  'materialCode',
+  'dosage',
+  'name',
+  'specification'
+];
+
+/*
+ * 模版自带的示例 BOM(示例树:产品-工程机械行业-顺新产品 / 物料-顺新物料)。
+ * 只是填写示例,不属于真实业务数据,导入时必须过滤掉。
+ * 判定要求「分类与编码同时命中」,避免误伤真实数据里同编码的物料。
+ */
+export const BOM_TEMPLATE_DEMO_CATEGORIES = ['产品-工程机械行业-顺新产品', '物料-顺新物料'];
+export const BOM_TEMPLATE_DEMO_CODES = [
+  'TQWV5-00-00',
+  'PZM-1500-00',
+  'PZM-1500-01',
+  'PZM-1500-01-03',
+  'PZM-1500-01-01',
+  'PZM-1500-01-04',
+  'PZM-1500-01-05'
+];
+
+/** 是否为模版自带的示例行 */
+export function isTemplateDemoLine(line) {
+  if (!line) return false;
+  const category = normalizeCell(line.bomCategory);
+  const code = normalizeCell(line.materialCode);
+  if (BOM_TEMPLATE_DEMO_CODES.indexOf(code) < 0) return false;
+  return BOM_TEMPLATE_DEMO_CATEGORIES.some(
+    (demoCategory) => category === demoCategory || category.indexOf(demoCategory + '-') === 0
+  );
+}
+
+/* 空价格:查不到商品 / 商品未上架 / 商品无价格,一律按 0 参与计算 */
+export const EMPTY_PRICE = {
+  goodsId: null,
+  goodsPriceId: null,
+  priceType: '',
+  taxPrice: 0,
+  taxRate: null,
+  notaxPrice: 0,
+  shelfStatus: 0
+};
+
+export function toNumber(value, fallback) {
+  if (value === null || value === undefined || value === '') {
+    return fallback === undefined ? 0 : fallback;
+  }
+  const num = Number(value);
+  return Number.isFinite(num) ? num : fallback === undefined ? 0 : fallback;
+}
+
+export function round(value, digits) {
+  const scale = digits === undefined ? BOM_PRICE_SCALE : digits;
+  const num = toNumber(value, 0);
+  const factor = Math.pow(10, scale);
+  return Math.round((num + Number.EPSILON) * factor) / factor;
+}
+
+function normalizeCell(cell) {
+  return String(cell === null || cell === undefined ? '' : cell).trim();
+}
+
+/**
+ * 解析模版二维数组。
+ * @param {Array<Array>} matrix xlsx 读出的二维数组(header:1)
+ * @returns {{lines: Array, errors: Array<string>}}
+ */
+export function parseBomRows(matrix) {
+  const rows = Array.isArray(matrix) ? matrix : [];
+  const headerIndex = rows.findIndex((row) =>
+    (Array.isArray(row) ? row : []).some((cell) => normalizeCell(cell).indexOf('物料编码') > -1)
+  );
+  if (headerIndex < 0) {
+    return { lines: [], errors: ['未识别到表头行,请使用标准「BOM导入模板」'] };
+  }
+  const header = (Array.isArray(rows[headerIndex]) ? rows[headerIndex] : []).map((cell) =>
+    normalizeCell(cell).replace(/^\*+/, '')
+  );
+  const columns = BOM_TEMPLATE_COLUMNS.map((column) => ({
+    prop: column.prop,
+    label: column.label,
+    index: header.indexOf(column.label)
+  }));
+  const missing = columns
+    .filter((column) => REQUIRED_PROPS.indexOf(column.prop) > -1 && column.index < 0)
+    .map((column) => column.label);
+  if (missing.length) {
+    return { lines: [], errors: ['模版缺少必要列:' + missing.join('、')] };
+  }
+
+  const lines = [];
+  const errors = [];
+  const skipped = [];
+  for (let i = headerIndex + 1; i < rows.length; i++) {
+    const row = Array.isArray(rows[i]) ? rows[i] : [];
+    const rowNo = i + 1;
+    if (row.every((cell) => !normalizeCell(cell))) {
+      continue;
+    }
+    const cellOf = (prop) => {
+      const column = columns.find((item) => item.prop === prop);
+      return column && column.index > -1 ? row[column.index] : '';
+    };
+    const materialCode = normalizeCell(cellOf('materialCode'));
+    if (!materialCode) {
+      // 有内容却缺物料编码:属填写问题,明确指出是哪一行
+      errors.push('第' + rowNo + '行:物料编码不能为空');
+      continue;
+    }
+    const line = {
+      sort: lines.length + 1,
+      bomCategory: normalizeCell(cellOf('bomCategory')),
+      bomLevel: toNumber(cellOf('bomLevel'), 1),
+      parentMaterialCode: normalizeCell(cellOf('parentMaterialCode')),
+      materialCode: materialCode,
+      dosage: toNumber(cellOf('dosage'), 0),
+      name: normalizeCell(cellOf('name')),
+      specification: normalizeCell(cellOf('specification')),
+      supplierInfo: normalizeCell(cellOf('supplierInfo'))
+    };
+    if (isTemplateDemoLine(line)) {
+      // 模版自带的填写示例(如 产品-工程机械行业-顺新产品 / TQWV5-00-00 多功能提取罐)
+      // 静默丢弃,不打扰用户
+      skipped.push({ rowNo: rowNo, reason: '模版示例行' });
+      continue;
+    }
+    if (!line.name) {
+      errors.push('第' + rowNo + '行:名称不能为空');
+      continue;
+    }
+    lines.push(line);
+  }
+  if (!lines.length && !errors.length) {
+    errors.push('模版中没有可导入的数据行');
+  }
+  return { lines: lines, errors: errors, skipped: skipped };
+}
+
+/* 物料编码与商品编码 / 物品编码(categoryInfo.code)任一相等即命中 */
+function goodsMatchesCode(goods, code) {
+  if (!goods) return false;
+  if (normalizeCell(goods.goodsCode) === code) return true;
+  const categoryInfo = goods.categoryInfo;
+  return !!categoryInfo && normalizeCell(categoryInfo.code) === code;
+}
+
+/**
+ * 用一个物品编码取出单价。
+ * 候选 = 命中该编码且已上架(goodsStatus === 1)的商品下的全部价格;
+ * 多个价格按接口返回顺序取第一条(需求:有多个价格就取第一条)。
+ * 未命中 / 未上架 / 未设置价格 -> EMPTY_PRICE(各项 0),流程不报错。
+ */
+export function pickGoodsPrice(goodsList, materialCode) {
+  const code = normalizeCell(materialCode);
+  if (!code || !Array.isArray(goodsList) || !goodsList.length) {
+    return Object.assign({}, EMPTY_PRICE);
+  }
+  const matched = goodsList.filter((goods) => goodsMatchesCode(goods, code));
+  if (!matched.length) return Object.assign({}, EMPTY_PRICE);
+  const onShelf = matched.filter((goods) => Number(goods.goodsStatus) === 1);
+  if (!onShelf.length) return Object.assign({}, EMPTY_PRICE);
+
+  const candidates = [];
+  onShelf.forEach((goods) => {
+    (goods.goodsPriceList || []).forEach((price) => {
+      candidates.push({ goods: goods, price: price });
+    });
+  });
+  if (!candidates.length) return Object.assign({}, EMPTY_PRICE);
+
+  const picked = candidates[0];
+  const taxPrice = round(toNumber(picked.price.unitPrice, 0));
+  const taxRate =
+    picked.price.taxRate === null || picked.price.taxRate === undefined
+      ? null
+      : round(picked.price.taxRate, 2);
+  const notaxFromPrice =
+    picked.price.excludeTaxPrice === null || picked.price.excludeTaxPrice === undefined
+      ? null
+      : toNumber(picked.price.excludeTaxPrice, 0);
+  return {
+    goodsId: picked.goods.id === undefined ? null : picked.goods.id,
+    goodsPriceId: picked.price.id === undefined ? null : picked.price.id,
+    priceType: picked.price.priceType || '',
+    taxPrice: taxPrice,
+    taxRate: taxRate,
+    notaxPrice: round(
+      notaxFromPrice === null ? taxPrice / (1 + toNumber(taxRate, 0) / 100) : notaxFromPrice
+    ),
+    shelfStatus: 1
+  };
+}
+
+/**
+ * 用量 -> 数量:数量 = 用量 × 物品清单行数量(明细数量为空或 0 时按 1 计)。
+ */
+export function calcBomQuantity(dosage, lineCount) {
+  const count = toNumber(lineCount, 0);
+  const base = count > 0 ? count : 1;
+  return round(toNumber(dosage, 0) * base);
+}
+
+/**
+ * 生成入库用的 BOM 明细行(模版字段 + 价格字段 + 关联字段)。
+ * @param {Array} templateLines parseBomRows().lines
+ * @param {{quantity: number, priceMap: Object, quoteId: (string|number), quoteProductId: (string|number), rowKey: string}} ctx
+ */
+export function buildBomLines(templateLines, ctx) {
+  const options = ctx || {};
+  const priceMap = options.priceMap || {};
+  return (templateLines || []).map((line) => {
+    const price = priceMap[line.materialCode] || EMPTY_PRICE;
+    const quantity = calcBomQuantity(line.dosage, options.quantity);
+    const taxPrice = round(toNumber(price.taxPrice, 0));
+    return Object.assign({}, line, {
+      quoteId: options.quoteId || 0,
+      quoteProductId: options.quoteProductId || 0,
+      rowKey: options.rowKey || '',
+      quantity: quantity,
+      taxPrice: taxPrice,
+      taxRate: price.taxRate === undefined ? null : price.taxRate,
+      notaxPrice: round(toNumber(price.notaxPrice, 0)),
+      totalPrice: round(taxPrice * quantity),
+      goodsId: price.goodsId === undefined ? null : price.goodsId,
+      goodsPriceId: price.goodsPriceId === undefined ? null : price.goodsPriceId,
+      shelfStatus: toNumber(price.shelfStatus, 0)
+    });
+  });
+}
+
+/* BOM 合计总价 = Σ(含税单价 × 数量) */
+export function sumBomTotalPrice(bomList) {
+  return round(
+    (bomList || []).reduce((total, item) => total + toNumber(item.totalPrice, 0), 0)
+  );
+}
+
+/**
+ * 回填到物品清单行的单价:单位成本 = Σ(含税单价 × 用量)。
+ * 与 BOM 行 quantity/totalPrice 同源,保证「单价 × 明细数量」等于「Σ BOM 总价」。
+ */
+export function sumBomUnitPrice(bomList) {
+  return round(
+    (bomList || []).reduce(
+      (total, item) => total + toNumber(item.taxPrice, 0) * toNumber(item.dosage, 0),
+      0
+    )
+  );
+}
+
+/* 从 BOM 行中取一个税率回填明细行(多个时取第一个非空) */
+export function pickBomTaxRate(bomList) {
+  const found = (bomList || []).find(
+    (item) => item.taxRate !== null && item.taxRate !== undefined
+  );
+  return found ? found.taxRate : null;
+}
+
+/**
+ * 物品清单行的回填价格:含税单价、不含税单价、税率。
+ */
+export function buildRowPrice(bomList) {
+  const singlePrice = sumBomUnitPrice(bomList);
+  const taxRate = pickBomTaxRate(bomList);
+  const notaxSinglePrice =
+    taxRate === null ? singlePrice : round(singlePrice / (1 + toNumber(taxRate, 0) / 100), 2);
+  return {
+    singlePrice: singlePrice,
+    notaxSinglePrice: notaxSinglePrice,
+    taxRate: taxRate
+  };
+}
+
+/**
+ * 物品清单行的稳定键:已落库行用明细行 id,新增行用前端生成的 uuid。
+ * 服务端以 row_key 做「同一明细数据」的判重与覆盖依据。
+ */
+export function buildRowKey(row, index) {
+  if (row && row.id !== undefined && row.id !== null && row.id !== '') {
+    return String(row.id);
+  }
+  const seed = [Date.now(), index, Math.random()].join('-');
+  return 'tmp-' + seed.replace(/[^0-9a-zA-Z-]/g, '').slice(0, 48);
+}
+
+/**
+ * 分片:按物料编码查价时控制并发,避免一次性打爆 eom/goods/page。
+ */
+export function chunkList(list, size) {
+  const step = size > 0 ? size : 1;
+  const chunks = [];
+  for (let i = 0; i < (list || []).length; i += step) {
+    chunks.push(list.slice(i, i + step));
+  }
+  return chunks;
+}

+ 87 - 2
src/views/saleManage/quotation/components/addDialog.vue

@@ -229,7 +229,28 @@
         :cacheKeyUrl="cacheKeyUrl"
         :quoteType="form.type"
         :isHideProductionRequirements="true"
-      ></inventoryTable>
+        :rowActionWidth="260"
+      >
+        <!-- 行内操作:BOM导入 / BOM详情(仅报价单传入,其它单据不受影响) -->
+        <template v-slot:rowActions="{ row, index }">
+          <el-link
+            type="primary"
+            :underline="false"
+            icon="el-icon-upload2"
+            @click="openBomImport(row, index)"
+          >
+            BOM导入
+          </el-link>
+          <el-link
+            type="primary"
+            :underline="false"
+            icon="el-icon-document"
+            @click="openBomDetail(row, index)"
+          >
+            BOM详情<span v-if="bomCount(row)">({{ bomCount(row) }})</span>
+          </el-link>
+        </template>
+      </inventoryTable>
 
       <!-- <el-row style="margin-top: 20px">
         <el-col :span="6">
@@ -279,6 +300,11 @@
       ref="processSubmitDialogRef"
       @reload="reload"
     ></process-submit-dialog>
+    <bom-import-dialog
+      ref="bomImportDialogRef"
+      @success="handleBomImported"
+    ></bom-import-dialog>
+    <bom-detail-dialog ref="bomDetailDialogRef"></bom-detail-dialog>
   </ele-modal>
 </template>
 
@@ -313,6 +339,9 @@ import { copyObj } from '@/utils/util';
 import { contactDetail, updateRelationStatus } from '@/api/saleManage/contact';
 // import fileMain from '@/components/addDoc/index.vue';
 import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
+import bomImportDialog from './bomImportDialog.vue';
+import bomDetailDialog from './bomDetailDialog.vue';
+import { buildRowKey } from '@/utils/quotationBom';
 
 export default {
   props: {
@@ -337,7 +366,9 @@ export default {
     inventoryTable,
     deptSelect,
     parentList,
-    personSelect
+    personSelect,
+    bomImportDialog,
+    bomDetailDialog
   },
   data() {
     let formDef = {
@@ -758,6 +789,60 @@ export default {
         })
       ]);
     },
+    /* ===== BOM导入 / BOM详情 ===== */
+    bomCount(row) {
+      return row && Array.isArray(row.bomList) ? row.bomList.length : 0;
+    },
+    // 物品清单行的稳定唯一键:已落库行用明细行id,新增行生成 uuid(服务端据此判重覆盖)
+    bomRowKey(row, index) {
+      if (!row.rowKey) {
+        this.$set(row, 'rowKey', buildRowKey(row, index));
+      }
+      return row.rowKey;
+    },
+    openBomImport(row, index) {
+      this.$refs.bomImportDialogRef.open({
+        row: row,
+        index: index,
+        quoteId: this.form.id,
+        rowKey: this.bomRowKey(row, index)
+      });
+    },
+    openBomDetail(row, index) {
+      this.$refs.bomDetailDialogRef.open({
+        row: row,
+        index: index,
+        quoteId: this.form.id,
+        rowKey: this.bomRowKey(row, index)
+      });
+    },
+    // 导入成功:BOM 挂到清单行(随报价单一起提交),累计价格回填到该行单价
+    handleBomImported(payload) {
+      const row = (payload && payload.row) || {};
+      const price = (payload && payload.price) || {};
+      const bomList = (payload && payload.bomList) || [];
+      this.$set(row, 'bomList', bomList);
+      this.$set(row, 'singlePrice', price.singlePrice);
+      this.$set(row, 'notaxSinglePrice', price.notaxSinglePrice);
+      if (price.taxRate !== null && price.taxRate !== undefined) {
+        this.$set(row, 'taxRate', price.taxRate);
+      }
+      const count = Number(row.totalCount) || 0;
+      const weight = Number(row.singleWeight) || 0;
+      // 与清单表自身口径一致:按数量计价 单价×数量;按重量计价 单价×数量×单重
+      const rowAmount =
+        Number(row.pricingWay) === 2
+          ? price.singlePrice * count * weight
+          : price.singlePrice * count;
+      this.$set(row, 'totalPrice', Number(rowAmount.toFixed(4)));
+      // 单价/总价被外部改写后必须让清单表重算「总计」,否则重新导入后总计不刷新
+      this.$nextTick(() => {
+        const table = this.$refs.inventoryTable;
+        if (table && typeof table.changeAll === 'function') {
+          table.changeAll();
+        }
+      });
+    },
     async save(type) {
       try {
         await this.getValidate();

+ 117 - 0
src/views/saleManage/quotation/components/bomDetailDialog.vue

@@ -0,0 +1,117 @@
+<template>
+  <el-dialog
+    :title="dialogTitle"
+    :visible.sync="dialogVisible"
+    :close-on-click-modal="false"
+    append-to-body
+    width="80%"
+    top="5vh"
+    custom-class="ele-dialog-form"
+    @close="close"
+  >
+    <el-card shadow="never">
+      <el-alert
+        v-if="!bomList.length"
+        type="info"
+        :closable="false"
+        show-icon
+        title="该明细行暂无 BOM 数据"
+      />
+
+      <ele-pro-table
+        v-else
+        ref="table"
+        :need-page="false"
+        :columns="columns"
+        :datasource="bomList"
+        row-key="materialCode"
+        max-height="420px"
+        class="dict-table"
+      >
+        <template v-slot:shelf="{ row: item }">
+          <el-tag v-if="toNumber(item.shelfStatus, 0) === 1" type="success" size="small">
+            已上架
+          </el-tag>
+          <el-tag v-else type="info" size="small">按0</el-tag>
+        </template>
+      </ele-pro-table>
+
+      <div class="bom-summary" v-if="bomList.length">
+        <span class="amount">数量:{{ toNumber(row.totalCount, 0) }}</span>
+        <span class="amount">单价:{{ formatAmount(row.singlePrice) }}元</span>
+        <span class="amount">BOM条数:{{ bomList.length }}</span>
+        <span class="amount">总计:{{ formatAmount(sumTotal) }}元</span>
+      </div>
+    </el-card>
+
+    <div slot="footer" class="dialog-footer">
+      <el-button size="small" @click="close">关 闭</el-button>
+    </div>
+  </el-dialog>
+</template>
+
+<script>
+  import {
+    BOM_DETAIL_COLUMNS,
+    sumBomTotalPrice,
+    toNumber
+  } from '@/utils/quotationBom';
+
+  export default {
+    name: 'BomDetailDialog',
+    data() {
+      return {
+        dialogVisible: false,
+        row: {},
+        quoteId: '',
+        rowKey: '',
+        bomList: [],
+        columns: BOM_DETAIL_COLUMNS.concat([
+          { columnKey: 'shelf', label: '状态', width: 90, align: 'center', slot: 'shelf' }
+        ])
+      };
+    },
+    computed: {
+      dialogTitle() {
+        const name = this.row && this.row.productName ? this.row.productName : '';
+        return name ? 'BOM详情 - ' + name : 'BOM详情';
+      },
+      sumTotal() {
+        return sumBomTotalPrice(this.bomList);
+      }
+    },
+    methods: {
+      toNumber(value, fallback) {
+        return toNumber(value, fallback);
+      },
+      formatAmount(value) {
+        return toNumber(value, 0).toFixed(4);
+      },
+      /* 父组件调用:数据来自行上 bomList(报价单 getById 已按产品回填,见 QuoteServiceImpl#fillBomList) */
+      open(payload) {
+        const params = payload || {};
+        this.dialogVisible = true;
+        this.row = params.row || {};
+        this.quoteId = params.quoteId || '';
+        this.rowKey = params.rowKey || '';
+        this.bomList = Array.isArray(this.row.bomList) ? this.row.bomList : [];
+      },
+      close() {
+        this.dialogVisible = false;
+      }
+    }
+  };
+</script>
+
+<style lang="scss" scoped>
+  .bom-summary {
+    margin-top: 8px;
+    text-align: right;
+  }
+
+  .bom-summary .amount {
+    margin-left: 20px;
+    font-size: 13px;
+    color: #606266;
+  }
+</style>

+ 336 - 0
src/views/saleManage/quotation/components/bomImportDialog.vue

@@ -0,0 +1,336 @@
+<template>
+  <el-dialog
+    :title="dialogTitle"
+    :visible.sync="dialogVisible"
+    :close-on-click-modal="false"
+    :close-on-press-escape="false"
+    append-to-body
+    width="80%"
+    top="5vh"
+    custom-class="ele-dialog-form"
+    @close="close"
+  >
+    <el-card shadow="never">
+      <el-form size="small" label-width="80px" class="zw-criterion" @submit.native.prevent>
+        <el-form-item label="选择文件">
+          <div class="bom-upload">
+            <el-upload
+              action="#"
+              :show-file-list="false"
+              :http-request="handleUpload"
+              accept=".xls,.xlsx"
+              :disabled="loading"
+            >
+              <el-button size="small" type="primary" icon="el-icon-upload2" :loading="loading">
+                文件上传
+              </el-button>
+            </el-upload>
+            <span class="bom-upload-tip">
+              只能上传 excel 文件(.xls/.xlsx),点击
+              <el-link type="primary" :underline="false" @click="downloadTemplate">
+                下载《BOM导入模板》
+              </el-link>
+            </span>
+            <span class="bom-upload-file" v-if="fileName">{{ fileName }}</span>
+          </div>
+        </el-form-item>
+      </el-form>
+
+      <el-alert
+        v-for="(item, index) in errors"
+        :key="index"
+        type="error"
+        :closable="false"
+        show-icon
+        :title="item"
+        class="bom-alert"
+      />
+
+      <ele-pro-table
+        ref="table"
+        :need-page="false"
+        :columns="columns"
+        :datasource="bomList"
+        row-key="materialCode"
+        v-loading="loading"
+        max-height="320px"
+        class="dict-table"
+      >
+        <template v-slot:shelf="{ row: item }">
+          <el-tag v-if="toNumber(item.shelfStatus, 0) === 1" type="success" size="small">
+            已上架
+          </el-tag>
+          <el-tag v-else type="info" size="small">按0</el-tag>
+        </template>
+      </ele-pro-table>
+
+      <div class="bom-summary" v-if="bomList.length">
+        <span class="amount">BOM条数:{{ bomList.length }}</span>
+        <span class="amount">总计:{{ formatAmount(sumTotal) }}元</span>
+        <span class="amount">回填单价:{{ formatAmount(rowPrice.singlePrice) }}元</span>
+      </div>
+    </el-card>
+
+    <div slot="footer" class="dialog-footer">
+      <el-button size="small" @click="close">关 闭</el-button>
+      <el-button
+        size="small"
+        type="primary"
+        :disabled="loading || !bomList.length"
+        v-click-once
+        @click="confirm"
+      >
+        确定导入
+      </el-button>
+    </div>
+  </el-dialog>
+</template>
+
+<script>
+  import * as XLSX from 'xlsx';
+  import { download1 } from '@/utils/file';
+  import { getList as getGoodsList } from '@/api/goodsManage';
+  import {
+    BOM_DETAIL_COLUMNS,
+    BOM_TEMPLATE_NAME,
+    BOM_TEMPLATE_URL,
+    chunkList,
+    parseBomRows,
+    pickGoodsPrice,
+    buildBomLines,
+    buildRowPrice,
+    sumBomTotalPrice,
+    toNumber
+  } from '@/utils/quotationBom';
+
+  const PRICE_QUERY_CHUNK = 5;
+
+  export default {
+    name: 'BomImportDialog',
+    data() {
+      return {
+        dialogVisible: false,
+        loading: false,
+        fileName: '',
+        row: {},
+        rowIndex: -1,
+        quoteId: '',
+        rowKey: '',
+        bomList: [],
+        errors: [],
+        rowPrice: { singlePrice: 0, notaxSinglePrice: 0, taxRate: null },
+        columns: BOM_DETAIL_COLUMNS.concat([
+          { columnKey: 'shelf', label: '状态', width: 90, align: 'center', slot: 'shelf' }
+        ])
+      };
+    },
+    computed: {
+      dialogTitle() {
+        const name = this.row && this.row.productName ? this.row.productName : '';
+        return name ? 'BOM导入 - ' + name : 'BOM导入';
+      },
+      sumTotal() {
+        return sumBomTotalPrice(this.bomList);
+      }
+    },
+    methods: {
+      toNumber(value, fallback) {
+        return toNumber(value, fallback);
+      },
+      formatAmount(value) {
+        return toNumber(value, 0).toFixed(4);
+      },
+      /* 父组件调用:row 为物品清单行对象,index 为行下标 */
+      open(payload) {
+        const params = payload || {};
+        this.dialogVisible = true;
+        this.row = params.row || {};
+        this.rowIndex = params.index === undefined ? -1 : params.index;
+        this.quoteId = params.quoteId || '';
+        this.rowKey = params.rowKey || '';
+        this.fileName = '';
+        this.errors = [];
+        this.bomList = [];
+        this.rowPrice = { singlePrice: 0, notaxSinglePrice: 0, taxRate: null };
+      },
+      close() {
+        this.dialogVisible = false;
+        this.loading = false;
+      },
+      downloadTemplate() {
+        download1(window.location.origin + BOM_TEMPLATE_URL, BOM_TEMPLATE_NAME);
+      },
+      /* 读文件 -> 解析模版 -> 按物料编码取价 -> 计算数量与价格 */
+      async handleUpload(param) {
+        const file = param && param.file;
+        if (!file) return;
+        this.loading = true;
+        this.fileName = file.name;
+        this.errors = [];
+        try {
+          const matrix = await this.readSheet(file);
+          const parsed = parseBomRows(matrix);
+          if (parsed.errors.length) {
+            // 只回报有问题的行(第N行 + 原因),示例行/空行静默丢弃;其余行照常导入
+            this.errors = parsed.errors;
+          }
+          if (!parsed.lines.length) {
+            this.bomList = [];
+            this.rowPrice = { singlePrice: 0, notaxSinglePrice: 0, taxRate: null };
+            return;
+          }
+          const priceMap = await this.loadPriceMap(parsed.lines);
+          const bomList = buildBomLines(parsed.lines, {
+            quantity: this.row.totalCount,
+            priceMap: priceMap,
+            quoteId: this.quoteId,
+            quoteProductId: this.row.id,
+            rowKey: this.rowKey
+          });
+          this.bomList = bomList;
+          this.rowPrice = buildRowPrice(bomList);
+          const missCodes = bomList
+            .filter((item) => toNumber(item.shelfStatus, 0) !== 1)
+            .map((item) => item.materialCode);
+          if (missCodes.length) {
+            this.errors = this.errors.concat([
+              '以下物料编码未取到上架价格,已按 0 计算:' + missCodes.join('、')
+            ]);
+          }
+        } catch (error) {
+          this.errors = ['文件解析失败:' + (error && error.message ? error.message : error)];
+          this.bomList = [];
+        } finally {
+          this.loading = false;
+        }
+      },
+      readSheet(file) {
+        return new Promise((resolve, reject) => {
+          const reader = new FileReader();
+          reader.onload = (event) => {
+            try {
+              const workbook = XLSX.read(new Uint8Array(event.target.result), {
+                type: 'array'
+              });
+              const firstSheet = workbook.Sheets[workbook.SheetNames[0]];
+              resolve(
+                XLSX.utils.sheet_to_json(firstSheet, { header: 1, raw: false, defval: '' })
+              );
+            } catch (error) {
+              reject(error);
+            }
+          };
+          reader.onerror = reject;
+          reader.readAsArrayBuffer(file);
+        });
+      },
+      /* 按物料编码调 eom/goods/page,命中后按「优先上架、多价格取第一条」取价;查不到就是 0 */
+      async loadPriceMap(lines) {
+        const codes = [];
+        (lines || []).forEach((line) => {
+          if (line.materialCode && codes.indexOf(line.materialCode) < 0) {
+            codes.push(line.materialCode);
+          }
+        });
+        const priceMap = {};
+        const groups = chunkList(codes, PRICE_QUERY_CHUNK);
+        for (let i = 0; i < groups.length; i++) {
+          const results = await Promise.all(
+            groups[i].map((code) => this.queryGoodsByCode(code))
+          );
+          groups[i].forEach((code, index) => {
+            priceMap[code] = pickGoodsPrice(results[index], code);
+          });
+        }
+        return priceMap;
+      },
+      async queryGoodsByCode(code) {
+        try {
+          // pageNum/size 是后端 PaginationPO 的分页字段(不是 pageSize)
+          const res = await getGoodsList({
+            searchName: code,
+            pageNum: 1,
+            size: 50
+          });
+          if (Array.isArray(res)) return res;
+          if (res && Array.isArray(res.list)) return res.list;
+          if (res && Array.isArray(res.records)) return res.records;
+          return [];
+        } catch (error) {
+          // 单个编码查询失败不影响整单导入,按 0 处理
+          return [];
+        }
+      },
+      confirm() {
+        if (!this.bomList.length) {
+          this.$message.warning('请先选择并解析模版文件');
+          return;
+        }
+        const existed = (this.row.bomList || []).length;
+        const tip = existed
+          ? '该物品清单行已有 ' +
+            existed +
+            ' 条 BOM 数据,确定覆盖导入 ' +
+            this.bomList.length +
+            ' 条吗?'
+          : '确定导入 ' + this.bomList.length + ' 条 BOM 数据吗?';
+        this.$confirm(tip, '提示', {
+          type: 'warning',
+          confirmButtonText: '确定',
+          cancelButtonText: '取消'
+        })
+          .then(() => this.doImport())
+          .catch(() => {});
+      },
+      doImport() {
+        // BOM 挂在物品清单行上,随报价单 save/update 一起提交,
+        // 由后端 QuoteProductServiceImpl#saveBomBatch 按产品整行覆盖落库(新增与修改同一套逻辑)。
+        this.$emit('success', {
+          bomList: this.bomList,
+          price: this.rowPrice,
+          row: this.row,
+          index: this.rowIndex,
+          rowKey: this.rowKey
+        });
+        this.$message.success('成功导入 ' + this.bomList.length + ' 条 BOM 数据');
+        this.close();
+      }
+    }
+  };
+</script>
+
+<style lang="scss" scoped>
+  .bom-upload {
+    display: flex;
+    align-items: center;
+    flex-wrap: wrap;
+  }
+
+  .bom-upload-tip {
+    margin-left: 12px;
+    font-size: 12px;
+    color: #909399;
+  }
+
+  .bom-upload-file {
+    margin-left: 12px;
+    font-size: 12px;
+    color: #606266;
+  }
+
+  .bom-alert {
+    margin-bottom: 8px;
+  }
+
+
+  .bom-summary {
+    margin-top: 8px;
+    text-align: right;
+  }
+
+  .bom-summary .amount {
+    margin-left: 20px;
+    font-size: 13px;
+    color: #606266;
+  }
+</style>

+ 12 - 1
src/views/saleManage/quotation/components/detailDialog.vue

@@ -155,7 +155,11 @@
           :cacheKeyUrl="cacheKeyUrl"
           :quoteType="detailData.type"
           :isHideProductionRequirements="true"
+          showBomDetail
+          @showBomDetail="openBomDetail"
         ></inventoryTabledetail>
+
+        <bomDetailDialog ref="bomDetailDialogRef"></bomDetailDialog>
       </el-form>
     </div>
 
@@ -331,6 +335,7 @@
   import { copyObj } from '@/utils/util';
   import bpmDetail from '@/views/bpm/processInstance/detail.vue';
   import inventoryTabledetail from '@/BIZComponents/inventoryTableDetails.vue';
+  import bomDetailDialog from './bomDetailDialog.vue';
   import { acceptUnpackoptions } from '@/enum/dict';
   // import fileMain from '@/components/addDoc/index.vue';
 
@@ -338,7 +343,8 @@
     mixins: [dictMixins],
     components: {
       bpmDetail,
-      inventoryTabledetail
+      inventoryTabledetail,
+      bomDetailDialog
       // fileMain
     },
     data() {
@@ -493,6 +499,11 @@
       };
     },
     methods: {
+      // 查看该物品清单行已导入的 BOM(数据来自 eom/quote/getById 的 quoteProductList[].bomList)
+      openBomDetail(row) {
+        this.$refs.bomDetailDialogRef &&
+          this.$refs.bomDetailDialogRef.open({ row: row });
+      },
       //导出
       async exportTable() {
         const response = await exportByPathId(this.detailId);