Runs.vue
6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!-- 补货单列表:定时补货(定时推送 / 手动补充)和单次补货(群里一句话);立即执行补货;导出留痕表(按钮已隐藏,见 SHOW_TRACE_EXPORT)。 -->
<script setup lang="ts">
import { Download, Refresh, VideoPlay } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { api } from '@/api'
import EmptyState from '@/components/EmptyState.vue'
import PageHeader from '@/components/PageHeader.vue'
import Pager from '@/components/Pager.vue'
import Panel from '@/components/Panel.vue'
import StatusPill from '@/components/StatusPill.vue'
import { usePaged } from '@/composables/usePaged'
import { fmtMoney, fmtShort, STAGE, TRIGGER } from '@/format'
const router = useRouter()
const { rows, total, page, size, loading, filters, load } = usePaged('/api/restock/runs', { filters: { kind: '', status: '' }, query: true })
const starting = ref(false)
const range = ref<[string, string] | null>(null)
const SHOW_TRACE_EXPORT = false // 「导出留痕表」按钮(连同日期范围)暂时隐藏,代码和后端接口保留;要用时改成 true
onMounted(load)
async function runNow() {
try {
await ElMessageBox.confirm('马上按今天的出库窗口算一张补货清单,推到群里确认。不影响每天的定时推送。', '立即执行补货',
{ confirmButtonText: '执行', type: 'warning' })
} catch { return }
starting.value = true
try {
const r = await api.post('/api/restock/runs/start')
ElMessage[r.result === 'started' ? 'success' : 'warning'](r.message)
load()
} catch (e: any) { ElMessage.error(e.message) } finally { starting.value = false }
}
async function exportTrace() {
const q = range.value ? `?since=${range.value[0]}&until=${range.value[1]}` : ''
try { await api.download('/api/restock/trace.csv' + q, '补货留痕表.csv') } catch (e: any) { ElMessage.error(e.message) }
}
</script>
<template>
<div class="page">
<PageHeader title="补货单" desc="定时补货:每天定时推送,出库明细 → 补货推荐 → 页面确认 → DMS 建单截图 → 页面「确认提交」→ 提交回执。
「立即执行补货」是手动补充,不影响当天的定时推送。
单次补货:计划员在群里发「零件号 数量」→ 回「订」建单截图 → 本人回「确认」提交。">
<template #actions>
<el-button :icon="Refresh" @click="load()">刷新</el-button>
<el-button type="primary" :icon="VideoPlay" :loading="starting" @click="runNow">立即执行补货</el-button>
</template>
</PageHeader>
<Panel flush title="补货单列表">
<template #extra>
<template v-if="SHOW_TRACE_EXPORT">
<el-date-picker v-model="range" type="daterange" value-format="YYYY-MM-DD" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" class="w-range" />
<el-button :icon="Download" @click="exportTrace">导出留痕表</el-button>
</template>
</template>
<template #toolbar>
<el-radio-group v-model="filters.kind" size="small">
<el-radio-button value="">全部类型</el-radio-button>
<el-radio-button value="scheduled">定时补货</el-radio-button>
<el-radio-button value="single">单次补货</el-radio-button>
<el-radio-button value="multi">批量补货</el-radio-button>
</el-radio-group>
<el-radio-group v-model="filters.status" size="small">
<el-radio-button value="">全部状态</el-radio-button>
<el-radio-button value="awaiting_confirm">待确认</el-radio-button>
<el-radio-button value="awaiting_submit">待确认提交</el-radio-button>
<el-radio-button value="done">已完成</el-radio-button>
<el-radio-button value="cancelled">不订</el-radio-button>
<el-radio-button value="error">出错</el-radio-button>
<el-radio-button value="expired">已过期</el-radio-button>
<el-radio-button value="terminated">已终止</el-radio-button>
</el-radio-group>
</template>
<el-table v-loading="loading" :data="rows" class="clickable nowrap" @row-click="(r: any) => router.push('/runs/' + r.id)">
<el-table-column label="业务日期" width="108"><template #default="{ row }"><span class="num">{{ row.biz_date }}</span></template></el-table-column>
<el-table-column label="补货单号" min-width="168"><template #default="{ row }"><b class="mono">{{ row.doc_no }}</b></template></el-table-column>
<el-table-column label="类型" width="150">
<template #default="{ row }">{{ row.kind_cn }}<span class="muted"> · {{ TRIGGER[row.trigger] || row.trigger }}</span></template>
</el-table-column>
<el-table-column label="状态" width="150"><template #default="{ row }"><StatusPill :tone="STAGE[row.status]?.tone">{{ STAGE[row.status]?.text || row.stage_cn }}</StatusPill></template></el-table-column>
<el-table-column label="可订" width="130" align="right"><template #default="{ row }"><span class="num">{{ row.summary.order_count }} 项 / {{ row.summary.order_qty }} 件</span></template></el-table-column>
<el-table-column label="改过" width="80" align="center">
<template #default="{ row }">
<el-tag v-if="row.summary.changed_count" size="small" type="warning">改 {{ row.summary.changed_count }} 处</el-tag>
<span v-else class="muted">—</span>
</template>
</el-table-column>
<el-table-column label="金额" width="110" align="right"><template #default="{ row }"><span class="num">{{ fmtMoney(row.summary.amount) }}</span></template></el-table-column>
<el-table-column label="发起人" width="110" show-overflow-tooltip><template #default="{ row }">{{ row.triggered_by || '—' }}</template></el-table-column>
<el-table-column label="确认人" width="110" show-overflow-tooltip><template #default="{ row }">{{ row.confirmed_by || '—' }}</template></el-table-column>
<el-table-column label="采购单号" min-width="140"><template #default="{ row }"><span class="mono">{{ row.order_no || '—' }}</span></template></el-table-column>
<el-table-column label="发起时间" width="116"><template #default="{ row }"><span class="num">{{ fmtShort(row.created_at) }}</span></template></el-table-column>
<template #empty><EmptyState title="还没有补货单" /></template>
</el-table>
<Pager v-model:page="page" v-model:size="size" :total="total" />
</Panel>
</div>
</template>
<style scoped>
.w-range { width: 260px; }
.clickable { cursor: pointer; }
.nowrap :deep(.cell) { white-space: nowrap; }
</style>