更新
This commit is contained in:
1 parent
5718a00e31
commit
1850ac640e
226 files changed
+37772
-12071
No files matched your search
@@ -0,0 +1,458 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<view class="tab-bar">
|
||||
<view
|
||||
v-for="tab in TABS"
|
||||
:key="tab.key"
|
||||
class="tab"
|
||||
:class="{ active: tabKey === tab.key }"
|
||||
@tap="switchTab(tab.key)"
|
||||
>
|
||||
<text class="tab-label">{{ tab.label }}</text>
|
||||
<text v-if="countOf(tab.key)" class="tab-count">{{ countOf(tab.key) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="loading" class="state-box">
|
||||
<text class="state-text">正在盘点预警...</text>
|
||||
</view>
|
||||
<template v-else>
|
||||
<view class="head-line">
|
||||
<text class="head-text">{{ headText }}</text>
|
||||
<text v-if="!isReplenish" class="head-tip">点商品看档案</text>
|
||||
</view>
|
||||
|
||||
<view v-if="!rows.length" class="state-box">
|
||||
<u-empty :text="emptyText" mode="list" />
|
||||
</view>
|
||||
|
||||
<template v-else-if="isReplenish">
|
||||
<view v-for="row in rows" :key="row.product_id" class="w-card">
|
||||
<view class="w-top">
|
||||
<text class="w-name" @tap="openProduct(row)">{{ row.product_name }}</text>
|
||||
<u-tag text="建议补货" type="primary" size="mini" />
|
||||
</view>
|
||||
<text class="w-sub">{{ [row.product_code, row.spec].filter(Boolean).join(' · ') }}</text>
|
||||
<view class="w-grid">
|
||||
<view class="w-cell">
|
||||
<text class="cell-label">现库存</text>
|
||||
<text class="cell-value">{{ qtyText(row.quantity) }} {{ row.unit || '' }}</text>
|
||||
</view>
|
||||
<view class="w-cell">
|
||||
<text class="cell-label">在途</text>
|
||||
<text class="cell-value">{{ qtyText(row.in_transit) }}</text>
|
||||
</view>
|
||||
<view class="w-cell">
|
||||
<text class="cell-label">近30天销量</text>
|
||||
<text class="cell-value">{{ qtyText(row.sold_30) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="w-sug">
|
||||
<view class="sug-left">
|
||||
<text class="sug-label">建议采购</text>
|
||||
<text class="sug-qty">{{ qtyText(row.suggest_qty) }} {{ row.unit || '' }}</text>
|
||||
</view>
|
||||
<view class="sug-right">
|
||||
<text class="sug-amount">约 ¥{{ moneyText(row.amount) }}</text>
|
||||
<view class="go-btn" @tap="toPurchase(row)">
|
||||
<FaIcon name="cart-plus" color="#ffffff" :size="13" />
|
||||
<text>去开采购单</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<view v-for="(row, i) in rows" :key="`${row.product_id}-${row.batch_no || ''}-${i}`" class="w-card">
|
||||
<view class="w-top">
|
||||
<text class="w-name" @tap="openProduct(row)">{{ row.product_name }}</text>
|
||||
<u-tag :text="row.type_label || tabLabel" :type="tagType" size="mini" />
|
||||
</view>
|
||||
<text class="w-sub">
|
||||
{{ [row.category_name, row.warehouse_name, row.batch_no ? '批次 ' + row.batch_no : '']
|
||||
.filter(Boolean).join(' · ') }}
|
||||
</text>
|
||||
<view class="w-grid">
|
||||
<view class="w-cell">
|
||||
<text class="cell-label">库存</text>
|
||||
<text class="cell-value strong">{{ qtyText(row.quantity) }} {{ row.unit || '' }}</text>
|
||||
</view>
|
||||
<view v-if="tabKey !== 'expiring'" class="w-cell">
|
||||
<text class="cell-label">安全库存</text>
|
||||
<text class="cell-value">{{ qtyText(row.safety_qty) }}</text>
|
||||
</view>
|
||||
<view v-if="tabKey === 'over'" class="w-cell">
|
||||
<text class="cell-label">最高库存</text>
|
||||
<text class="cell-value">{{ qtyText(row.max_qty) }}</text>
|
||||
</view>
|
||||
<view v-if="tabKey === 'low'" class="w-cell">
|
||||
<text class="cell-label">在途</text>
|
||||
<text class="cell-value">{{ qtyText(row.in_transit) }}</text>
|
||||
</view>
|
||||
<view v-if="tabKey === 'expiring'" class="w-cell">
|
||||
<text class="cell-label">到期日</text>
|
||||
<text class="cell-value">{{ row.expire_date || '未登记' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="w-foot">
|
||||
<text v-if="tabKey === 'expiring'" class="foot-warn">
|
||||
{{ expireText(row) }}
|
||||
</text>
|
||||
<text v-else-if="Number(row.suggest_qty) > 0" class="foot-sug">
|
||||
建议{{ row.type === 'over' ? '清仓' : '补货' }} {{ qtyText(row.suggest_qty) }} {{ row.unit || '' }}
|
||||
</text>
|
||||
<view v-if="row.type === 'low' || row.type === 'out'" class="go-mini" @tap="toPurchase(row)">
|
||||
<text>去开采购单</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</template>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
/**
|
||||
* 库存预警与智能补货。
|
||||
* 四类预警一次取回(同源同一份结存快照),切 tab 只换视图不重复打接口;
|
||||
* 补货建议口径更重(含近30天销量与在途),单独按需拉。
|
||||
*/
|
||||
import { computed, ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import FaIcon from '@/components/FaIcon.vue'
|
||||
import { fetchReplenish, fetchStockWarning, moneyText, qtyText } from '@/api/erp.js'
|
||||
|
||||
const TABS = [
|
||||
{ key: 'low', label: '低库存' },
|
||||
{ key: 'out', label: '缺货' },
|
||||
{ key: 'over', label: '积压' },
|
||||
{ key: 'expiring', label: '效期' },
|
||||
{ key: 'replenish', label: '补货' }
|
||||
]
|
||||
|
||||
const HEADS = {
|
||||
low: '低于安全库存,按 1.5 倍安全量给出补货建议',
|
||||
out: '库存已清零,销售出库会被拦截',
|
||||
over: '超出最高库存,占资金且易过期',
|
||||
expiring: '30 天内到期的批次,先出先用',
|
||||
replenish: '综合现库存、在途与近 30 天销量的采购建议'
|
||||
}
|
||||
|
||||
const tabKey = ref('low')
|
||||
const warning = ref({ low: [], out: [], over: [], expiring: [], counts: {} })
|
||||
const replenish = ref([])
|
||||
const loading = ref(true)
|
||||
const replenishLoaded = ref(false)
|
||||
|
||||
const tabLabel = computed(() => (TABS.find((t) => t.key === tabKey.value) || {}).label || '预警')
|
||||
const isReplenish = computed(() => tabKey.value === 'replenish')
|
||||
const rows = computed(() => (isReplenish.value ? replenish.value : warning.value[tabKey.value] || []))
|
||||
const headText = computed(() => HEADS[tabKey.value] || '')
|
||||
const emptyText = computed(() => (isReplenish.value ? '库存充足,暂无补货建议' : '这一类没有预警,库存健康'))
|
||||
const tagType = computed(
|
||||
() => ({ low: 'warning', out: 'error', over: 'primary', expiring: 'warning' })[tabKey.value] || 'warning'
|
||||
)
|
||||
|
||||
onLoad((query = {}) => {
|
||||
if (query.tab && TABS.some((t) => t.key === query.tab)) tabKey.value = query.tab
|
||||
loadWarning()
|
||||
})
|
||||
|
||||
async function loadWarning() {
|
||||
loading.value = true
|
||||
try {
|
||||
warning.value = await fetchStockWarning()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
if (tabKey.value === 'replenish') loadReplenish()
|
||||
}
|
||||
|
||||
async function loadReplenish() {
|
||||
if (replenishLoaded.value) return
|
||||
replenishLoaded.value = true
|
||||
try {
|
||||
replenish.value = (await fetchReplenish()).list || []
|
||||
} catch (e) {
|
||||
replenishLoaded.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function switchTab(key) {
|
||||
if (tabKey.value === key) return
|
||||
tabKey.value = key
|
||||
if (key === 'replenish') loadReplenish()
|
||||
}
|
||||
|
||||
function countOf(key) {
|
||||
if (key === 'replenish') return replenish.value.length
|
||||
return (warning.value.counts || {})[key] || 0
|
||||
}
|
||||
|
||||
function expireText(row) {
|
||||
const d = Number(row.expire_in_days)
|
||||
if (!row.expire_date) return '未登记效期'
|
||||
if (d < 0) return `已过期 ${Math.abs(d)} 天,禁止出库`
|
||||
return `还有 ${d} 天到期`
|
||||
}
|
||||
|
||||
function openProduct(row) {
|
||||
if (!row.product_id) return
|
||||
uni.navigateTo({ url: `/pages/erp/basic/product-detail?id=${row.product_id}` })
|
||||
}
|
||||
|
||||
function toPurchase(row) {
|
||||
const qty = Number(row.suggest_qty) > 0 ? row.suggest_qty : ''
|
||||
uni.navigateTo({
|
||||
url: `/pages/erp/document/edit?doc_type=purchase_order&product_id=${row.product_id}&quantity=${qty}`
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import '@/src/styles/page-common.scss';
|
||||
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: $color-bg-page;
|
||||
padding-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.tab-bar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
background: $color-card;
|
||||
box-shadow: $shadow-header;
|
||||
padding: 0 8rpx;
|
||||
}
|
||||
|
||||
.tab {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8rpx;
|
||||
padding: 24rpx 0 20rpx;
|
||||
position: relative;
|
||||
|
||||
.tab-label {
|
||||
font-size: 26rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.tab-count {
|
||||
min-width: 32rpx;
|
||||
height: 32rpx;
|
||||
padding: 0 8rpx;
|
||||
border-radius: $radius-full;
|
||||
background: #f1f5f9;
|
||||
color: $color-text-secondary;
|
||||
font-size: 20rpx;
|
||||
line-height: 32rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&.active {
|
||||
.tab-label {
|
||||
color: $color-primary;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.tab-count {
|
||||
background: $color-primary;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
width: 48rpx;
|
||||
height: 6rpx;
|
||||
margin-left: -24rpx;
|
||||
border-radius: 3rpx;
|
||||
background: $color-primary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.head-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
padding: 22rpx $page-padding-x 6rpx;
|
||||
}
|
||||
|
||||
.head-text {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 23rpx;
|
||||
color: $color-text-muted;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.head-tip {
|
||||
flex-shrink: 0;
|
||||
font-size: 22rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.w-card {
|
||||
@include card;
|
||||
margin: 20rpx $page-padding-x 0;
|
||||
padding: 24rpx 28rpx;
|
||||
}
|
||||
|
||||
.w-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.w-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 29rpx;
|
||||
font-weight: 500;
|
||||
color: $color-text;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.w-sub {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 23rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.w-grid {
|
||||
display: flex;
|
||||
gap: 12rpx;
|
||||
margin-top: 18rpx;
|
||||
padding-top: 16rpx;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
|
||||
.w-cell {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.cell-label {
|
||||
display: block;
|
||||
font-size: 21rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.cell-value {
|
||||
display: block;
|
||||
margin-top: 6rpx;
|
||||
font-size: 25rpx;
|
||||
color: $color-text;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
&.strong {
|
||||
font-weight: 600;
|
||||
color: $color-primary-dark;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.w-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
.foot-sug {
|
||||
font-size: 23rpx;
|
||||
color: $color-primary;
|
||||
}
|
||||
|
||||
.foot-warn {
|
||||
font-size: 23rpx;
|
||||
color: $color-danger;
|
||||
}
|
||||
|
||||
.go-mini {
|
||||
flex-shrink: 0;
|
||||
padding: 8rpx 20rpx;
|
||||
border-radius: $radius-full;
|
||||
background: $color-primary-bg;
|
||||
font-size: 22rpx;
|
||||
color: $color-primary-dark;
|
||||
}
|
||||
|
||||
.w-sug {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
gap: 20rpx;
|
||||
margin-top: 20rpx;
|
||||
padding-top: 18rpx;
|
||||
border-top: 1rpx solid $color-divider;
|
||||
}
|
||||
|
||||
.sug-left {
|
||||
.sug-label {
|
||||
display: block;
|
||||
font-size: 21rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
|
||||
.sug-qty {
|
||||
display: block;
|
||||
margin-top: 6rpx;
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
color: $color-primary;
|
||||
}
|
||||
}
|
||||
|
||||
.sug-right {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 12rpx;
|
||||
|
||||
.sug-amount {
|
||||
font-size: 23rpx;
|
||||
color: $color-text-secondary;
|
||||
}
|
||||
}
|
||||
|
||||
.go-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
height: 56rpx;
|
||||
padding: 0 24rpx;
|
||||
border-radius: $radius-full;
|
||||
background: linear-gradient(135deg, #60a5fa, #2563eb);
|
||||
color: #ffffff;
|
||||
font-size: 23rpx;
|
||||
}
|
||||
|
||||
.state-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 120rpx 40rpx;
|
||||
}
|
||||
|
||||
.state-text {
|
||||
font-size: 28rpx;
|
||||
color: $color-text-muted;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user