Commit 98413923 by 黄南光

优化前端

1 parent 7a9119aa
# 2026-11-13
## 定时补货单据页:按零件分类二级分组
- 需求:定时补货链接(手机单据页 OrderPage.vue)的零件按属性分类展示
- 历史常备件大组下按常备分类(保养/机油/轮胎/养护品,跟 stock_categories 配置走)分子组 + 末尾"近N个月SO单"子组(SO命中但非常备分类的)
- 当天出库的其他零件大组下也按分类分子组(钣喷件/未分类/其他)
- 大组全选 + 每个子组也带全选
- 改动文件:
- web/src/mobile/OrderPage.vue:新增 stockGroups/otherGroups computed(按 category 二级聚合),模板从平铺改为 v-for 子组循环;行内渲染逻辑完全复用
- web/src/mobile/mobile.css:新增 .m-subsection 子组标题样式
- 后端不动(数据已齐全:Line 带 category/so_hit/grp,page_state 传 stock_categories/so_months)
- vue-tsc 类型检查通过(exit 0,零错误)
- 决策来源:老大拍板 ①大组+子组全选 ②空分类归未分类 ③so_months 跟配置走(补货规则页可配)
...@@ -84,9 +84,38 @@ const lines = computed<any[]>(() => st.value?.lines || []) ...@@ -84,9 +84,38 @@ const lines = computed<any[]>(() => st.value?.lines || [])
const hiddenZero = (l: any) => !!st.value?.hide_zero && !l.error && Number(l.preview_qty ?? l.final_qty) === 0 const hiddenZero = (l: any) => !!st.value?.hide_zero && !l.error && Number(l.preview_qty ?? l.final_qty) === 0
const visibleLines = computed(() => lines.value.filter((l) => !hiddenZero(l))) const visibleLines = computed(() => lines.value.filter((l) => !hiddenZero(l)))
const hiddenCount = computed(() => lines.value.length - visibleLines.value.length) const hiddenCount = computed(() => lines.value.length - visibleLines.value.length)
const stockLines = computed(() => visibleLines.value.filter((l) => l.grp !== 'other')) const stockCats = computed<string[]>(() => st.value?.stock_categories || [])
const otherLines = computed(() => visibleLines.value.filter((l) => l.grp === 'other')) const normCat = (c: any) => { const v = String(c || '').trim(); return (!v || v === '未分类') ? '未分类' : v }
const otherCount = computed(() => otherLines.value.length) const stockAllLines = computed(() => visibleLines.value.filter((l) => l.grp !== 'other'))
const otherAllLines = computed(() => visibleLines.value.filter((l) => l.grp === 'other'))
const otherCount = computed(() => otherAllLines.value.length)
/** 历史常备件按分类二级分组:常备分类子组(按配置顺序)+ 末尾「近N个月SO单」子组(SO命中但分类不在常备分类里的) */
const stockGroups = computed<{ label: string; lines: any[] }[]>(() => {
const cats = stockCats.value
const groups = cats.map((c) => ({ label: c, lines: stockAllLines.value.filter((l) => (l.category || '') === c) }))
.filter((g) => g.lines.length > 0)
const soLines = stockAllLines.value.filter((l) => !cats.includes(l.category || ''))
if (soLines.length > 0) groups.push({ label: `近${st.value?.so_months || 3}个月SO单`, lines: soLines })
return groups
})
/** 其他出库件按分类二级分组:钣喷件 → 未分类 → 其余按出现顺序 */
const otherGroups = computed<{ label: string; lines: any[] }[]>(() => {
const other = otherAllLines.value
const fixed = ['钣喷件', '未分类']
const groups: { label: string; lines: any[] }[] = []
const seen = new Set<string>()
for (const c of fixed) {
const lines = other.filter((l) => normCat(l.category) === c)
if (lines.length > 0) { groups.push({ label: c, lines }); seen.add(c) }
}
for (const l of other) {
const c = normCat(l.category)
if (fixed.includes(c) || seen.has(c)) continue
seen.add(c)
groups.push({ label: c, lines: other.filter((x) => normCat(x.category) === c) })
}
return groups
})
/** DMS 里还没提交的采购单(含他人创建、本系统建单结果未知的):只提示,不参与计算 */ /** DMS 里还没提交的采购单(含他人创建、本系统建单结果未知的):只提示,不参与计算 */
const drafts = computed<{ items: any[], error?: string, truncated?: boolean }>(() => { const drafts = computed<{ items: any[], error?: string, truncated?: boolean }>(() => {
const d = st.value?.drafts const d = st.value?.drafts
...@@ -326,15 +355,22 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli ...@@ -326,15 +355,22 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli
</div> </div>
</template> </template>
<!-- 定时补货:历史常备件 --> <!-- 定时补货:历史常备件(按零件分类二级分组) -->
<template v-else-if="!['creating', 'screenshotting', 'awaiting_submit', 'submitting', 'done'].includes(status) || !st.run.order_no"> <template v-else-if="!['creating', 'screenshotting', 'awaiting_submit', 'submitting', 'done'].includes(status) || !st.run.order_no">
<div class="m-section">建议补货 <span>历史常备件 {{ stockLines.length }} 项 · 期望默认取「库存 + 出库」(推荐),填过的带上次的值(上次)</span></div> <div class="m-section">建议补货 <span>历史常备件 {{ stockAllLines.length }} 项 · 期望默认取「库存 + 出库」(推荐),填过的带上次的值(上次)</span></div>
<div v-if="editing && stockLines.length" class="m-allbar"> <div v-if="editing && stockAllLines.length" class="m-allbar">
<van-checkbox :model-value="allChecked(stockLines)" :indeterminate="someChecked(stockLines)" icon-size="18px" <van-checkbox :model-value="allChecked(stockAllLines)" :indeterminate="someChecked(stockAllLines)" icon-size="18px"
@update:model-value="(v: boolean) => toggleAll(stockLines, v, 'stock')"> @update:model-value="(v: boolean) => toggleAll(stockAllLines, v, 'stock')">
全选 <span>已选 {{ checkedCount(stockLines) }} / {{ stockLines.length }}</span></van-checkbox> 全选 <span>已选 {{ checkedCount(stockAllLines) }} / {{ stockAllLines.length }}</span></van-checkbox>
</div> </div>
<div v-for="l in stockLines" :key="l.part_no" class="m-card m-line" :class="{ off: !edits[l.part_no]?.checked }"> <template v-for="(g, gi) in stockGroups" :key="g.label + gi">
<div class="m-subsection">
<van-checkbox v-if="editing" :model-value="allChecked(g.lines)" :indeterminate="someChecked(g.lines)" icon-size="16px"
@update:model-value="(v: boolean) => toggleAll(g.lines, v, 'stock')">{{ g.label }}</van-checkbox>
<template v-else>{{ g.label }}</template>
<span>{{ g.lines.length }} 项</span>
</div>
<div v-for="l in g.lines" :key="l.part_no" class="m-card m-line" :class="{ off: !edits[l.part_no]?.checked }">
<div class="m-line-head"> <div class="m-line-head">
<van-checkbox v-if="editing" :model-value="edits[l.part_no]?.checked" icon-size="18px" @update:model-value="(v: boolean) => toggle(l, v)"> <van-checkbox v-if="editing" :model-value="edits[l.part_no]?.checked" icon-size="18px" @update:model-value="(v: boolean) => toggle(l, v)">
<span class="m-line-name">{{ l.name || l.part_no }}</span></van-checkbox> <span class="m-line-name">{{ l.name || l.part_no }}</span></van-checkbox>
...@@ -359,19 +395,27 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli ...@@ -359,19 +395,27 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli
</div> </div>
<div v-if="calc(l).note || l.error" class="m-note">{{ calc(l).note }} {{ l.error }}</div> <div v-if="calc(l).note || l.error" class="m-note">{{ calc(l).note }} {{ l.error }}</div>
</div> </div>
</template>
<!-- 其他出库件(折叠、默认不勾) --> <!-- 其他出库件(折叠、默认不勾;展开后按分类二级分组) -->
<div v-if="otherCount" class="m-section m-fold" @click="expand"> <div v-if="otherCount" class="m-section m-fold" @click="expand">
当天出库的其他零件 <span>{{ otherCount }} 项 · 默认不勾选 · 补货数已按期望算好,勾选即加入</span> 当天出库的其他零件 <span>{{ otherCount }} 项 · 默认不勾选 · 补货数已按期望算好,勾选即加入</span>
<i>{{ showOthers ? '▴' : '▾' }}</i> <i>{{ showOthers ? '▴' : '▾' }}</i>
</div> </div>
<template v-if="showOthers"> <template v-if="showOthers">
<div v-if="editing && otherLines.length" class="m-allbar"> <div v-if="editing && otherAllLines.length" class="m-allbar">
<van-checkbox :model-value="allChecked(otherLines)" :indeterminate="someChecked(otherLines)" icon-size="18px" <van-checkbox :model-value="allChecked(otherAllLines)" :indeterminate="someChecked(otherAllLines)" icon-size="18px"
@update:model-value="(v: boolean) => toggleAll(otherLines, v, 'other')"> @update:model-value="(v: boolean) => toggleAll(otherAllLines, v, 'other')">
全选 <span>已选 {{ checkedCount(otherLines) }} / {{ otherLines.length }}</span></van-checkbox> 全选 <span>已选 {{ checkedCount(otherAllLines) }} / {{ otherAllLines.length }}</span></van-checkbox>
</div> </div>
<div v-for="l in otherLines" :key="l.part_no" class="m-card m-line" :class="{ off: !edits[l.part_no]?.checked }"> <template v-for="(g, gi) in otherGroups" :key="g.label + gi">
<div class="m-subsection">
<van-checkbox v-if="editing" :model-value="allChecked(g.lines)" :indeterminate="someChecked(g.lines)" icon-size="16px"
@update:model-value="(v: boolean) => toggleAll(g.lines, v, 'other')">{{ g.label }}</van-checkbox>
<template v-else>{{ g.label }}</template>
<span>{{ g.lines.length }} 项</span>
</div>
<div v-for="l in g.lines" :key="l.part_no" class="m-card m-line" :class="{ off: !edits[l.part_no]?.checked }">
<div class="m-line-head"> <div class="m-line-head">
<van-checkbox v-if="editing" :model-value="edits[l.part_no]?.checked" icon-size="18px" @update:model-value="(v: boolean) => toggle(l, v)"> <van-checkbox v-if="editing" :model-value="edits[l.part_no]?.checked" icon-size="18px" @update:model-value="(v: boolean) => toggle(l, v)">
<span class="m-line-name">{{ l.name || l.part_no }}</span></van-checkbox> <span class="m-line-name">{{ l.name || l.part_no }}</span></van-checkbox>
...@@ -397,6 +441,7 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli ...@@ -397,6 +441,7 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli
</div> </div>
</template> </template>
</template> </template>
</template>
<!-- 底部唯一的按钮:所有状态都在它身上 --> <!-- 底部唯一的按钮:所有状态都在它身上 -->
<div v-if="isScheduled && status !== 'done' && !['cancelled', 'expired', 'superseded', 'error', 'terminated'].includes(status)" class="m-bar"> <div v-if="isScheduled && status !== 'done' && !['cancelled', 'expired', 'superseded', 'error', 'terminated'].includes(status)" class="m-bar">
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
.m-sum span { font-size: 11.5px; opacity: 0.8; } .m-sum span { font-size: 11.5px; opacity: 0.8; }
.m-section { padding: 18px 16px 8px; font-weight: 600; font-size: 14px; color: var(--c-text); } .m-section { padding: 18px 16px 8px; font-weight: 600; font-size: 14px; color: var(--c-text); }
.m-section span { font-weight: 400; font-size: 12px; color: var(--c-text-3); margin-left: 6px; } .m-section span { font-weight: 400; font-size: 12px; color: var(--c-text-3); margin-left: 6px; }
.m-subsection { display: flex; align-items: center; gap: 6px; padding: 10px 16px 4px; font-weight: 600; font-size: 13px; color: var(--c-text-2); }
.m-subsection span { font-weight: 400; font-size: 11.5px; color: var(--c-text-3); margin-left: 4px; }
.m-allbar { margin: 0 12px 10px; padding: 0 14px; font-size: 13.5px; } .m-allbar { margin: 0 12px 10px; padding: 0 14px; font-size: 13.5px; }
.m-allbar span { margin-left: 6px; font-size: 12px; color: var(--c-text-3); } .m-allbar span { margin-left: 6px; font-size: 12px; color: var(--c-text-3); }
.m-card { margin: 0 12px 10px; background: var(--c-surface); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); border: 1px solid var(--c-border); } .m-card { margin: 0 12px 10px; background: var(--c-surface); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); border: 1px solid var(--c-border); }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!