| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * wc/ph-bom.js —— BOM 拆解(详情页与实验室共用)。
- * 桌面:按 group 分组的表格(序号 / 件名 / 规格 / 供应商 / 单价 / 数量 / 小计);
- * 手机:每组一行「件名 + 右侧小计」,点开展开规格与其余字段。
- * 可变宽度自适应切换用容器内 CSS 容器查询(实验室坞很窄时同样切成卡片)。
- */
- import { html, LitElement } from 'lit';
- // 样式见 wc/styles/bom-style.js(vendor lit-html 的 css`` 在部分源码上解析异常,改为静态文本注入)
- import { bomGroups } from '../services/products.js';
- import { money, num } from '../utils/format.js';
- import { applyCss } from '../lib/css.js';
- import { bomStyle } from './styles/bom-style.js';
- class PhBom extends LitElement {
- static properties = { bom: { attribute: false } };
- createRenderRoot() {
- applyCss(this, ...bomStyle); // light DOM + 页面级样式文本
- return this;
- }
- render() {
- const groups = bomGroups(this.bom);
- const total = this.bom?.bomTotal ?? groups.reduce((s, g) => s + g.subtotal, 0);
- return html`
- ${groups.map((g) => html`
- <section class="group">
- <div class="ghead">
- <h3>${g.group}</h3>
- <span class="gsum">${g.rows.length} 项 · <b>${money(g.subtotal)}</b></span>
- </div>
- <table>
- <thead><tr>
- <th class="seq">序号</th><th>件名</th><th>规格</th><th>供应商</th>
- <th class="r">单价</th><th class="r">数量</th><th class="r">小计</th>
- </tr></thead>
- <tbody>
- ${g.rows.map((r) => html`<tr>
- <td class="seq">${r.seq}</td>
- <td class="nm">${r.name}</td>
- <td class="sp">${r.spec}${r.notes ? html`<small>${r.notes}</small>` : ''}</td>
- <td class="sup">${r.supplier}</td>
- <td class="r">${money(r.price, 2)}</td>
- <td class="r">${r.qty}${r.unit ? html` <span style="color:var(--ink-3)">${r.unit}</span>` : ''}</td>
- <td class="r sub">${money(r.subtotal)}</td>
- </tr>`)}
- </tbody>
- </table>
- <div class="cards">
- ${g.rows.map((r) => html`<details>
- <summary>
- <span class="idx">${r.seq}</span>
- <span class="t">${r.name}</span>
- <span class="p">${money(r.subtotal)}</span>
- <span class="chev" aria-hidden="true">›</span>
- </summary>
- <div class="det">
- <dl>
- <dt>规格</dt><dd>${r.spec}${r.notes ? html`<br /><span style="color:var(--ink-3)">${r.notes}</span>` : ''}</dd>
- <dt>供应商</dt><dd>${r.supplier}</dd>
- <dt>单价 × 数量</dt><dd>${money(r.price, 2)} × ${r.qty}${r.unit || ''}</dd>
- </dl>
- </div>
- </details>`)}
- </div>
- </section>`)}
- <div class="total">
- <span>BOM 物料成本合计</span>
- <span class="sum">${money(total)}</span>
- </div>
- ${this.bom?.notes ? html`<p class="bomnote">${this.bom.notes}</p>` : ''}
- `;
- }
- }
- customElements.define('ph-bom', PhBom);
- export { PhBom };
|