588 lines
15 KiB
Vue
588 lines
15 KiB
Vue
<template>
|
||
<view class="random-storage-list-page">
|
||
<view class="normar_container">
|
||
<page-nav title="随机入库" :showBack="true" @back="handleBack"></page-nav>
|
||
|
||
<view class="search-filter">
|
||
<view class="search-row">
|
||
<u-search
|
||
v-model="searchKeyword"
|
||
placeholder="扫描/输入入库单号、采购单号、供应商..."
|
||
shape="round"
|
||
:show-action="false"
|
||
:clearabled="true"
|
||
@search="handleSearch"
|
||
@clear="handleClearSearch"
|
||
></u-search>
|
||
<view class="search-scan-btn" @click="handleScan">
|
||
<u-icon name="scan" size="34rpx" color="#2979ff"></u-icon>
|
||
</view>
|
||
</view>
|
||
<view class="search-hint">
|
||
<text class="search-hint__text">默认仅显示待审核入库单(PENDING)</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="summary-bar">
|
||
<text class="summary-bar__text">共 {{ totalItems }} 单</text>
|
||
<text class="summary-bar__page">第 {{ currentPage }} / {{ totalPages || 1 }} 页</text>
|
||
<text v-if="searchKeyword" class="summary-bar__keyword">当前关键词:{{ searchKeyword }}</text>
|
||
</view>
|
||
|
||
<scroll-view class="list-content" scroll-y>
|
||
<view v-if="!loading && entryList.length === 0" class="empty-state">
|
||
<u-icon name="list-dot" size="100" color="#ccc"></u-icon>
|
||
<text class="empty-text">暂无待入库单</text>
|
||
<text class="empty-hint">可通过上方搜索框或扫码查找入库单</text>
|
||
</view>
|
||
|
||
<view class="entry-items">
|
||
<view
|
||
v-for="item in entryList"
|
||
:key="item.id || item.entry_order_code"
|
||
class="entry-card"
|
||
@click="openShelfPage(item)"
|
||
>
|
||
<view class="entry-card__header">
|
||
<text class="entry-card__code">{{ item.entry_order_code || '--' }}</text>
|
||
<u-tag :text="getStatusText(item.order_status)" :type="getStatusType(item.order_status)" size="mini"></u-tag>
|
||
</view>
|
||
<view class="entry-card__meta">
|
||
<text class="entry-card__meta-text">类型:{{ item.order_type || '--' }}</text>
|
||
<text class="entry-card__meta-text">行数:{{ item.total_order_lines || 0 }}</text>
|
||
</view>
|
||
|
||
<view class="entry-card__body">
|
||
<view class="entry-card__row">
|
||
<text class="entry-card__label">采购单号</text>
|
||
<text class="entry-card__value">{{ item.purchase_order_code || '--' }}</text>
|
||
</view>
|
||
<view class="entry-card__row">
|
||
<text class="entry-card__label">供应商</text>
|
||
<text class="entry-card__value">{{ item.supplier_name || '--' }}</text>
|
||
</view>
|
||
<view class="entry-card__row">
|
||
<text class="entry-card__label">货主</text>
|
||
<text class="entry-card__value">{{ item.store_name || '--' }}</text>
|
||
</view>
|
||
<view class="entry-card__row">
|
||
<text class="entry-card__label">仓库</text>
|
||
<text class="entry-card__value">{{ item.warehouse_name || '--' }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="entry-card__footer">
|
||
<view class="entry-card__badges">
|
||
<u-tag
|
||
:text="item.hasReceiving ? '已绑定收货单' : '未绑定收货单'"
|
||
:type="item.hasReceiving ? 'success' : 'info'"
|
||
:plain="true"
|
||
size="mini"
|
||
></u-tag>
|
||
<u-tag
|
||
v-for="(receivingNo, receivingIndex) in getReceivingNumbers(item)"
|
||
:key="`${item.id || item.entry_order_code}-receiving-${receivingIndex}`"
|
||
:text="`收货单 ${receivingNo}`"
|
||
type="warning"
|
||
:plain="true"
|
||
size="mini"
|
||
></u-tag>
|
||
</view>
|
||
<text class="entry-card__time">创建:{{ formatDateTime(item.created_at) }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="safe-area-bottom"></view>
|
||
</scroll-view>
|
||
|
||
<pagination
|
||
:pageNum.sync="currentPage"
|
||
:pageSize="pageSize"
|
||
:total="totalItems"
|
||
:showTotal="true"
|
||
:prevText="'上一页'"
|
||
:nextText="'下一页'"
|
||
:showFirstLast="true"
|
||
:firstText="'首页'"
|
||
:lastText="'末页'"
|
||
@change="handlePageChange"
|
||
/>
|
||
</view>
|
||
|
||
<u-loading-page :loading="loading" bg-color="rgba(255,255,255,0.9)"></u-loading-page>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import voice from '@/core/utils/voice';
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
loading: false,
|
||
searchKeyword: '',
|
||
entryList: [],
|
||
pageSize: 20,
|
||
currentPage: 1,
|
||
totalPages: 0,
|
||
totalItems: 0,
|
||
refreshMarker: 0
|
||
};
|
||
},
|
||
onLoad() {
|
||
this.safeDispatchBroadcast('setCallbacks', {
|
||
onResult: this.handleBroadcastResult
|
||
});
|
||
this.safeDispatchBroadcast('start');
|
||
this.consumeRefreshFlag();
|
||
this.loadEntryList();
|
||
},
|
||
onShow() {
|
||
this.safeDispatchBroadcast('setCallbacks', {
|
||
onResult: this.handleBroadcastResult
|
||
});
|
||
this.safeDispatchBroadcast('resume');
|
||
this.consumeRefreshFlag();
|
||
},
|
||
onHide() {
|
||
this.safeDispatchBroadcast('pause');
|
||
},
|
||
onUnload() {
|
||
this.safeDispatchBroadcast('stop');
|
||
},
|
||
methods: {
|
||
speakVoice(text) {
|
||
voice.speak(text, { minInterval: 800 });
|
||
},
|
||
safeDispatchBroadcast(action, payload) {
|
||
try {
|
||
const task = this.$store.dispatch(`broadcast/${action}`, payload);
|
||
if (task && typeof task.catch === 'function') {
|
||
task.catch(error => {
|
||
console.warn(`[RandomStorageList] broadcast/${action} 调用失败:`, error);
|
||
});
|
||
}
|
||
} catch (error) {
|
||
console.warn(`[RandomStorageList] broadcast/${action} 调用异常:`, error);
|
||
}
|
||
},
|
||
consumeRefreshFlag() {
|
||
const marker = Number(uni.getStorageSync('random_storage_need_refresh') || 0);
|
||
if (marker && marker !== this.refreshMarker) {
|
||
this.refreshMarker = marker;
|
||
uni.removeStorageSync('random_storage_need_refresh');
|
||
this.loadEntryList();
|
||
}
|
||
},
|
||
handleBack() {
|
||
uni.navigateBack({ delta: 1 });
|
||
},
|
||
normalizeKeyword(value) {
|
||
return String(value || '').replace(/\s+/g, '');
|
||
},
|
||
normalizeScanResult(scanResult) {
|
||
if (!scanResult) return '';
|
||
if (typeof scanResult === 'string') return this.normalizeKeyword(scanResult);
|
||
if (typeof scanResult.result === 'string') return this.normalizeKeyword(scanResult.result);
|
||
if (Array.isArray(scanResult.result)) {
|
||
const first = scanResult.result.find(item => item);
|
||
if (typeof first === 'string') return this.normalizeKeyword(first);
|
||
if (first && typeof first.data === 'string') return this.normalizeKeyword(first.data);
|
||
}
|
||
if (typeof scanResult.data === 'string') return this.normalizeKeyword(scanResult.data);
|
||
return '';
|
||
},
|
||
handleBroadcastResult(result) {
|
||
const scanText = this.normalizeScanResult(result);
|
||
if (!scanText) return;
|
||
this.searchKeyword = scanText;
|
||
this.handleSearch();
|
||
},
|
||
handleSearch() {
|
||
this.currentPage = 1;
|
||
this.loadEntryList();
|
||
},
|
||
handleClearSearch() {
|
||
this.searchKeyword = '';
|
||
this.currentPage = 1;
|
||
this.loadEntryList();
|
||
},
|
||
handleScan() {
|
||
uni.scanCode({
|
||
onlyFromCamera: true,
|
||
scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
|
||
success: (res) => {
|
||
const scanText = this.normalizeScanResult(res);
|
||
if (!scanText) {
|
||
uni.showToast({ title: '未识别到有效条码', icon: 'none' });
|
||
return;
|
||
}
|
||
this.searchKeyword = scanText;
|
||
this.handleSearch();
|
||
},
|
||
fail: (error) => {
|
||
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||
if (errMsg.includes('cancel')) return;
|
||
uni.showToast({ title: '扫码失败,请重试', icon: 'none' });
|
||
}
|
||
});
|
||
},
|
||
buildWhere() {
|
||
const where = {
|
||
order_status: {
|
||
field: 'order_status',
|
||
operator: 'eq',
|
||
type: 'string',
|
||
value: 'PENDING'
|
||
}
|
||
};
|
||
const keyword = this.normalizeKeyword(this.searchKeyword);
|
||
if (keyword) {
|
||
where.quickWhere = {
|
||
value: keyword
|
||
};
|
||
}
|
||
return where;
|
||
},
|
||
async loadEntryList() {
|
||
if (this.loading) return;
|
||
this.loading = true;
|
||
try {
|
||
const res = await this.$http('storage.entry.list', {
|
||
pagination: {
|
||
page: this.currentPage,
|
||
pageSize: this.pageSize
|
||
},
|
||
where: this.buildWhere()
|
||
});
|
||
const isSuccess = String(res?.code || '') === '200' || String(res?.flag || '').toLowerCase() === 'success';
|
||
if (!isSuccess) {
|
||
this.entryList = [];
|
||
this.totalPages = 0;
|
||
this.totalItems = 0;
|
||
uni.showToast({ title: res?.message || '查询入库单失败', icon: 'none' });
|
||
return;
|
||
}
|
||
const data = res?.data?.data || res?.data || {};
|
||
const list = Array.isArray(data.list) ? data.list : [];
|
||
const pagination = data.pagination || {};
|
||
const summary = data.summary || {};
|
||
this.entryList = list;
|
||
this.totalItems = Number(pagination.total || summary.total || list.length || 0);
|
||
this.totalPages = Number(pagination.totalPages || Math.ceil(this.totalItems / this.pageSize) || 0);
|
||
this.currentPage = Number(pagination.page || this.currentPage || 1);
|
||
// 待入库列表为空且带关键词时,去掉 order_status 条件再查一次,仅用于判断是否已入库,不参与列表展示
|
||
if (list.length === 0 && this.normalizeKeyword(this.searchKeyword)) {
|
||
this.checkAlreadyInbound(this.searchKeyword);
|
||
}
|
||
} catch (error) {
|
||
const msg = String(error?.message || error?.msg || '查询入库单失败');
|
||
uni.showToast({ title: msg, icon: 'none' });
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
},
|
||
async checkAlreadyInbound(keyword) {
|
||
const normalizedKeyword = this.normalizeKeyword(keyword);
|
||
if (!normalizedKeyword) return;
|
||
try {
|
||
// 不带 order_status 条件,仅按关键词查询,用于判断该单是否已不在待入库列表(如已入库)
|
||
const res = await this.$http('storage.entry.list', {
|
||
pagination: {
|
||
page: 1,
|
||
pageSize: this.pageSize
|
||
},
|
||
where: {
|
||
quickWhere: {
|
||
value: normalizedKeyword
|
||
}
|
||
}
|
||
});
|
||
const isSuccess = String(res?.code || '') === '200' || String(res?.flag || '').toLowerCase() === 'success';
|
||
if (!isSuccess) return;
|
||
const data = res?.data?.data || res?.data || {};
|
||
const list = Array.isArray(data.list) ? data.list : [];
|
||
// 关键词与返回列表的入库单号对比,命中则提示已入库(二次查询结果不用于展示)
|
||
const matched = list.some(item =>
|
||
this.normalizeKeyword(item?.entry_order_code) === normalizedKeyword
|
||
);
|
||
if (matched) {
|
||
uni.showToast({ title: '已入库', icon: 'none' });
|
||
this.speakVoice('已入库');
|
||
}
|
||
} catch (error) {
|
||
// 二次查询仅用于提示,异常时静默忽略,不影响主流程
|
||
console.warn('[RandomStorageList] checkAlreadyInbound 查询异常:', error);
|
||
}
|
||
},
|
||
handlePageChange(pageNum) {
|
||
const nextPage = Number(pageNum?.pageNum || pageNum?.page || pageNum);
|
||
this.currentPage = Number.isFinite(nextPage) && nextPage > 0 ? nextPage : 1;
|
||
this.loadEntryList();
|
||
},
|
||
getReceivingNumbers(item) {
|
||
const bindings = Array.isArray(item?.receivingBindings) ? item.receivingBindings : [];
|
||
return bindings
|
||
.map(binding => binding?.receiving?.receiving_number || binding?.receiving_id)
|
||
.filter(Boolean)
|
||
.slice(0, 2);
|
||
},
|
||
openShelfPage(item) {
|
||
const entryOrderCode = String(item?.entry_order_code || '').trim();
|
||
if (!entryOrderCode) {
|
||
uni.showToast({ title: '缺少入库单号', icon: 'none' });
|
||
return;
|
||
}
|
||
uni.navigateTo({
|
||
url: `/pages/work/storage/random-storage-shelf?entryOrderCode=${encodeURIComponent(entryOrderCode)}`
|
||
});
|
||
},
|
||
getStatusText(status) {
|
||
switch (String(status || '').toUpperCase()) {
|
||
case 'CREATING':
|
||
return '创建中';
|
||
case 'CREATED':
|
||
return '待审核';
|
||
case 'PENDING':
|
||
return '已审核';
|
||
case 'COMPLETED':
|
||
return '已完成';
|
||
case 'CANCELLED':
|
||
return '已取消';
|
||
default:
|
||
return status || '--';
|
||
}
|
||
},
|
||
getStatusType(status) {
|
||
switch (String(status || '').toUpperCase()) {
|
||
case 'CREATED':
|
||
return 'warning';
|
||
case 'PENDING':
|
||
return 'primary';
|
||
case 'COMPLETED':
|
||
return 'success';
|
||
case 'CANCELLED':
|
||
return 'error';
|
||
default:
|
||
return 'info';
|
||
}
|
||
},
|
||
formatDateTime(value) {
|
||
if (!value) return '--';
|
||
const date = new Date(value);
|
||
if (Number.isNaN(date.getTime())) return String(value);
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||
const day = String(date.getDate()).padStart(2, '0');
|
||
const hours = String(date.getHours()).padStart(2, '0');
|
||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.random-storage-list-page {
|
||
height: 100vh;
|
||
background: #f8f9fa;
|
||
}
|
||
|
||
.normar_container {
|
||
height: 100%;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.search-filter {
|
||
background: #ffffff;
|
||
padding: 20rpx 24rpx 12rpx;
|
||
border-bottom: 1rpx solid #f0f0f0;
|
||
}
|
||
|
||
.search-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10rpx;
|
||
}
|
||
|
||
.search-row ::v-deep .u-search {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.search-scan-btn {
|
||
flex-shrink: 0;
|
||
width: 56rpx;
|
||
height: 56rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: #f5f5f5;
|
||
border-radius: 50%;
|
||
}
|
||
|
||
.search-scan-btn:active {
|
||
opacity: 0.7;
|
||
}
|
||
|
||
.search-hint {
|
||
margin-top: 12rpx;
|
||
}
|
||
|
||
.search-hint__text {
|
||
font-size: 24rpx;
|
||
color: #909399;
|
||
}
|
||
|
||
.summary-bar {
|
||
padding: 16rpx 24rpx 12rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
font-size: 24rpx;
|
||
color: #606266;
|
||
}
|
||
|
||
.summary-bar__page {
|
||
color: #2979ff;
|
||
}
|
||
|
||
.summary-bar__keyword {
|
||
color: #2979ff;
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.list-content {
|
||
flex: 1;
|
||
height: 0;
|
||
min-height: 0;
|
||
padding: 0 24rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.empty-state {
|
||
min-height: 50vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 14rpx;
|
||
color: #909399;
|
||
}
|
||
|
||
.empty-text {
|
||
font-size: 34rpx;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
|
||
.empty-hint {
|
||
font-size: 26rpx;
|
||
color: #909399;
|
||
text-align: center;
|
||
}
|
||
|
||
.entry-items {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 20rpx;
|
||
padding-bottom: 24rpx;
|
||
}
|
||
|
||
.entry-card {
|
||
background: #ffffff;
|
||
border-radius: 18rpx;
|
||
padding: 22rpx;
|
||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
|
||
}
|
||
|
||
.entry-card:active {
|
||
opacity: 0.92;
|
||
}
|
||
|
||
.entry-card__header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.entry-card__code {
|
||
font-size: 32rpx;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
flex: 1;
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.entry-card__body {
|
||
margin-top: 18rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.entry-card__meta {
|
||
margin-top: 10rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 20rpx;
|
||
}
|
||
|
||
.entry-card__meta-text {
|
||
font-size: 24rpx;
|
||
color: #909399;
|
||
}
|
||
|
||
.entry-card__row {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
gap: 12rpx;
|
||
font-size: 26rpx;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
.entry-card__label {
|
||
width: 120rpx;
|
||
flex-shrink: 0;
|
||
color: #909399;
|
||
}
|
||
|
||
.entry-card__value {
|
||
flex: 1;
|
||
min-width: 0;
|
||
color: #303133;
|
||
word-break: break-all;
|
||
}
|
||
|
||
.entry-card__footer {
|
||
margin-top: 18rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.entry-card__badges {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 10rpx;
|
||
}
|
||
|
||
.entry-card__time {
|
||
font-size: 24rpx;
|
||
color: #909399;
|
||
}
|
||
|
||
.safe-area-bottom {
|
||
height: calc(20rpx + env(safe-area-inset-bottom));
|
||
}
|
||
</style>
|