WMS_PDA/pages/replenishment/replenishShorts.vue

647 lines
15 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="replenish-shorts-page">
<view class="status-bar"></view>
<view class="page-header">
<view class="header-side header-side--left" @click="handleBack">
<u-icon name="arrow-left" size="18" color="#303133"></u-icon>
</view>
<text class="header-title">分拣缺货补货</text>
<view class="header-side header-side--right" @click="handleRefresh">
<view class="header-btn-refresh">刷新</view>
</view>
</view>
<!-- 汇总统计栏 -->
<view v-if="summary" class="summary-bar">
<view class="summary-bar__item">
<text class="summary-bar__item-label">SKU总数</text>
<text class="summary-bar__item-value">{{ getSummaryVal(summary.total_skus) }}</text>
</view>
<view class="summary-bar__item">
<text class="summary-bar__item-label">缺货SKU</text>
<text class="summary-bar__item-value summary-bar__item-value--warning">{{ getSummaryVal(summary.total_shortage_skus) }}</text>
</view>
<view class="summary-bar__item">
<text class="summary-bar__item-label">建议补货总量</text>
<text class="summary-bar__item-value summary-bar__item-value--primary">{{ formatQty(summary.total_replenishment_needed) }}</text>
</view>
<view class="summary-bar__item">
<text class="summary-bar__item-label">真实缺货SKU</text>
<text class="summary-bar__item-value summary-bar__item-value--danger">{{ getSummaryVal(summary.total_true_shortage_skus) }}</text>
</view>
</view>
<!-- 搜索框 -->
<view class="search-bar">
<view class="search-bar__input-wrap">
<u-icon name="search" size="20" color="#909399"></u-icon>
<input
class="search-bar__input"
type="text"
v-model="searchKeyword"
placeholder="输入商品名称搜索..."
placeholder-style="color: #c0c4cc; font-size: 34rpx;"
confirm-type="search"
/>
<text v-if="searchKeyword" class="search-bar__clear" @click="searchKeyword = ''">
<u-icon name="close-circle-fill" size="20" color="#c0c4cc"></u-icon>
</text>
</view>
</view>
<view class="page-body">
<!-- 加载状态 -->
<view v-if="loading" class="loading-state">
<u-loading-icon mode="circle" size="36"></u-loading-icon>
<text class="loading-state__text">加载中...</text>
</view>
<!-- 空数据 -->
<view v-else-if="filteredList.length === 0" class="empty-card">
<u-icon name="info-circle" size="72" color="#c0c4cc"></u-icon>
<text class="empty-card__title">{{ list.length === 0 ? '暂无缺货数据' : '未找到匹配的商品' }}</text>
<text class="empty-card__desc">{{ list.length === 0 ? '当前仓库所有SKU分拣区库存充足,无需补货。' : '请尝试其他搜索关键词' }}</text>
</view>
<!-- 数据列表:卡片模式 -->
<scroll-view v-else class="card-scroll" scroll-y>
<view class="card-list">
<view
v-for="(item, index) in filteredList"
:key="item.stock_id || index"
class="card-item"
@click="goProductQuery(item)"
>
<!-- 卡片内容:标签名在左,数值在右,斑马纹 -->
<view class="card-item__body">
<view class="card-metric card-metric--0">
<text class="card-metric__label">SKU编码</text>
<view class="card-metric__divider"></view>
<text class="card-metric__value card-metric__value--code">{{ item.stock_code || item.stock_id || '-' }}</text>
</view>
<view class="card-metric card-metric--1">
<text class="card-metric__label">缺货数</text>
<view class="card-metric__divider"></view>
<text class="card-metric__value card-metric__value--danger">{{ formatQty(item.shortage) }}</text>
</view>
<view class="card-metric card-metric--0">
<text class="card-metric__label">补货状态</text>
<view class="card-metric__divider"></view>
<text class="card-metric__value" :class="replenishStatusClass(item)">{{ replenishStatusText(item.replenishment_status) }}</text>
</view>
<view class="card-metric card-metric--1">
<text class="card-metric__label">商品名称</text>
<view class="card-metric__divider"></view>
<text class="card-metric__value card-metric__value--name">{{ item.stock_name || '-' }}</text>
</view>
<view class="card-metric card-metric--0">
<text class="card-metric__label">出货数量</text>
<view class="card-metric__divider"></view>
<text class="card-metric__value">{{ formatQty(item.total_demand) }}</text>
</view>
<view class="card-metric card-metric--1">
<text class="card-metric__label">分拣区数量</text>
<view class="card-metric__divider"></view>
<text class="card-metric__value">{{ formatQty(item.pick_zone_quantity) }}</text>
</view>
<view class="card-metric card-metric--0">
<text class="card-metric__label">存储区数量</text>
<view class="card-metric__divider"></view>
<text class="card-metric__value">{{ formatQty(item.storage_zone_quantity) }}</text>
</view>
<view class="card-metric card-metric--1">
<text class="card-metric__label">推荐补货量</text>
<view class="card-metric__divider"></view>
<text class="card-metric__value card-metric__value--primary">{{ formatQty(item.replenishment_needed) }}</text>
</view>
<view class="card-metric card-metric--0">
<text class="card-metric__label">补货库位</text>
<view class="card-metric__divider"></view>
<text class="card-metric__value card-metric__value--spaces">{{ formatLocations(item.replenishment_locations) }}</text>
</view>
</view>
</view>
</view>
<!-- 底部安全区 -->
<view class="safe-area-bottom"></view>
</scroll-view>
<!-- 底部统计栏 -->
<view v-if="summary" class="bottom-bar">
<view class="bottom-bar__pagination">
<view
class="pagination-btn"
:class="{ 'pagination-btn--disabled': page <= 1 }"
@click="goPrevPage"
>
上一页
</view>
<text class="bottom-bar__text">
第 {{ page }}/{{ totalPages }} 页,共 {{ getSummaryVal(summary.total_skus) }} 条
</text>
<view
class="pagination-btn"
:class="{ 'pagination-btn--disabled': page >= totalPages }"
@click="goNextPage"
>
下一页
</view>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
loading: false,
list: [],
summary: null,
total: 0,
page: 1,
pageSize: 20,
searchKeyword: '',
sort: {
sortField: 'shortage',
sortOrder: 'DESC'
}
};
},
computed: {
totalPages() {
return Math.max(1, Math.ceil(this.total / this.pageSize));
},
filteredList() {
const keyword = this.searchKeyword.trim();
if (!keyword) {
return this.list;
}
return this.list.filter(item => {
const name = String(item.stock_name || '').toLowerCase();
return name.includes(keyword.toLowerCase());
});
}
},
onLoad() {
this.fetchData();
},
methods: {
goProductQuery(item) {
const keyword = item.stock_name || item.stock_code || item.stock_id || '';
const stockId = item.stock_id || '';
uni.setStorageSync('replenish_query_keyword', keyword);
uni.navigateTo({
url: `/pages/work/product/query?stock_id=${encodeURIComponent(stockId)}`
});
},
handleBack() {
uni.navigateBack({ delta: 1 });
},
handleRefresh() {
this.page = 1;
this.list = [];
this.fetchData();
uni.showToast({ title: '已刷新', icon: 'none' });
},
goNextPage() {
if (this.page >= this.totalPages || this.loading) return;
this.page += 1;
this.fetchData();
},
goPrevPage() {
if (this.page <= 1 || this.loading) return;
this.page -= 1;
this.fetchData();
},
getSummaryVal(val) {
return val ?? 0;
},
formatLocations(locations) {
if (!Array.isArray(locations) || locations.length === 0) return '-';
return locations.map(loc => {
const spaceLabel = loc.space_name || loc.name || loc.custom_name || loc.space_code || '-';
return `${spaceLabel}(${loc.available_quantity})`;
}).join('、');
},
replenishStatusText(status) {
const map = {
true_shortage: '真实缺货',
replenishable: '可补货'
};
return map[status] || status || '-';
},
replenishStatusClass(item) {
const status = item.replenishment_status;
if (status === 'replenishable') {
return 'card-metric__value--primary';
}
if (status === 'true_shortage') {
return 'card-metric__value--danger';
}
return '';
},
formatQty(val) {
const num = Number(val);
return isNaN(num) ? '-' : num.toLocaleString();
},
async fetchData() {
this.loading = true;
try {
const params = {
pagination: {
page: this.page,
pageSize: this.pageSize
},
sort: {
sortField: this.sort.sortField,
sortOrder: this.sort.sortOrder
}
};
const res = await this.$http('storage.management.replenishmentDemand', params);
this.list = Array.isArray(res.list) ? res.list : [];
this.total = Number(res.pagination?.total ?? this.list.length);
this.summary = res.summary ?? null;
} catch (error) {
console.error('[replenishShorts] 请求失败:', error);
uni.showToast({
title: error?.message || error?.msg || '请求失败',
icon: 'none'
});
this.list = [];
this.total = 0;
} finally {
this.loading = false;
}
}
}
};
</script>
<style lang="scss" scoped>
.replenish-shorts-page {
height: 100vh;
display: flex;
flex-direction: column;
background: #f5f7fa;
overflow: hidden;
}
.status-bar {
height: var(--status-bar-height);
background: #ffffff;
}
.page-header {
height: 88rpx;
padding: 0 24rpx;
display: flex;
align-items: center;
justify-content: space-between;
background: #ffffff;
border-bottom: 1rpx solid #ebeef5;
box-sizing: border-box;
flex-shrink: 0;
}
.header-side {
min-width: 112rpx;
display: flex;
align-items: center;
}
.header-side--left {
justify-content: flex-start;
}
.header-side--right {
justify-content: flex-end;
}
.header-title {
flex: 1;
padding: 0 16rpx;
font-size: 32rpx;
font-weight: bold;
color: #333;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.header-action-text {
margin-left: 8rpx;
font-size: 28rpx;
color: #303133;
line-height: 1;
}
.header-btn-refresh {
padding: 14rpx 28rpx;
background: #2979ff;
color: #ffffff;
font-size: 30rpx;
border-radius: 8rpx;
line-height: 1;
}
/* ===== 汇总统计栏 ===== */
.summary-bar {
display: flex;
align-items: stretch;
padding: 16rpx 16rpx;
background: #ffffff;
border-bottom: 1rpx solid #ebeef5;
gap: 8rpx;
flex-shrink: 0;
}
.summary-bar__item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 6rpx;
padding: 12rpx 8rpx;
background: #f5f7fa;
border-radius: 12rpx;
}
.summary-bar__item-value {
font-size: 36rpx;
font-weight: 700;
color: #303133;
line-height: 1.2;
font-variant-numeric: tabular-nums;
}
.summary-bar__item-value--danger {
color: #f56c6c;
}
.summary-bar__item-value--primary {
color: #2979ff;
}
.summary-bar__item-value--warning {
color: #e6a23c;
}
.summary-bar__item-label {
font-size: 22rpx;
color: #909399;
line-height: 1;
}
/* ===== 搜索框 ===== */
.search-bar {
padding: 12rpx 16rpx;
background: #ffffff;
border-bottom: 1rpx solid #ebeef5;
flex-shrink: 0;
}
.search-bar__input-wrap {
display: flex;
align-items: center;
gap: 16rpx;
padding: 20rpx 24rpx;
background: #f5f7fa;
border-radius: 12rpx;
}
.search-bar__input {
flex: 1;
font-size: 34rpx;
color: #303133;
height: 48rpx;
line-height: 48rpx;
padding: 0;
background: transparent;
border: none;
outline: none;
}
.search-bar__clear {
display: flex;
align-items: center;
justify-content: center;
padding: 6rpx;
}
/* ===== 页面主体 ===== */
.page-body {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 0;
}
.loading-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 120rpx 0;
gap: 24rpx;
}
.loading-state__text {
font-size: 28rpx;
color: #909399;
}
.empty-card {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 120rpx 48rpx;
gap: 24rpx;
}
.empty-card__title {
font-size: 32rpx;
font-weight: 500;
color: #303133;
}
.empty-card__desc {
font-size: 26rpx;
color: #909399;
text-align: center;
line-height: 1.6;
}
/* ===== 卡片列表 ===== */
.card-scroll {
flex: 1;
overflow: hidden;
}
.card-list {
padding: 16rpx;
display: flex;
flex-direction: column;
gap: 16rpx;
}
.card-item {
background: #ffffff;
border-radius: 16rpx;
padding: 24rpx 20rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
}
.card-item__body {
display: flex;
flex-direction: column;
}
.card-metric {
display: flex;
align-items: center;
padding: 18rpx 16rpx;
}
.card-metric--1 {
background: #f0f2f5;
border-radius: 6rpx;
}
.card-metric__label {
font-size: 30rpx;
color: #303133;
line-height: 1;
flex-shrink: 0;
width: 150rpx;
}
.card-metric__divider {
width: 2rpx;
height: 28rpx;
background: #e4e7ed;
flex-shrink: 0;
margin: 0 16rpx;
}
.card-metric__value {
font-size: 32rpx;
font-weight: 600;
color: #303133;
line-height: 1.4;
font-variant-numeric: tabular-nums;
text-align: left;
flex: 1;
min-width: 0;
word-break: break-all;
}
.card-metric__value--code {
font-weight: 700;
font-size: 34rpx;
}
.card-metric__value--name {
font-weight: 400;
font-size: 30rpx;
color: #303133;
}
.card-metric__value--danger {
background-color: #f56c6c;
color: #ffffff;
padding: 18rpx 12rpx;
margin: -18rpx 0;
border-radius: 0 6rpx 6rpx 0;
}
.card-metric__value--primary {
color: #2979ff;
}
.card-metric__value--warning {
color: #e6a23c;
}
.card-metric__value--spaces {
font-weight: 400;
color: #303133;
max-width: 60%;
white-space: normal;
word-break: break-all;
line-height: 1.4;
font-size: 28rpx;
}
/* ===== 加载更多 ===== */
.loadmore-state {
display: flex;
align-items: center;
justify-content: center;
padding: 24rpx 0;
gap: 12rpx;
}
.loadmore-state__text {
font-size: 24rpx;
color: #909399;
}
.no-more-tip {
padding: 24rpx 0;
text-align: center;
}
.no-more-tip__text {
font-size: 24rpx;
color: #c0c4cc;
}
.safe-area-bottom {
height: 20rpx;
}
/* ===== 底部统计栏 ===== */
.bottom-bar {
flex-shrink: 0;
padding: 24rpx 24rpx;
background: #ffffff;
border-top: 1rpx solid #ebeef5;
}
.bottom-bar__pagination {
display: flex;
align-items: center;
justify-content: center;
gap: 24rpx;
}
.bottom-bar__text {
font-size: 26rpx;
color: #909399;
}
.pagination-btn {
padding: 18rpx 36rpx;
font-size: 30rpx;
color: #2979ff;
background: #f0f5ff;
border-radius: 8rpx;
line-height: 1;
transition: opacity 0.2s;
}
.pagination-btn--disabled {
color: #c0c4cc;
background: #f5f7fa;
}
</style>