feat(B2BOperation): 新增B2B备货与提货作业页面及接口

- 新增备货作业列表页 stockPreparation.vue
  - 支持待处理B2B订单搜索、备货状态筛选(未备货/备货中/已完成)
  - 卡片点击按状态处理:未备货自动开始备货、备货中校验工号、已完成进入详情
  - 备货中卡片支持取消备货
- 新增备货明细页 stockPreparationDetail.vue
  - 展示商品明细与分箱快照,支持编辑/保存分箱及自动保存
  - 支持提交完成备货、取消备货
  - 集成备货凭证照片上传(uploadImgCos + updateB2bOrderImages)
- 新增提货作业页 pickupOperation.vue
  - 待提货/已提货两个状态切换,按运单号/发货单号搜索
  - 已提货卡片展示备货人、备货/提货照片缩略图
  - 待提货卡片弹窗确认提货,输入/扫码提货车牌号
- 注册页面路由:stockPreparation、stockPreparationDetail、pickupOperation
- core/request/apis.js 新增B2B接口:
  - order.pendingOrder2b.list(B2B待处理订单列表)
  - order.deliveryOrder2b.list(B2B配送订单列表,dispatch/m4)
  - order.startB2bPrep / cancelB2bPrep / finishB2bPrep(备货开始/取消/完成)
  - order.getB2bPackingSnapshot / updateB2bPackingItems(分箱快照/更新)
  - order.updateB2bOrderImages(订单图片同步)
  - order.pickupB2b(提货确认)
This commit is contained in:
zm2000 2026-11-19 20:18:13 +08:00
parent 7c90d2f498
commit 9b2d14dd12
5 changed files with 2571 additions and 0 deletions

View File

@ -700,6 +700,56 @@ export default {
isSystemApi: true
}
},
pendingOrder2b: {
list: {
path: "order.pendingOrder2b.list",
auth: true,
method: "POST",
isSystemApi: true
}
},
startB2bPrep: {
path: "order.startB2bPrep",
auth: true,
method: "POST",
isSystemApi: true
},
getB2bPackingSnapshot: {
path: "order.getB2bPackingSnapshot",
auth: true,
method: "POST",
isSystemApi: true
},
updateB2bPackingItems: {
path: "order.updateB2bPackingItems",
auth: true,
method: "POST",
isSystemApi: true
},
cancelB2bPrep: {
path: "order.cancelB2bPrep",
auth: true,
method: "POST",
isSystemApi: true
},
updateB2bOrderImages: {
path: "order.updateB2bOrderImages",
auth: true,
method: "POST",
isSystemApi: true
},
finishB2bPrep: {
path: "order.finishB2bPrep",
auth: true,
method: "POST",
isSystemApi: true
},
pickupB2b: {
path: "order.pickupB2b",
auth: true,
method: "POST",
isSystemApi: true
},
recheckOrder: {
recheckOrderList: {
path: "order.recheckOrder.recheckOrderList",
@ -764,6 +814,15 @@ export default {
isSystemApi: true
}
},
// B2B 配送订单列表:dispatch 分表 + 默认 dispatch_lane=m4,强制 is_b2b='Y'
deliveryOrder2b: {
list: {
path: "order.deliveryOrder2b.list",
auth: true,
method: "POST",
isSystemApi: true
}
},
detail: {
path: "order.detail",
auth: true,

View File

@ -380,6 +380,27 @@
{
"titleNView": false
}
},
{
"path" : "pages/B2BOperation/stockPreparation",
"style" :
{
"titleNView": false
}
},
{
"path" : "pages/B2BOperation/pickupOperation",
"style" :
{
"titleNView": false
}
},
{
"path" : "pages/B2BOperation/stockPreparationDetail",
"style" :
{
"titleNView": false
}
}
],

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,587 @@
<template>
<view class="normar_container stock-prep-page">
<page-nav title="备货作业"></page-nav>
<!-- 搜索栏 -->
<view class="search-panel">
<SearchBar
v-model="keyword"
placeholder="扫码/输入发货单号"
:input-font-size="'34rpx'"
:search-text-font-size="'34rpx'"
@search="handleSearch"
@clear="handleClear"
@scan="handleCameraScan"
></SearchBar>
</view>
<!-- 备货状态筛选 -->
<view class="status-tags">
<view
v-for="tab in prepTabs"
:key="tab.value"
class="status-tag"
:class="statusTagClass(tab)"
@click="handlePrepStatusChange(tab.value)"
>
<text class="tag-name">{{ tab.label }}</text>
</view>
</view>
<!-- 列表 -->
<scroll-view class="list-content" scroll-y @scrolltolower="handleLoadMore">
<view v-if="loading && list.length === 0" class="loading-state">
<u-loading-icon mode="circle" size="40" color="#2979ff"></u-loading-icon>
<text class="loading-text">加载中...</text>
</view>
<view v-else-if="!loading && list.length === 0" class="empty-state">
<u-icon name="order" size="88" color="#c0c4cc"></u-icon>
<text class="empty-text">暂无B2B待处理订单</text>
</view>
<view v-else class="order-list">
<view
v-for="(item, index) in list"
:key="getItemKey(item, index)"
class="order-card"
@click="handleViewDetail(item)"
>
<view class="card-header">
<text class="order-code">{{ getDeliveryOrderCode(item) }}</text>
<text v-if="isUrgent(item)" class="badge badge--urgent">加急</text>
<text v-if="hasSn(item)" class="badge badge--sn">含SN</text>
<view class="prep-tag">
<u-tag :text="getPrepStatusText(item)" :bgColor="getPrepStatusBgColor(item)" :borderColor="getPrepStatusBgColor(item)" color="#ffffff" size="mini"></u-tag>
</view>
</view>
<view class="card-body">
<view class="info-row">
<text class="info-label">货主:</text>
<text class="info-value">{{ getStoreOwner(item) }}</text>
</view>
<view class="info-row">
<text class="info-label">总箱数:</text>
<text class="info-value">{{ item.total_box_count || 0 }}</text>
</view>
<view class="info-row">
<text class="info-label">备货人:</text>
<text class="info-value">{{ item.prep_operator_name || '--' }}</text>
</view>
<view class="info-row">
<text class="info-label">备注:</text>
<text class="info-value">{{ item.prep_remark || '--' }}</text>
</view>
</view>
<view class="card-footer">
<text class="footer-time">创建:{{ getOrderCreateAt(item) }}</text>
</view>
</view>
<view v-if="list.length > 0" class="load-more-hint">
<text>{{ noMore ? '没有更多了' : '上拉加载更多' }}</text>
</view>
</view>
<view class="safe-area-bottom"></view>
</scroll-view>
<!-- 分页 -->
<view class="pagination-wrap">
<pagination
:pageNum.sync="currentPage"
:pageSize="pageSize"
:total="total"
:showTotal="true"
:prevText="'上一页'"
:nextText="'下一页'"
:showFirstLast="true"
:firstText="'首页'"
:lastText="'末页'"
@change="handlePageChange"
/>
</view>
</view>
</template>
<script>
export default {
data() {
return {
keyword: '',
prepStatusTab: '',
prepTabs: [
{ label: '全部', value: '' },
{ label: '未备货', value: 'none' },
{ label: '备货中', value: 'padding' },
{ label: '已完成', value: 'fin' }
],
list: [],
currentPage: 1,
pageSize: 20,
total: 0,
noMore: false,
loading: false,
_hasShown: false
}
},
onLoad() {
this.fetchList();
},
onShow() {
// 从详情页返回时刷新备货状态(首次进入由 onLoad 拉取,避免重复)
if (this._hasShown) {
this.currentPage = 1;
this.fetchList();
}
this._hasShown = true;
},
computed: {
// 当前登录工号:后端 prep_operator_id 取的是当前员工工号(user.employees_id),
// 必须与备货人 prep_operator_id 同口径,不能优先取账号 user.id
currentUserId() {
const user = (this.$store && this.$store.getters && this.$store.getters.user) || {};
const candidates = [user.employees_id, user.id, user.user_id, user.userId, user.uid];
for (let i = 0; i < candidates.length; i++) {
const value = Number(candidates[i]);
if (Number.isFinite(value) && value > 0) return value;
}
const roleId = Number(this.$store && this.$store.getters && this.$store.getters.roleId);
return Number.isFinite(roleId) && roleId > 0 ? roleId : '';
}
},
methods: {
async fetchList() {
this.loading = true;
try {
const pagination = {
page: this.currentPage,
pageSize: this.pageSize
};
const keyword = String(this.keyword || '').trim();
const where = {};
if (keyword) {
where.delivery_order_code = {
operator: 'like',
value: keyword
};
}
// 备货状态筛选(简写结构)
if (this.prepStatusTab) {
where.prep_status = this.prepStatusTab;
}
const response = await this.$http('order.pendingOrder2b.list', {
pagination,
where,
sort: {
sortField: 'updated_at',
sortOrder: 'DESC'
}
});
const data = response?.data || response || {};
const rawList = Array.isArray(data.list) ? data.list : [];
const pag = data.pagination || {};
const total = Number(pag.total || 0);
if (this.currentPage === 1) {
this.list = rawList;
} else {
this.list = this.list.concat(rawList);
}
this.total = total;
this.noMore = this.list.length >= total;
} catch (error) {
console.error('[stockPreparation] fetchList error:', error);
if (this.currentPage === 1) {
this.list = [];
}
} finally {
this.loading = false;
}
},
handleSearch() {
this.currentPage = 1;
this.fetchList();
},
handleClear() {
this.keyword = '';
this.currentPage = 1;
this.fetchList();
},
handleCameraScan() {
uni.scanCode({
onlyFromCamera: true,
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
success: (res) => {
const code = String(res?.result || '').trim();
if (!code) return;
this.keyword = code;
this.currentPage = 1;
this.fetchList();
},
fail: () => {}
});
},
handlePrepStatusChange(value) {
if (this.prepStatusTab === value) return;
this.prepStatusTab = value;
this.currentPage = 1;
this.fetchList();
},
// 状态按钮样式:选中时按状态色调高亮(参考收货列表页)
statusTagClass(status) {
const toneMap = {
'': 'strong',
none: 'strong',
padding: 'warning',
fin: 'success'
};
const isActive = this.prepStatusTab === status.value;
const tone = toneMap[status.value] || '';
return {
active: isActive,
[`status-tag--tone-${tone}`]: isActive && !!tone
};
},
handlePageChange(page) {
if (page === this.currentPage) return;
this.currentPage = page;
this.fetchList();
},
handleLoadMore() {
if (this.loading || this.noMore) return;
this.currentPage += 1;
this.fetchList();
},
getItemKey(item, index) {
return item?.id ?? `order-${index}`;
},
getDeliveryOrderCode(item) {
return item?.delivery_order_code || item?.order_no || item?.order_code || '--';
},
isUrgent(item) {
return String(item?.is_urgent || item?.is_urgency || '').toUpperCase() === 'Y';
},
hasSn(item) {
const flag = item?.has_sn_item ?? item?.is_sn_order ?? item?.need_sn ?? item?.has_sn ?? item?.is_sn;
return String(flag || '').toUpperCase() === 'Y';
},
getPrepStatus(item) {
return String(item?.prep_status || 'none');
},
getPrepStatusText(item) {
const status = String(item?.prep_status || 'none');
const map = {
none: '未备货',
padding: '备货中',
fin: '已完成'
};
return map[status] || status;
},
getPrepStatusBgColor(item) {
const colorMap = {
none: '#2979ff',
padding: '#ff9800',
fin: '#18a058'
};
return colorMap[String(item?.prep_status || 'none')] || '#2979ff';
},
getStoreOwner(item) {
if (!item || typeof item !== 'object') return '--';
return item.store_remark || '--';
},
getOrderCreateAt(item) {
return this.formatDateTime(item?.created_at ?? item?.create_at);
},
formatDateTime(value) {
if (value === null || value === undefined || value === '') return '--';
const date = new Date(String(value).trim());
if (Number.isNaN(date.getTime())) return String(value).trim();
const pad = (n) => String(n).padStart(2, '0');
const year = date.getFullYear();
const month = pad(date.getMonth() + 1);
const day = pad(date.getDate());
const hour = pad(date.getHours());
const minute = pad(date.getMinutes());
const second = pad(date.getSeconds());
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
},
handleViewDetail(item) {
const orderId = Number(item?.id || 0);
if (!orderId) {
uni.showToast({ title: '订单ID缺失', icon: 'none' });
return;
}
const status = this.getPrepStatus(item);
if (status === 'none') {
this.startPrepAndEnter(item);
} else if (status === 'padding') {
if (!this.isCurrentOperator(item)) {
uni.showToast({ title: '该订单已由其他工号备货,无法操作', icon: 'none', duration: 2500 });
return;
}
this.goDetail(orderId);
} else {
this.goDetail(orderId);
}
},
isCurrentOperator(item) {
const operatorId = Number(item?.prep_operator_id || 0);
if (!operatorId) return true;
return operatorId === this.currentUserId;
},
goDetail(orderId) {
uni.navigateTo({
url: `./stockPreparationDetail?orderId=${orderId}`,
animationType: 'slide-in-right'
});
},
startPrepAndEnter(item) {
const orderId = Number(item?.id || 0);
if (!orderId) {
uni.showToast({ title: '订单ID缺失', icon: 'none' });
return;
}
this.doStartPrepAndEnter(orderId);
},
async doStartPrepAndEnter(orderId) {
uni.showLoading({ title: '开始备货中...' });
try {
const response = await this.$http('order.startB2bPrep', { ids: [orderId] }, '', false);
const data = response?.data || response || {};
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || data?.message || '开始备货失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
return;
}
this.goDetail(orderId);
} catch (error) {
console.error('[stockPreparation] startB2bPrep error:', error);
uni.showToast({ title: '网络异常', icon: 'none' });
} finally {
uni.hideLoading();
}
}
}
}
</script>
<style lang="scss" scoped>
.stock-prep-page {
display: flex;
flex-direction: column;
height: 100vh;
overflow: hidden;
background-color: #f8f8f8;
::v-deep .nav-wrap {
flex-shrink: 0;
}
}
.search-panel {
flex-shrink: 0;
padding: 16rpx 24rpx 8rpx;
background-color: #ffffff;
}
.status-tags {
flex-shrink: 0;
display: flex;
align-items: center;
padding: 8rpx 24rpx 16rpx;
background-color: #ffffff;
.status-tag {
flex: 1;
height: 56rpx;
padding: 0 12rpx;
display: flex;
align-items: center;
justify-content: center;
background: #f5f7fa;
border: 1rpx solid #ebeef5;
border-radius: 28rpx;
position: relative;
& + .status-tag {
margin-left: 16rpx;
}
&.active {
background: #2979ff;
border-color: #2979ff;
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.28);
.tag-name {
color: #ffffff;
font-weight: bold;
}
}
&.active.status-tag--tone-warning {
background: #ff9800;
border-color: #ff9800;
box-shadow: 0 4rpx 12rpx rgba(255, 152, 0, 0.28);
}
&.active.status-tag--tone-success {
background: #18a058;
border-color: #18a058;
box-shadow: 0 4rpx 12rpx rgba(24, 160, 88, 0.28);
}
&.active.status-tag--tone-muted {
background: #909399;
border-color: #909399;
box-shadow: 0 4rpx 12rpx rgba(144, 147, 153, 0.28);
}
.tag-name {
font-size: 34rpx;
color: #606266;
}
}
}
.list-content {
flex: 1;
min-height: 0;
padding: 16rpx 24rpx 0;
box-sizing: border-box;
}
.loading-state,
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 120rpx 0;
}
.loading-text,
.empty-text {
margin-top: 16rpx;
font-size: 28rpx;
color: #909399;
}
.order-list {
padding-bottom: 16rpx;
}
.order-card {
margin-bottom: 20rpx;
padding: 22rpx;
background-color: #ffffff;
border-radius: 18rpx;
border: 1rpx solid #ebeef5;
}
.card-header {
display: flex;
align-items: center;
padding-bottom: 15rpx;
margin-bottom: 18rpx;
border-bottom: 1rpx solid #f0f0f0;
.prep-tag {
margin-left: 12rpx;
flex-shrink: 0;
display: flex;
align-items: center;
}
::v-deep .u-tag__text {
font-size: 36rpx;
line-height: 36rpx;
}
}
.order-code {
flex: 1;
min-width: 0;
font-size: 40rpx;
font-weight: bold;
color: #303133;
word-break: break-all;
}
.badge {
margin-left: 12rpx;
padding: 4rpx 16rpx;
border-radius: 8rpx;
font-size: 26rpx;
flex-shrink: 0;
}
.badge--urgent {
background-color: #fef0f0;
color: #f56c6c;
}
.badge--sn {
background-color: #fff7e6;
color: #fa8c16;
}
.card-body {
margin-bottom: 12rpx;
}
.info-row {
display: flex;
align-items: flex-start;
font-size: 36rpx;
line-height: 1.5;
margin-bottom: 12rpx;
}
.info-label {
flex-shrink: 0;
margin-right: 8rpx;
font-size: 36rpx;
color: #909399;
white-space: nowrap;
}
.info-value {
flex: 1;
min-width: 0;
font-size: 36rpx;
color: #303133;
word-break: break-all;
}
.card-footer {
display: flex;
align-items: center;
justify-content: space-between;
padding-top: 12rpx;
}
.footer-time {
font-size: 36rpx;
line-height: 1.5;
color: #909399;
}
.load-more-hint {
padding: 16rpx 0;
text-align: center;
font-size: 24rpx;
color: #c0c4cc;
}
.safe-area-bottom {
height: 20rpx;
}
.pagination-wrap {
flex-shrink: 0;
padding: 12rpx 24rpx;
background-color: #ffffff;
border-top: 1rpx solid #ebeef5;
}
</style>

View File

@ -0,0 +1,895 @@
<template>
<view class="normar_container prep-detail-page">
<page-nav title="备货明细" @back="handleBack">
<template #right>
<view v-if="canEdit" class="nav-save-btn" @click="savePacking">
<text class="nav-save-btn__text">保存分箱</text>
</view>
</template>
</page-nav>
<scroll-view class="detail-scroll" scroll-y>
<view v-if="loading" class="loading-state">
<u-loading-icon mode="circle" size="40" color="#2979ff"></u-loading-icon>
<text class="loading-text">加载中...</text>
</view>
<template v-else>
<view class="summary-card">
<view class="summary-row">
<text class="summary-label">发货单号:</text>
<text class="summary-value">{{ detail.delivery_order_code || '--' }}</text>
</view>
<view class="summary-row">
<text class="summary-label">备货状态:</text>
<text class="summary-value">{{ prepStatusText }}</text>
</view>
<view class="summary-row">
<text class="summary-label">总箱数:</text>
<text class="summary-value">{{ displayTotalBoxCount }}</text>
</view>
<view class="summary-row">
<text class="summary-label">取货储位:</text>
<text class="summary-value">{{ detail.pick_location_count || 0 }} 个</text>
</view>
</view>
<view v-if="editing" class="goods-list">
<view class="packing-tip">
<text class="packing-tip__text">同一商品行 + 箱号不能重复;分箱数量合计需等于应拣数量(超量会被拦截)。</text>
</view>
<view v-for="(it, idx) in editItems" :key="idx" class="goods-item">
<view class="goods-item__header">
<text class="goods-item__name">{{ it.item_name }}、{{ it.item_code }}</text>
</view>
<view class="goods-item__row">
<text class="goods-item__label">应拣</text>
<text class="goods-item__value">{{ it.plan_qty || 0 }}</text>
<text class="goods-item__label">已分箱</text>
<text class="goods-item__value" :class="{ 'goods-item__value--success': getItemDiffQty(it) === 0 }">{{ getItemPackedQty(it) }}</text>
<text class="goods-item__label">{{ getDiffLabel(it) }}</text>
<text class="goods-item__value" :class="{ 'goods-item__value--success': getItemDiffQty(it) === 0 }">{{ getItemDiffAbs(it) }}</text>
</view>
<view v-if="getPickLocations(it)" class="goods-item__locations">
<text class="goods-item__label">取货储位</text>
<text class="goods-item__location">{{ getPickLocations(it) }}</text>
</view>
<view v-for="(box, bi) in it.boxes" :key="bi" class="box-edit-row">
<input class="box-edit-input" v-model="box.box_no" placeholder="箱号" @blur="handleBoxInputBlur" />
<input class="box-edit-input box-edit-input--qty" v-model="box.quantity" type="number" placeholder="数量" @blur="handleBoxInputBlur" />
<text class="box-edit-del" @click="removeBox(idx, bi)">删除</text>
</view>
<view class="box-add" @click="addBox(idx)">
<text class="box-add__text">+ 添加箱号</text>
</view>
</view>
</view>
<template v-else>
<view v-if="items.length === 0" class="empty-state">
<u-icon name="list" size="86" color="#c0c4cc"></u-icon>
<text class="empty-text">暂无商品明细</text>
</view>
<view v-else class="goods-list">
<view v-for="(it, idx) in items" :key="idx" class="goods-item">
<view class="goods-item__header">
<text class="goods-item__name">{{ it.item_name || it.item_code || '--' }}</text>
<text class="goods-item__code">{{ it.item_code || '' }}</text>
</view>
<view class="goods-item__row">
<text class="goods-item__label">应拣:</text>
<text class="goods-item__value">{{ it.plan_qty || 0 }}</text>
<text class="goods-item__label">已分箱:</text>
<text class="goods-item__value" :class="{ 'goods-item__value--warn': requireMatch && (it.packed_quantity || 0) < (it.plan_qty || 0) }">{{ it.packed_quantity || 0 }}</text>
</view>
<view v-if="it.boxes && it.boxes.length > 0" class="goods-item__boxes">
<text class="goods-item__label">分箱:</text>
<view class="goods-item__box-list">
<text v-for="(box, bi) in it.boxes" :key="bi" class="goods-item__box">{{ box.box_no || '--' }} × {{ box.quantity || 0 }}</text>
</view>
</view>
<view v-if="getPickLocations(it)" class="goods-item__locations">
<text class="goods-item__label">取货储位:</text>
<text class="goods-item__location">{{ getPickLocations(it) }}</text>
</view>
</view>
</view>
</template>
<view class="photo-card">
<view class="photo-card__header">
<text class="photo-card__title">备货凭证照片</text>
</view>
<uploadImgCos
business_type="b2b_order"
:business_id="orderId"
v-model="photoList"
@change="handlePhotoChange"
></uploadImgCos>
</view>
<view class="total-box-card">
<text class="total-box-label">总箱数:</text>
<text class="total-box-value">{{ displayTotalBoxCount }}</text>
</view>
<view class="remark-card">
<view class="remark-card__header">
<text class="remark-card__title">备货备注</text>
<text class="remark-card__required">必填</text>
</view>
<textarea
v-model="prepRemark"
class="remark-textarea"
placeholder="例:共3箱,需要4米2车"
placeholder-class="remark-placeholder"
:maxlength="500"
></textarea>
<view class="remark-card__footer">
<text class="remark-count">{{ prepRemark.length }}/500</text>
</view>
<view class="submit-tip">
<text class="submit-tip__text">提交即完成备货并同步扣减库存,不可撤回;未齐套的商品行会被后端拦截。</text>
</view>
</view>
</template>
<view class="safe-area-bottom"></view>
</scroll-view>
<!-- 底部操作栏 -->
<view v-if="canEdit" class="bottom-bar">
<u-button type="error" @click="handleCancelPrep">取消备货</u-button>
<u-button type="primary" :loading="submitting" @click="handleFinishPrep">完成备货</u-button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
orderId: null,
loading: false,
detail: {},
editing: false,
saving: false,
submitting: false,
editItems: [],
photoList: [],
prepRemark: '',
photoSyncTimer: null,
autoSaveTimer: null,
lastSavedPackingKey: ''
}
},
computed: {
items() {
return Array.isArray(this.detail.items) ? this.detail.items : [];
},
requireMatch() {
return !!this.detail.require_packing_quantity_match;
},
prepStatusText() {
const map = {
none: '未备货',
padding: '备货中',
fin: '已完成'
};
return map[String(this.detail.prep_status || 'none')] || String(this.detail.prep_status || 'none');
},
canEdit() {
return String(this.detail.prep_status || 'none') === 'padding';
},
// 总箱数随箱号/数量实时联动:编辑态按有效箱号行计数,非编辑态取后端字段
displayTotalBoxCount() {
if (this.editing) {
let count = 0;
for (const it of this.editItems) {
for (const box of it.boxes) {
const boxNo = String(box.box_no || '').trim();
const quantity = Number(box.quantity);
if (boxNo && Number.isFinite(quantity) && quantity >= 1) {
count += 1;
}
}
}
return count;
}
return Number(this.detail.total_box_count || 0);
}
},
onLoad(options) {
this.orderId = Number(options.orderId || 0);
if (this.orderId) {
this.fetchDetail();
} else {
uni.showToast({ title: '订单ID缺失', icon: 'none' });
}
},
methods: {
async fetchDetail() {
this.loading = true;
try {
const response = await this.$http('order.getB2bPackingSnapshot', { ids: [this.orderId] }, '', false);
const data = response?.data || response || {};
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || data?.message || '查询失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
return;
}
this.detail = data;
this.loadPhotos();
// 备货中:默认进入可编辑分箱
if (this.canEdit) {
this.startEdit();
}
} catch (error) {
console.error('[stockPreparationDetail] fetchDetail error:', error);
uni.showToast({ title: '网络异常', icon: 'none' });
} finally {
this.loading = false;
}
},
async loadPhotos() {
try {
const response = await this.$http('common.getImages', { type: 'b2b_order', id: Number(this.orderId) }, '', false);
const entries = this.extractImageEntries(response);
this.photoList = entries.map(e => ({
id: e.id || e.file_id || e.fileId || '',
url: e.url || e.path || e.image_url || ''
})).filter(e => e.url);
} catch (error) {
console.warn('[stockPreparationDetail] loadPhotos error:', error);
}
},
extractImageEntries(response) {
if (!response || typeof response !== 'object') return [];
const candidates = [
response.data,
response.data && response.data.data,
response.data && response.data.images,
response.data && response.data.list,
response.data && response.data.rows,
response.images,
response.list
];
for (let i = 0; i < candidates.length; i++) {
if (Array.isArray(candidates[i])) return candidates[i];
}
return [];
},
getPickLocations(item) {
const locs = item?.pick_locations;
if (!Array.isArray(locs) || locs.length === 0) return '';
return locs
.map(loc => loc?.space_name || loc?.name || '')
.filter(Boolean)
.join('、');
},
getItemPackedQty(item) {
const boxes = item?.boxes;
if (!Array.isArray(boxes)) return 0;
return boxes.reduce((sum, b) => sum + (Number(b?.quantity || 0) || 0), 0);
},
getItemDiffQty(item) {
const plan = Number(item?.plan_qty || 0);
return plan - this.getItemPackedQty(item);
},
getDiffLabel(item) {
return this.getItemDiffQty(item) < 0 ? '超' : '差';
},
getItemDiffAbs(item) {
return Math.abs(this.getItemDiffQty(item));
},
handlePhotoChange(fileList) {
const fileIds = (Array.isArray(fileList) ? fileList : [])
.map(f => Number(f?.id || f?.file_id || f?.fileId || 0))
.filter(id => Number.isFinite(id) && id > 0);
const uniqueIds = Array.from(new Set(fileIds));
clearTimeout(this.photoSyncTimer);
this.photoSyncTimer = setTimeout(() => {
this.syncOrderImages(uniqueIds);
}, 300);
},
async syncOrderImages(fileIds) {
try {
const response = await this.$http('order.updateB2bOrderImages', { ids: [this.orderId], images: fileIds }, '', false);
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || '照片同步失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
}
} catch (error) {
console.warn('[stockPreparationDetail] updateB2bOrderImages error:', error);
}
},
startEdit() {
this.editItems = this.items.map(it => ({
order_item_id: it.order_item_id || it.orderItemId,
item_code: it.item_code,
item_name: it.item_name,
plan_qty: it.plan_qty,
pick_locations: it.pick_locations || [],
boxes: (Array.isArray(it.boxes) && it.boxes.length > 0)
? it.boxes.map(b => ({ box_no: b.box_no || '', quantity: b.quantity || 0 }))
: []
}));
this.lastSavedPackingKey = '';
clearTimeout(this.autoSaveTimer);
this.editing = true;
},
addBox(idx) {
const item = this.editItems[idx];
if (!item) return;
const boxes = Array.isArray(item.boxes) ? item.boxes : [];
let maxNo = 0;
boxes.forEach(b => {
const n = Number(b.box_no);
if (Number.isFinite(n) && n > maxNo) maxNo = n;
});
item.boxes.push({
box_no: String(maxNo + 1),
// 第一个箱默认填应拣数,后续箱数量默认空
quantity: boxes.length === 0 ? Number(item.plan_qty || 0) : ''
});
this.scheduleAutoSave();
},
removeBox(idx, bi) {
if (!this.editItems[idx]) return;
this.editItems[idx].boxes.splice(bi, 1);
this.scheduleAutoSave();
},
buildPackingItems() {
const packingItems = [];
for (const it of this.editItems) {
for (const box of it.boxes) {
const boxNo = String(box.box_no || '').trim();
const quantity = Number(box.quantity);
if (!boxNo || !Number.isFinite(quantity) || quantity < 1) continue;
packingItems.push({
order_item_id: it.order_item_id,
box_no: boxNo,
quantity
});
}
}
return packingItems;
},
savePacking() {
const packingItems = this.buildPackingItems();
if (packingItems.length === 0) {
uni.showModal({
title: '提示',
content: '当前分箱明细为空,保存将清空该订单全部分箱,是否继续?',
success: (res) => {
if (res.confirm) {
this.doUpdatePacking([]);
}
}
});
return;
}
this.doUpdatePacking(packingItems);
},
handleBoxInputBlur() {
this.scheduleAutoSave();
},
scheduleAutoSave() {
clearTimeout(this.autoSaveTimer);
this.autoSaveTimer = setTimeout(() => {
this.autoSavePacking();
}, 300);
},
autoSavePacking() {
if (this.saving || this.submitting || !this.editing) return;
const packingItems = this.buildPackingItems();
if (packingItems.length === 0) return;
const key = JSON.stringify(packingItems);
if (key === this.lastSavedPackingKey) return;
this.lastSavedPackingKey = key;
this.doAutoUpdatePacking(packingItems);
},
async doAutoUpdatePacking(items) {
this.saving = true;
try {
const response = await this.$http('order.updateB2bPackingItems', { ids: [this.orderId], items }, '', false);
const data = response?.data || response || {};
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || data?.message || '保存失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
return;
}
uni.showToast({ title: '已保存', icon: 'none', duration: 800 });
} catch (error) {
console.warn('[stockPreparationDetail] autoSavePacking error:', error);
} finally {
this.saving = false;
}
},
async doUpdatePacking(items) {
this.saving = true;
try {
const response = await this.$http('order.updateB2bPackingItems', { ids: [this.orderId], items }, '', false);
const data = response?.data || response || {};
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || data?.message || '保存失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
return;
}
uni.showToast({ title: '保存成功', icon: 'success' });
this.fetchDetail();
} catch (error) {
console.error('[stockPreparationDetail] updateB2bPackingItems error:', error);
uni.showToast({ title: '网络异常', icon: 'none' });
} finally {
this.saving = false;
}
},
handleFinishPrep() {
const remark = String(this.prepRemark || '').trim();
if (!remark) {
uni.showToast({ title: '请填写备货备注', icon: 'none' });
return;
}
if (remark.length > 500) {
uni.showToast({ title: '备货备注不能超过500个字符', icon: 'none' });
return;
}
const totalBoxCount = Number(this.displayTotalBoxCount || 0);
if (!Number.isInteger(totalBoxCount) || totalBoxCount < 0) {
uni.showToast({ title: '总箱数无效', icon: 'none' });
return;
}
uni.showModal({
title: '提示',
content: '提交即完成备货并同步扣减库存,不可撤回;未齐套的商品行会被后端拦截。确认提交?',
success: (res) => {
if (res.confirm) {
this.doFinishPrep(remark, totalBoxCount);
}
}
});
},
async doFinishPrep(remark, totalBoxCount) {
this.submitting = true;
try {
const response = await this.$http('order.finishB2bPrep', {
ids: [this.orderId],
prep_remark: remark,
total_box_count: totalBoxCount
}, '', false);
const data = response?.data || response || {};
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || data?.message || '提交失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
return;
}
uni.showToast({ title: '备货已完成', icon: 'success' });
setTimeout(() => {
uni.navigateBack();
}, 800);
} catch (error) {
console.error('[stockPreparationDetail] finishB2bPrep error:', error);
uni.showToast({ title: '网络异常', icon: 'none' });
} finally {
this.submitting = false;
}
},
handleBack() {
// 备货中返回时,提示是否取消备货;其他状态直接返回
if (this.canEdit) {
uni.showModal({
title: '提示',
content: '确认取消备货?',
success: (res) => {
if (res.confirm) {
this.doCancelPrep();
}
}
});
return;
}
uni.navigateBack({ delta: 1 });
},
handleCancelPrep() {
uni.showModal({
title: '提示',
content: '确认取消备货?',
success: (res) => {
if (res.confirm) {
this.doCancelPrep();
}
}
});
},
async doCancelPrep() {
uni.showLoading({ title: '取消备货中...' });
try {
const response = await this.$http('order.cancelB2bPrep', { ids: [this.orderId] }, '', false);
const data = response?.data || response || {};
if (response?.flag === 'failure') {
const msg = String(response?.message || response?.msg || data?.message || '取消备货失败');
uni.showToast({ title: msg, icon: 'none', duration: 2500 });
return;
}
uni.showToast({ title: '已取消备货', icon: 'success' });
setTimeout(() => {
uni.navigateBack();
}, 800);
} catch (error) {
console.error('[stockPreparationDetail] cancelB2bPrep error:', error);
uni.showToast({ title: '网络异常', icon: 'none' });
} finally {
uni.hideLoading();
}
}
}
}
</script>
<style lang="scss" scoped>
.prep-detail-page {
height: 100vh;
overflow: hidden;
background-color: #f8f8f8;
}
.detail-scroll {
flex: 1;
min-height: 0;
padding: 20rpx 24rpx 0;
box-sizing: border-box;
}
.loading-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 120rpx 0;
}
.loading-text {
margin-top: 16rpx;
font-size: 28rpx;
color: #909399;
}
.summary-card {
padding: 24rpx;
margin-bottom: 20rpx;
background-color: #ffffff;
border-radius: 18rpx;
border: 1rpx solid #ebeef5;
}
.photo-card {
padding: 24rpx;
margin-bottom: 20rpx;
background-color: #ffffff;
border-radius: 18rpx;
border: 1rpx solid #ebeef5;
}
.photo-card__header {
margin-bottom: 16rpx;
}
.photo-card__title {
font-size: 30rpx;
font-weight: 600;
color: #303133;
}
.total-box-card {
display: flex;
align-items: center;
padding: 24rpx;
margin-bottom: 20rpx;
background-color: #ffffff;
border-radius: 18rpx;
border: 1rpx solid #ebeef5;
}
.total-box-label {
font-size: 36rpx;
color: #909399;
margin-right: 8rpx;
}
.total-box-value {
font-size: 34rpx;
font-weight: 600;
color: #303133;
}
.remark-card {
padding: 24rpx;
margin-bottom: 20rpx;
background-color: #ffffff;
border-radius: 18rpx;
border: 1rpx solid #ebeef5;
}
.remark-card__header {
display: flex;
align-items: center;
margin-bottom: 16rpx;
}
.remark-card__title {
font-size: 30rpx;
font-weight: 600;
color: #303133;
}
.remark-card__required {
margin-left: 12rpx;
padding: 2rpx 12rpx;
font-size: 22rpx;
color: #f56c6c;
background-color: #fef0f0;
border-radius: 6rpx;
}
.remark-textarea {
width: 100%;
height: 160rpx;
padding: 16rpx;
box-sizing: border-box;
font-size: 36rpx;
color: #303133;
background-color: #f8f8f8;
border-radius: 8rpx;
}
.remark-placeholder {
font-size: 36rpx;
color: #c0c4cc;
}
.remark-card__footer {
display: flex;
justify-content: flex-end;
margin-top: 8rpx;
}
.remark-count {
font-size: 24rpx;
color: #c0c4cc;
}
.submit-tip {
margin-top: 16rpx;
padding: 16rpx;
background-color: #fff7e6;
border-radius: 8rpx;
}
.submit-tip__text {
font-size: 32rpx;
line-height: 1.5;
color: #fa8c16;
}
.summary-row {
display: flex;
align-items: center;
margin-bottom: 12rpx;
&:last-child {
margin-bottom: 0;
}
}
.summary-label {
flex-shrink: 0;
font-size: 36rpx;
color: #909399;
margin-right: 8rpx;
}
.summary-value {
flex: 1;
min-width: 0;
font-size: 34rpx;
color: #303133;
word-break: break-all;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 0;
}
.empty-text {
margin-top: 16rpx;
font-size: 28rpx;
color: #909399;
}
.packing-tip {
padding: 16rpx;
margin-bottom: 16rpx;
background-color: #fff7e6;
border-radius: 8rpx;
}
.packing-tip__text {
font-size: 32rpx;
line-height: 1.5;
color: #fa8c16;
}
.goods-item {
padding: 20rpx;
margin-bottom: 16rpx;
background-color: #ffffff;
border-radius: 12rpx;
border: 1rpx solid #ebeef5;
}
.goods-item__header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12rpx;
}
.goods-item__name {
flex: 1;
min-width: 0;
font-size: 34rpx;
font-weight: 600;
color: #303133;
}
.goods-item__code {
flex-shrink: 0;
margin-left: 12rpx;
font-size: 26rpx;
color: #909399;
}
.goods-item__row {
display: flex;
align-items: center;
margin-bottom: 8rpx;
}
.goods-item__label {
font-size: 36rpx;
color: #909399;
margin-right: 6rpx;
}
.goods-item__value {
font-size: 34rpx;
color: #303133;
margin-right: 20rpx;
}
.goods-item__value--warn {
color: #f56c6c;
}
.goods-item__value--success {
color: #18a058;
}
.goods-item__boxes,
.goods-item__locations {
display: flex;
align-items: flex-start;
margin-bottom: 8rpx;
}
.goods-item__box-list {
flex: 1;
display: flex;
flex-wrap: wrap;
}
.goods-item__box {
margin-right: 12rpx;
margin-bottom: 6rpx;
padding: 2rpx 12rpx;
font-size: 24rpx;
color: #2979ff;
background-color: #ecf5ff;
border-radius: 6rpx;
}
.goods-item__location {
flex: 1;
font-size: 34rpx;
color: #303133;
word-break: break-all;
}
.safe-area-bottom {
height: 20rpx;
}
.bottom-bar {
flex-shrink: 0;
display: flex;
align-items: center;
padding: 16rpx 24rpx;
background-color: #ffffff;
border-top: 1rpx solid #ebeef5;
::v-deep .u-button {
flex: 1;
font-size: 36rpx;
}
::v-deep .u-button + .u-button {
margin-left: 20rpx;
}
::v-deep .u-button__text,
::v-deep .u-button__loading-text {
font-size: 36rpx !important;
}
}
.nav-save-btn {
display: flex;
align-items: center;
justify-content: center;
height: 64rpx;
padding: 0 24rpx;
background-color: #2979ff;
border-radius: 8rpx;
}
.nav-save-btn__text {
font-size: 36rpx;
line-height: 1;
color: #ffffff;
}
.box-edit-row {
display: flex;
align-items: center;
margin-bottom: 12rpx;
}
.box-edit-input {
flex: 1;
min-width: 0;
height: 64rpx;
padding: 0 16rpx;
box-sizing: border-box;
font-size: 36rpx;
color: #303133;
background-color: #ffffff;
border: 1rpx solid #dcdfe6;
border-radius: 8rpx;
}
.box-edit-input--qty {
margin-left: 12rpx;
}
.box-edit-del {
flex-shrink: 0;
margin-left: 12rpx;
padding: 0 8rpx;
font-size: 36rpx;
color: #f56c6c;
}
.box-add {
display: inline-block;
padding: 8rpx 20rpx;
background-color: #ecf5ff;
border-radius: 8rpx;
}
.box-add__text {
font-size: 36rpx;
color: #2979ff;
}
</style>