WMS_PDA/src/pages/B2BOperation/stockPreparation.vue
zm2000 545018caaf feat(B2B备货): 详情页扫描标记与批量箱号操作,语音播报优化
- pickupOperation/stockPreparation 列表新增"快递"字段展示
- stockPreparation 进入详情页携带运单号,返回列表时清空搜索关键词
- stockPreparationDetail 展示运单号,商品扫描后标记"已扫"
- 箱号支持"+总箱数"批量生成、按区间批量删除、清空全部
- 集成扫码广播生命周期,条码归一化后匹配商品
- 语音播报:HTTP 接口失败后 60 秒内跳过避免超时阻塞,TTS 初始化失败清理状态
- 版本号升级至 1.0.146(package.json / manifest.json)
2026-11-21 14:41:24 +08:00

736 lines
19 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="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">{{ getWaybillText(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">{{ getDeliveryOrderCode(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">{{ getLogisticsName(item) || '--' }}</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 class="info-row">
<text class="info-label">提货车牌:</text>
<text class="info-value">{{ item.pickup_plate_number || '--' }}</text>
</view>
<view v-if="getPrepImages(item).length > 0" class="photo-row">
<text class="info-label">备货照片:</text>
<view class="photo-thumbs">
<image
v-for="(img, imgIndex) in getPrepImages(item)"
:key="'prep-' + imgIndex"
:src="img.url"
class="photo-thumb"
mode="aspectFill"
@click.stop="previewImages(getPrepImages(item), imgIndex)"
></image>
</view>
</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.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('start');
this.fetchList();
},
onShow() {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.safeDispatchBroadcast('resume');
// 从详情页返回时刷新备货状态(首次进入由 onLoad 拉取,避免重复)
if (this._hasShown) {
this.keyword = '';
this.currentPage = 1;
this.fetchList();
}
this._hasShown = true;
},
onHide() {
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.safeDispatchBroadcast('stop');
},
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: {
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[stockPreparation] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[stockPreparation] broadcast/${action} 调用异常:`, error);
}
},
normalizeUniScanResult(scanResult) {
if (!scanResult) {
return '';
}
if (typeof scanResult === 'string') {
return scanResult.trim();
}
if (typeof scanResult.result === 'string') {
return scanResult.result.trim();
}
if (Array.isArray(scanResult.result)) {
const firstResult = scanResult.result.find(item => item);
if (typeof firstResult === 'string') {
return firstResult.trim();
}
if (firstResult && typeof firstResult.data === 'string') {
return firstResult.data.trim();
}
}
if (typeof scanResult.data === 'string') {
return scanResult.data.trim();
}
return '';
},
handleBroadcastResult(result) {
const rawCode = this.normalizeUniScanResult(result);
if (!rawCode) {
return;
}
this.keyword = rawCode;
this.currentPage = 1;
this.fetchList();
},
async fetchList() {
this.loading = true;
try {
const pagination = {
page: this.currentPage,
pageSize: this.pageSize
};
const keyword = String(this.keyword || '').trim();
const where = {};
if (keyword) {
// 顶部搜索按运单号精确查询(与 order-review 列表一致)
where.waybill_codes = {
operator: 'eq',
type: 'text',
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';
},
getLogisticsName(item) {
return item?.logistics_name || item?.sys_logistics_name || '';
},
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 || '--';
},
getWaybillCodes(item) {
const raw = item?.waybill_codes ?? item?.express_numbers;
if (Array.isArray(raw)) {
return raw.map(String).filter(Boolean);
}
if (typeof raw === 'string' && raw.trim()) {
return raw.split(/[,,]/).map(s => s.trim()).filter(Boolean);
}
return [];
},
getWaybillText(item) {
const codes = this.getWaybillCodes(item);
return codes.length > 0 ? codes.join(' / ') : '--';
},
getOrderCreateAt(item) {
return this.formatDateTime(item?.created_at ?? item?.create_at);
},
getPrepImages(item) {
return this.normalizeImages(item?.images);
},
normalizeImages(list) {
if (!Array.isArray(list)) return [];
return list
.filter(e => e && (e.url || e.file_id || e.fileId))
.map(e => ({ url: e.url || e.path || e.image_url || '' }))
.filter(e => e.url);
},
previewImages(images, index) {
const urls = (Array.isArray(images) ? images : []).map(e => e.url).filter(Boolean);
if (!urls.length) return;
uni.previewImage({
urls,
current: urls[index] || urls[0]
});
},
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, this.getWaybillText(item));
} else {
this.goDetail(orderId, this.getWaybillText(item));
}
},
isCurrentOperator(item) {
const operatorId = Number(item?.prep_operator_id || 0);
if (!operatorId) return true;
return operatorId === this.currentUserId;
},
goDetail(orderId, waybillText) {
const waybill = String(waybillText || '').trim();
const url = waybill
? `./stockPreparationDetail?orderId=${orderId}&waybill=${encodeURIComponent(waybill)}`
: `./stockPreparationDetail?orderId=${orderId}`;
uni.navigateTo({
url,
animationType: 'slide-in-right'
});
},
startPrepAndEnter(item) {
const orderId = Number(item?.id || 0);
if (!orderId) {
uni.showToast({ title: '订单ID缺失', icon: 'none' });
return;
}
this.doStartPrepAndEnter(orderId, this.getWaybillText(item));
},
async doStartPrepAndEnter(orderId, waybillText) {
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, waybillText);
} 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: 36rpx;
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;
}
.photo-row {
display: flex;
align-items: flex-start;
margin-bottom: 12rpx;
.photo-thumbs {
flex: 1;
min-width: 0;
display: flex;
flex-wrap: wrap;
}
.photo-thumb {
width: 120rpx;
height: 120rpx;
margin: 0 12rpx 12rpx 0;
border-radius: 8rpx;
background-color: #f5f7fa;
border: 1rpx solid #ebeef5;
}
}
.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>