feat: 优化商品查询与收货任务流程

This commit is contained in:
zm2000 2026-04-09 18:23:34 +08:00
parent dcd8ae4f68
commit 154b2d7b2a
5 changed files with 867 additions and 80 deletions

View File

@ -40,6 +40,12 @@ export default {
method: "POST",
isSystemApi: true
},
recognizeLicensePlate: {
path: "index.recognizeLicensePlate",
auth: true,
method: "POST",
isSystemApi: true
},
listTemplatesByType: {
path: "setting.printTemplate.listTemplatesByType",
auth: true,
@ -94,6 +100,12 @@ export default {
method: "POST",
isSystemApi: true
},
bindStore: {
path: "storage.receiving.bindStore",
auth: true,
method: "POST",
isSystemApi: true
},
addDetail: {
path: "storage.receiving.addDetail",
auth: true,

View File

@ -2,9 +2,8 @@
<view class="goods-detail-page">
<view class="normar_container">
<page-nav :title="title"></page-nav>
<scroll-view class="detail-content" scroll-y>
<view class="detail-card" v-if="item">
<view v-if="item" class="detail-fixed-header">
<view class="detail-card detail-card--header">
<view class="detail-header">
<view class="item-title-row">
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
@ -16,8 +15,8 @@
class="goods-image"
:src="getImageUrl(item)"
mode="aspectFill"
width="90rpx"
height="90rpx"
width="140rpx"
height="140rpx"
>
<template #error>
<view class="image-placeholder">
@ -35,8 +34,8 @@
class="grid-image"
:src="img"
mode="aspectFill"
width="44rpx"
height="44rpx"
width="68rpx"
height="68rpx"
>
<template #error>
<view class="image-placeholder image-placeholder-small">
@ -62,7 +61,12 @@
</view>
</view>
</view>
</view>
</view>
<view v-if="item" class="detail-fixed-placeholder"></view>
<scroll-view class="detail-content" scroll-y>
<view class="detail-card detail-card--body" v-if="item">
<view class="info-section">
<view class="info-row">
<text class="label">名称:</text>
@ -292,9 +296,28 @@ export default {
overflow: hidden;
}
.detail-fixed-header {
flex-shrink: 0;
position: fixed;
left: 0;
right: 0;
top: calc(var(--status-bar-height) + 110rpx);
z-index: 30;
background: #f7f8fa;
padding: 0 20rpx 0;
box-shadow: 0 2rpx 10rpx rgba(15, 23, 42, 0.04);
}
.detail-fixed-placeholder {
flex-shrink: 0;
height: 290rpx;
}
.detail-content {
flex: 1;
min-height: 0;
position: relative;
z-index: 0;
}
.detail-card {
@ -304,6 +327,16 @@ export default {
padding: 20rpx;
}
.detail-card--header {
margin: 0;
padding: 20rpx;
border-radius: 0 0 12rpx 12rpx;
}
.detail-card--body {
margin-top: 20rpx;
}
.detail-header {
padding-bottom: 18rpx;
border-bottom: 2rpx solid #e5e7eb;
@ -318,7 +351,7 @@ export default {
}
.goods-name {
font-size: 30rpx;
font-size: 42rpx;
font-weight: 600;
color: #303133;
}
@ -329,7 +362,7 @@ export default {
}
.item-thumb {
width: 90rpx;
width: 140rpx;
margin-right: 20rpx;
flex-shrink: 0;
}
@ -341,8 +374,8 @@ export default {
}
.goods-image-grid {
width: 90rpx;
height: 90rpx;
width: 140rpx;
height: 140rpx;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
@ -351,8 +384,8 @@ export default {
.grid-cell {
position: relative;
width: 44rpx;
height: 44rpx;
width: 68rpx;
height: 68rpx;
border-radius: 8rpx;
overflow: hidden;
background: #f5f7fa;
@ -364,8 +397,8 @@ export default {
}
.image-placeholder {
width: 90rpx;
height: 90rpx;
width: 140rpx;
height: 140rpx;
display: flex;
align-items: center;
justify-content: center;
@ -373,8 +406,8 @@ export default {
}
.image-placeholder-small {
width: 44rpx;
height: 44rpx;
width: 68rpx;
height: 68rpx;
}
.more-mask {
@ -390,7 +423,7 @@ export default {
}
.more-text {
font-size: 18rpx;
font-size: 22rpx;
color: #fff;
font-weight: 600;
}
@ -414,7 +447,7 @@ export default {
.compact-label {
width: auto;
margin-right: 6rpx;
font-size: 24rpx;
font-size: 35rpx;
color: #909399;
white-space: nowrap;
flex-shrink: 0;
@ -422,7 +455,7 @@ export default {
.compact-value {
flex: 1;
font-size: 24rpx;
font-size: 35rpx;
color: #000;
white-space: nowrap;
overflow: hidden;
@ -443,14 +476,14 @@ export default {
.label {
width: auto;
margin-right: 6rpx;
font-size: 24rpx;
font-size: 35rpx;
color: #909399;
flex-shrink: 0;
}
.value {
flex: 1;
font-size: 24rpx;
font-size: 35rpx;
color: #000;
white-space: nowrap;
overflow: hidden;

View File

@ -1,26 +1,47 @@
<template>
<view class="goods-query-page">
<view class="normar_container">
<page-nav :title="title"></page-nav>
<view class="search-panel">
<view class="search-input-wrap">
<u-search
v-model="keyword"
placeholder="请输入商品条码或名称"
:bg-color="'#f5f5f5'"
shape="round"
:show-action="false"
@search="handleSearch"
@clear="handleSearch"
></u-search>
<view class="search-actions">
<view class="scan-btn" @click="handleCameraScan">
<u-icon name="scan" size="38rpx" color="#2979ff"></u-icon>
<view class="page-header">
<page-nav :title="title">
<template #right>
<view class="nav-mode-switch-group">
<view
class="nav-mode-switch-btn"
:class="{ 'nav-mode-switch-btn--active': queryMode === 'batch' }"
@click="setQueryMode('batch')"
>
<text class="nav-mode-switch-btn__text">批次</text>
</view>
<view
class="nav-mode-switch-btn"
:class="{ 'nav-mode-switch-btn--active': queryMode === 'nonBatch' }"
@click="setQueryMode('nonBatch')"
>
<text class="nav-mode-switch-btn__text">非批次</text>
</view>
</view>
<view class="search-divider"></view>
<view class="search-btn" @click="handleSearch">
<text class="search-btn__text">搜索</text>
</template>
</page-nav>
<view class="search-panel">
<view class="search-input-wrap">
<u-search
v-model="keyword"
placeholder="请输入商品条码或名称"
:bg-color="'#f5f5f5'"
shape="round"
:show-action="false"
@search="handleSearch"
@clear="handleSearch"
></u-search>
<view class="search-actions">
<view class="scan-btn" @click="handleCameraScan">
<u-icon name="scan" size="38rpx" color="#2979ff"></u-icon>
</view>
<view class="search-divider"></view>
<view class="search-btn" @click="handleSearch">
<text class="search-btn__text">搜索</text>
</view>
</view>
</view>
</view>
@ -45,8 +66,8 @@
class="goods-image"
:src="getImageUrl(item)"
mode="aspectFill"
width="90rpx"
height="90rpx"
width="140rpx"
height="140rpx"
>
<template #error>
<view class="image-placeholder">
@ -67,8 +88,8 @@
class="grid-image"
:src="img"
mode="aspectFill"
width="44rpx"
height="44rpx"
width="68rpx"
height="68rpx"
>
<template #error>
<view class="image-placeholder image-placeholder-small">
@ -99,11 +120,57 @@
<text class="label">SKU规格:</text>
<text class="value">{{ item.sku_property || '--' }}</text>
</view>
<view v-if="hasBatchNumber(item)" class="item-row">
<text class="label">批次号:</text>
<text class="value">{{ getBatchNumberText(item) }}</text>
</view>
</view>
<view class="item-arrow" @click.stop="goProductDetail(item)">
<u-icon name="arrow-right" size="18" color="#c0c4cc" :custom-style="{ pointerEvents: 'none' }"></u-icon>
</view>
</view>
<view v-if="queryMode === 'nonBatch' && getStorageList(item).length" class="storage-section">
<scroll-view class="storage-scroll" scroll-x>
<view class="storage-table storage-table--non-batch">
<view class="storage-table__head storage-table__row">
<text class="storage-col storage-col--space">库位</text>
<text class="storage-col storage-col--qty">库存</text>
<text class="storage-col storage-col--qty">可移库存</text>
</view>
<view
v-for="(storageItem, storageIndex) in getStorageList(item)"
:key="getStorageItemKey(storageItem, storageIndex)"
class="storage-table__row"
>
<text class="storage-col storage-col--space">{{ getStorageSpaceText(storageItem) }}</text>
<text class="storage-col storage-col--qty">{{ getStorageQuantityText(storageItem) }}</text>
<text class="storage-col storage-col--qty storage-col--highlight">{{ getStorageAvailableText(storageItem) }}</text>
</view>
</view>
</scroll-view>
</view>
<view v-if="queryMode === 'batch' && getBatchStorageList(item).length" class="storage-section">
<scroll-view class="storage-scroll" scroll-x>
<view class="storage-table storage-table--batch">
<view class="storage-table__head storage-table__row">
<text class="storage-col storage-col--batch">批次号</text>
<text class="storage-col storage-col--space">库位</text>
<text class="storage-col storage-col--qty">库存</text>
<text class="storage-col storage-col--qty">可移库存</text>
</view>
<view
v-for="(storageItem, storageIndex) in getBatchStorageList(item)"
:key="getBatchStorageItemKey(item, storageItem, storageIndex)"
class="storage-table__row"
>
<text class="storage-col storage-col--batch">{{ getBatchNumberBySource(storageItem, item) }}</text>
<text class="storage-col storage-col--space">{{ getStorageSpaceText(storageItem) }}</text>
<text class="storage-col storage-col--qty">{{ getStorageQuantityText(storageItem) }}</text>
<text class="storage-col storage-col--qty storage-col--highlight">{{ getStorageAvailableText(storageItem) }}</text>
</view>
</view>
</scroll-view>
</view>
</view>
</view>
@ -123,8 +190,10 @@
return {
title: '商品查询',
keyword: '',
queryMode: 'nonBatch',
loading: false,
list: [],
rawList: [],
restoreScrollTop: 0,
listScrollTopCache: 0
}
@ -363,6 +432,55 @@
return String(item.item_name || item.product_name || item.name || '').trim();
},
getBatchNumberText(item) {
if (!item || typeof item !== 'object') {
return '--';
}
return item.batch_number || item.batch_no || item.lot_number || item.lot_no || '--';
},
hasBatchNumber(item) {
return this.getBatchNumberText(item) !== '--';
},
applyQueryModeFilter(list) {
if (!Array.isArray(list) || !list.length) {
return [];
}
if (this.queryMode === 'batch') {
return list;
}
return list.filter(item => !this.hasBatchNumber(item));
},
updateDisplayListByMode(sourceList, keyword, isBarcodeKeyword) {
const filteredByKeyword = isBarcodeKeyword
? this.filterByBarcodeExact(sourceList, keyword)
: this.filterByNameContains(sourceList, keyword);
this.list = this.applyQueryModeFilter(filteredByKeyword);
},
buildQueryParams(keyword) {
return {
keyword,
with_stock: true,
is_batch: this.queryMode === 'batch'
};
},
setQueryMode(nextMode) {
if (!nextMode || nextMode === this.queryMode) {
return;
}
this.queryMode = nextMode;
const keyword = this.normalizeKeyword(this.keyword);
if (!keyword) {
this.list = this.applyQueryModeFilter(this.rawList);
return;
}
this.handleSearch();
},
filterByNameContains(list, keyword) {
const target = String(keyword || '').trim().toLowerCase();
if (!target) {
@ -413,6 +531,101 @@
getImageThumbList(item) {
return this.getImageList(item).slice(0, 4);
},
getStorageList(item) {
if (!item || typeof item !== 'object') {
return [];
}
if (Array.isArray(item.storage)) {
return item.storage.filter(entry => entry && typeof entry === 'object');
}
if (Array.isArray(item.wms_storage)) {
return item.wms_storage.filter(entry => entry && typeof entry === 'object');
}
return [];
},
getBatchStorageList(item) {
const storageList = this.getStorageList(item);
if (storageList.length) {
return storageList;
}
if (item && typeof item === 'object') {
return [item];
}
return [];
},
getStorageItemKey(item, index) {
if (!item || typeof item !== 'object') {
return index;
}
return item.id || item.space_id || item.storage_id || item.space_barcode || item.space_name || index;
},
getBatchStorageItemKey(sourceItem, storageItem, index) {
if (!storageItem || typeof storageItem !== 'object') {
return this.getStorageItemKey(sourceItem, index);
}
return storageItem.id
|| storageItem.batch_id
|| storageItem.space_id
|| `${this.getBatchNumberBySource(storageItem, sourceItem)}_${this.getStorageSpaceText(storageItem)}_${index}`;
},
getBatchNumberBySource(item, fallbackItem) {
const currentBatch = this.getBatchNumberText(item);
if (currentBatch !== '--') {
return currentBatch;
}
return this.getBatchNumberText(fallbackItem);
},
getStorageSpaceText(item) {
if (!item || typeof item !== 'object') {
return '--';
}
return item.space_code
|| item.space?.code
|| item.space?.space_code
|| item.space?.name
|| item.space_name
|| item.space_barcode
|| item.location_name
|| item.position_name
|| item.name
|| '--';
},
getStorageQuantityText(item) {
if (!item || typeof item !== 'object') {
return '--';
}
return this.getValueOrDash(
item.quantity
?? item.actual_quantity
?? item.stock
?? item.total_quantity
?? item.qty
);
},
getStorageAvailableText(item) {
if (!item || typeof item !== 'object') {
return '--';
}
return this.getValueOrDash(
item.available_quantity
?? item.movable_quantity
?? item.moveable_quantity
?? item.can_move_quantity
?? item.free_quantity
?? item.usable_quantity
);
},
getExtraImageCount(item) {
const total = this.getImageList(item).length;
return total > 4 ? total - 4 : 0;
@ -446,28 +659,21 @@
async handleSearch() {
const keyword = this.normalizeKeyword(this.keyword);
this.keyword = keyword;
console.log('[ProductQuery] 搜索内容:', keyword, '模式:', this.queryMode);
if (!keyword) {
this.rawList = [];
this.list = [];
console.log('[ProductQuery] 搜索内容为空,结果已清空');
return;
}
const isBarcodeKeyword = this.isBarcodeLike(keyword);
const queryParams = {
pagination: {
page: 1,
pageSize: 100
},
keyword
};
if (isBarcodeKeyword) {
queryParams.barcode = keyword;
queryParams.barcodes = [keyword];
}
const queryParams = this.buildQueryParams(keyword);
console.log('[ProductQuery] 搜索参数:', queryParams);
this.loading = true;
try {
const res = await this.$http('stock.warehouse.list', queryParams);
const res = await this.$http('stock.warehouse.search', queryParams);
if (res && res.code === 200) {
const responseData = res.data;
@ -478,20 +684,27 @@
nextList = responseData.list;
} else if (responseData && Array.isArray(responseData.rows)) {
nextList = responseData.rows;
} else if (responseData && Array.isArray(responseData.data)) {
nextList = responseData.data;
}
this.list = isBarcodeKeyword
? this.filterByBarcodeExact(nextList, keyword)
: this.filterByNameContains(nextList, keyword);
this.rawList = nextList;
this.updateDisplayListByMode(nextList, keyword, isBarcodeKeyword);
console.log('[ProductQuery] 搜索结果数量:', this.list.length);
console.log('[ProductQuery] 搜索结果列表:', this.list);
} else {
this.rawList = [];
this.list = [];
console.log('[ProductQuery] 搜索失败响应:', res);
uni.showToast({
title: (res && res.message) || '查询失败',
icon: 'none'
});
}
} catch (error) {
this.rawList = [];
this.list = [];
console.error('[ProductQuery] 搜索异常:', error);
uni.showToast({
title: (error && error.message) || '查询失败',
icon: 'none'
@ -521,13 +734,72 @@
overflow: hidden;
}
.page-header {
position: sticky;
top: 0;
z-index: 20;
background: #fff;
flex-shrink: 0;
box-shadow: 0 2rpx 10rpx rgba(15, 23, 42, 0.04);
}
.search-panel {
padding: 20rpx;
background: #fff;
border-bottom: 1rpx solid #f2f2f2;
flex-shrink: 0;
position: relative;
z-index: 2;
z-index: 1;
}
::v-deep .nav-title .right {
width: auto;
min-width: 182rpx;
display: flex;
justify-content: flex-end;
}
.nav-mode-switch-group {
height: 50rpx;
padding: 3rpx;
border-radius: 26rpx;
background: #edf2ff;
display: inline-flex;
align-items: center;
justify-content: flex-end;
box-sizing: border-box;
border: 1rpx solid #dbe7ff;
}
.nav-mode-switch-btn {
min-width: 76rpx;
height: 42rpx;
padding: 0 14rpx;
border-radius: 21rpx;
display: inline-flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
&__text {
font-size: 20rpx;
font-weight: 600;
color: #5f6b7a;
line-height: 1;
}
&:active {
opacity: 0.88;
}
}
.nav-mode-switch-btn--active {
background: #2979ff;
box-shadow: 0 3rpx 8rpx rgba(41, 121, 255, 0.18);
.nav-mode-switch-btn__text {
color: #fff;
}
}
.search-input-wrap {
@ -599,6 +871,8 @@
flex: 1;
min-height: 0;
height: auto;
position: relative;
z-index: 0;
}
.list-wrap {
@ -619,11 +893,11 @@
display: flex;
align-items: center;
position: relative;
padding-right: 20rpx;
padding-right: 92rpx;
}
.item-thumb {
width: 90rpx;
width: 140rpx;
margin-right: 20rpx;
margin-top: 0;
flex-shrink: 0;
@ -636,8 +910,8 @@
}
.goods-image-grid {
width: 90rpx;
height: 90rpx;
width: 140rpx;
height: 140rpx;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
@ -646,8 +920,8 @@
.grid-cell {
position: relative;
width: 44rpx;
height: 44rpx;
width: 68rpx;
height: 68rpx;
border-radius: 8rpx;
overflow: hidden;
background: #f5f7fa;
@ -660,7 +934,7 @@
.image-placeholder {
width: 100%;
height: 90rpx;
height: 140rpx;
display: flex;
align-items: center;
justify-content: center;
@ -668,7 +942,7 @@
}
.image-placeholder-small {
height: 44rpx;
height: 68rpx;
}
.more-mask {
@ -696,14 +970,14 @@
.item-arrow {
position: absolute;
right: 0;
right: -16rpx;
top: 50%;
transform: translateY(-50%);
display: flex;
align-items: center;
justify-content: center;
width: 44rpx;
height: 44rpx;
width: 112rpx;
height: 112rpx;
z-index: 1;
}
@ -715,7 +989,7 @@
}
.goods-name {
font-size: 30rpx;
font-size: 42rpx;
color: #303133;
font-weight: 600;
flex: 1;
@ -734,10 +1008,101 @@
margin-bottom: 0;
}
.storage-section {
margin-top: 10rpx;
padding-top: 10rpx;
border-top: 1rpx solid #eef1f6;
}
.storage-scroll {
width: 100%;
white-space: nowrap;
border-radius: 10rpx;
border: 1rpx solid #dfe7f5;
background: #f8faff;
box-sizing: border-box;
}
.storage-table {
background: #f8faff;
overflow: visible;
border: 0;
display: inline-block;
vertical-align: top;
}
.storage-table--non-batch {
min-width: 680rpx;
}
.storage-table--batch {
min-width: 860rpx;
}
.storage-table__row {
display: flex;
align-items: center;
min-height: 48rpx;
padding: 0 8rpx;
border-bottom: 1rpx solid #e8eef7;
}
.storage-table__row:last-child {
border-bottom: 0;
}
.storage-table__head {
background: #edf4ff;
border-bottom: 1rpx solid #dbe6f7;
position: sticky;
top: 0;
z-index: 8;
box-shadow: 0 2rpx 6rpx rgba(219, 230, 247, 0.65);
}
.storage-col {
font-size: 33rpx;
color: #606266;
line-height: 1.4;
padding: 10rpx 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: center;
border-right: 1rpx solid #e8eef7;
}
.storage-table__row .storage-col:last-child {
border-right: 0;
}
.storage-col--space {
flex: 1.1;
}
.storage-col--batch {
flex: 1;
}
.storage-col--qty {
flex: 0.72;
}
.storage-table--batch .storage-col--qty {
flex: 0.62;
padding-left: 2rpx;
padding-right: 2rpx;
}
.storage-col--highlight {
color: #2979ff;
font-weight: 600;
}
.label {
width: auto;
margin-right: 6rpx;
font-size: 24rpx;
font-size: 35rpx;
color: #909399;
white-space: nowrap;
flex-shrink: 0;
@ -745,7 +1110,7 @@
.value {
flex: 1;
font-size: 24rpx;
font-size: 35rpx;
color: #000;
white-space: nowrap;
overflow: hidden;

View File

@ -10,7 +10,18 @@
</u-form-item>
<u-form-item label="货主" prop="store_id">
<view>{{receivingInfo.store?receivingInfo.store.store_remask:'未设置'}}</view>
<view
v-if="canBindStore"
class="store-bind-trigger"
@click="showStorePicker = true"
>
<text class="store-bind-text">{{ pendingStoreName || '请选择货主绑定' }}</text>
<view class="store-bind-action">
<text class="store-bind-action-text">选择绑定</text>
<u-icon name="arrow-right" size="24rpx" color="#2979ff"></u-icon>
</view>
</view>
<view v-else>{{ receivingInfo.store ? receivingInfo.store.store_remask : '未设置' }}</view>
</u-form-item>
<u-form-item label="来货方式" prop="delivery_method">
@ -90,6 +101,14 @@
</view>
</view>
</u-form>
<inputAndSelect
title="选择货主"
:list="storeList"
:show="showStorePicker"
:value="pendingStoreId"
@change="handleStoreChange"
@close="showStorePicker = false"
></inputAndSelect>
</scroll-view>
</template>
@ -135,12 +154,23 @@
label: '不带托盘'
}
],
rules: {}
rules: {},
showStorePicker: false,
storeList: [],
pendingStoreId: null,
pendingStoreName: '',
bindingStore: false
};
},
computed: {
canBindStore() {
return !!this.receivingInfo && !!this.receivingInfo.id && !this.receivingInfo.store_id;
}
},
mounted() {
console.log("onShow");
this.qrcode(this.receivingInfo.receiving_number);
this.loadStoreList();
},
filters: {
statusFilter(status) {
@ -158,9 +188,90 @@
console.log(newval);
this.qrcode(newval)
}
},
'receivingInfo.store_id': {
immediate: true,
handler(newValue) {
if (newValue) {
this.pendingStoreId = newValue;
this.pendingStoreName = this.receivingInfo.store && this.receivingInfo.store.store_remask ? this.receivingInfo.store.store_remask : '';
} else {
this.pendingStoreId = null;
this.pendingStoreName = '';
}
}
}
},
methods: {
async loadStoreList() {
try {
const res = await this.$http('common.store', {});
this.storeList = Array.isArray(res && res.stores) ? res.stores : [];
} catch (error) {
console.error('加载货主列表失败:', error);
}
},
handleStoreChange(option) {
this.showStorePicker = false;
if (!option || !option.value) {
this.pendingStoreId = null;
this.pendingStoreName = '';
return;
}
uni.showModal({
title: '货主绑定',
content: `是否将当前收货单绑定到货主【${option.label}】?绑定后不可更改。`,
success: async ({ confirm }) => {
if (!confirm) {
return;
}
await this.bindStore(option);
}
});
},
async bindStore(option) {
if (!this.receivingInfo || !this.receivingInfo.id || !option || !option.value || this.bindingStore) {
return;
}
try {
this.bindingStore = true;
uni.showLoading({
title: '绑定中...'
});
const res = await this.$http('storage.receiving.bindStore', {
id: this.receivingInfo.id,
receiving_id: this.receivingInfo.id,
store_id: option.value
});
if (res && res.code === 200) {
this.pendingStoreId = option.value;
this.pendingStoreName = option.label;
uni.showToast({
title: '绑定成功',
icon: 'success'
});
this.$emit('change');
return;
}
throw new Error((res && res.message) || '绑定失败');
} catch (error) {
console.error('绑定货主失败:', error);
uni.showToast({
title: (error && error.message) || '绑定失败',
icon: 'none'
});
} finally {
this.bindingStore = false;
uni.hideLoading();
}
},
normalizeUniScanResult(scanResult) {
if (!scanResult) {
return '';
@ -303,6 +414,33 @@
opacity: 0.85;
}
.store-bind-trigger {
width: 100%;
min-height: 72rpx;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.store-bind-text {
flex: 1;
font-size: 28rpx;
color: #303133;
}
.store-bind-action {
display: flex;
align-items: center;
gap: 8rpx;
flex-shrink: 0;
}
.store-bind-action-text {
font-size: 26rpx;
color: #2979ff;
}
.section {
background-color: #fff;
border-radius: 16rpx;

View File

@ -10,7 +10,10 @@
<!-- 店铺信息 -->
<u-form-item label="货主" @click="showStorePicker = true">
<u-input v-model="storeName" placeholder="请选择货主" />
<view class="store-select-display">
<text :class="['store-select-text', !formData.store_id ? 'store-select-placeholder' : '']">{{ storeName || '请选择货主' }}</text>
<u-icon name="arrow-right" size="24rpx" color="#c0c4cc"></u-icon>
</view>
</u-form-item>
<!-- 来货方式 -->
@ -23,7 +26,12 @@
<!-- 车牌号(货车时显示) -->
<u-form-item v-if="formData.delivery_method === 'truck'" label="车牌号" prop="license_plate">
<u-input v-model="formData.license_plate" placeholder="请输入车牌号" maxlength="20" />
<view class="tracking-input-wrap">
<u-input v-model="formData.license_plate" placeholder="请输入车牌号" maxlength="20" />
<view class="scan-camera-btn" @click="handleLicensePlateCapture">
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
</view>
</view>
</u-form-item>
<!-- 物流单号(非货车时显示) -->
@ -181,10 +189,221 @@
}],
},
submitting: false,
recognizingPlate: false,
};
},
methods: {
getPlatformInfo() {
const systemInfo = typeof uni.getSystemInfoSync === 'function' ? uni.getSystemInfoSync() : {};
return {
platform: systemInfo.platform || 'unknown',
uniPlatform: systemInfo.uniPlatform || 'unknown',
system: systemInfo.system || '',
model: systemInfo.model || '',
appVersion: systemInfo.appVersion || ''
};
},
arrayBufferToBase64(buffer) {
if (uni.arrayBufferToBase64) {
return uni.arrayBufferToBase64(buffer);
}
let binary = '';
const bytes = new Uint8Array(buffer);
const length = bytes.byteLength;
for (let i = 0; i < length; i += 1) {
binary += String.fromCharCode(bytes[i]);
}
if (typeof btoa === 'function') {
return btoa(binary);
}
throw new Error('当前环境不支持 ArrayBuffer 转 Base64');
},
readFileBase64ByPlus(filePath) {
return new Promise((resolve, reject) => {
if (typeof plus === 'undefined' || !plus.io || !plus.io.resolveLocalFileSystemURL) {
reject(new Error('PLUS 文件系统不可用'));
return;
}
plus.io.resolveLocalFileSystemURL(filePath, (entry) => {
entry.file((file) => {
const reader = new plus.io.FileReader();
reader.onloadend = (event) => {
const result = String(event?.target?.result || event?.result || '');
resolve(result.replace(/^data:.*?;base64,/, ''));
};
reader.onerror = (error) => reject(error);
reader.readAsDataURL(file);
}, reject);
}, reject);
});
},
readFileBase64ByRequest(filePath) {
return new Promise((resolve, reject) => {
uni.request({
url: filePath,
method: 'GET',
responseType: 'arraybuffer',
success: (res) => {
try {
resolve(this.arrayBufferToBase64(res.data));
} catch (error) {
reject(error);
}
},
fail: (error) => reject(error)
});
});
},
async getImageBase64(filePath) {
const platformInfo = this.getPlatformInfo();
console.log('[ReceivingCreate] 图片转Base64平台信息:', platformInfo);
console.log('[ReceivingCreate] 图片转Base64文件路径:', filePath);
const tryByFileSystemManager = () => new Promise((resolve, reject) => {
try {
const fileSystemManager = uni.getFileSystemManager && uni.getFileSystemManager();
if (!fileSystemManager || typeof fileSystemManager.readFile !== 'function') {
reject(new Error('getFileSystemManager.readFile 不可用'));
return;
}
console.log('[ReceivingCreate] 图片转Base64读取分支: getFileSystemManager.readFile');
fileSystemManager.readFile({
filePath,
encoding: 'base64',
success: ({ data }) => resolve(String(data || '')),
fail: (error) => reject(error)
});
} catch (error) {
reject(error);
}
});
return new Promise((resolve, reject) => {
if (!filePath) {
reject(new Error('图片路径无效'));
return;
}
tryByFileSystemManager()
.then(resolve)
.catch((fileSystemError) => {
console.warn('[ReceivingCreate] getFileSystemManager 分支失败:', fileSystemError);
console.log('[ReceivingCreate] 图片转Base64读取分支: plus.io.FileReader');
this.readFileBase64ByPlus(filePath)
.then(resolve)
.catch((plusError) => {
console.warn('[ReceivingCreate] plus.io.FileReader 分支失败:', plusError);
console.log('[ReceivingCreate] 图片转Base64读取分支: uni.request(arraybuffer)');
this.readFileBase64ByRequest(filePath)
.then(resolve)
.catch((requestError) => {
console.error('[ReceivingCreate] uni.request(arraybuffer) 分支失败:', requestError);
reject(requestError);
});
});
});
});
},
extractLicensePlate(response) {
if (!response) {
return '';
}
const directFields = [
response.license_plate,
response.licensePlate,
response.plate_number,
response.plateNo,
response.plate_number_text,
response.number
];
const directMatch = directFields.find(value => typeof value === 'string' && value.trim());
if (directMatch) {
return directMatch.trim();
}
const data = response.data;
if (data && typeof data === 'object') {
return this.extractLicensePlate(data);
}
if (Array.isArray(data) && data.length) {
return this.extractLicensePlate(data[0]);
}
return '';
},
async handleLicensePlateCapture() {
if (this.recognizingPlate) {
return;
}
try {
const chooseResult = await new Promise((resolve, reject) => {
uni.chooseImage({
count: 1,
sourceType: ['camera'],
sizeType: ['compressed'],
success: resolve,
fail: reject
});
});
const filePath = chooseResult?.tempFilePaths?.[0] || chooseResult?.tempFiles?.[0]?.path;
if (!filePath) {
throw new Error('未获取到拍照文件');
}
this.recognizingPlate = true;
uni.showLoading({ title: '识别车牌中', mask: true });
const imageBase64 = await this.getImageBase64(filePath);
if (!imageBase64) {
throw new Error('图片转换失败');
}
const recognizeParams = {
image_base64: imageBase64
};
console.log('[ReceivingCreate] 车牌识别请求参数:', {
...recognizeParams,
image_base64: `${imageBase64.slice(0, 80)}...`,
image_base64_length: imageBase64.length
});
const result = await this.$http('common.recognizeLicensePlate', recognizeParams, '', false);
console.log('[ReceivingCreate] 车牌识别接口返回:', result);
const licensePlate = this.extractLicensePlate(result);
if (!licensePlate) {
throw new Error((result && result.message) || '未识别到车牌号');
}
this.formData.license_plate = licensePlate;
uni.showToast({
title: '识别成功',
icon: 'success'
});
} catch (error) {
const errMsg = String(error?.errMsg || error?.message || error || '').toLowerCase();
if (errMsg.includes('cancel')) {
return;
}
uni.showToast({
title: (error && error.message) || '车牌识别失败',
icon: 'none'
});
} finally {
this.recognizingPlate = false;
uni.hideLoading();
}
},
normalizeUniScanResult(scanResult) {
if (!scanResult) {
return '';
@ -437,4 +656,24 @@
border-top: 1px solid rgba(0, 0, 0, .3);
background-color: #FFF;
}
.store-select-display {
width: 100%;
min-height: 72rpx;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.store-select-text {
flex: 1;
font-size: 28rpx;
color: #303133;
line-height: 1.4;
}
.store-select-placeholder {
color: #c0c4cc;
}
</style>