优化、修复收货功能
This commit is contained in:
parent
b3d545b1c8
commit
03c5d46067
@ -51,7 +51,7 @@
|
||||
:class="{ 'active': selectedDetail && selectedDetail.id === item.id }"
|
||||
@click="handleSelectDetail(item)">
|
||||
<view class="item-index">
|
||||
{{ (pageIndex * itemsPerPage) + index + 1 }}
|
||||
{{ getDetailDisplayIndex(item, pageIndex, index) }}
|
||||
</view>
|
||||
<view class="item-content">
|
||||
<text class="item-name">{{ truncateText(item.product_name,5) }}</text>
|
||||
@ -131,6 +131,19 @@
|
||||
}
|
||||
|
||||
return pages;
|
||||
},
|
||||
detailDisplayIndexMap() {
|
||||
const map = {};
|
||||
const orderedIds = this.details
|
||||
.map(item => Number(item && item.id))
|
||||
.filter(id => Number.isFinite(id))
|
||||
.sort((left, right) => left - right);
|
||||
|
||||
orderedIds.forEach((id, index) => {
|
||||
map[id] = index + 1;
|
||||
});
|
||||
|
||||
return map;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@ -245,6 +258,14 @@
|
||||
handleSwiperChange(e) {
|
||||
this.currentPage = e.detail.current + 1;
|
||||
},
|
||||
getDetailDisplayIndex(item, pageIndex, index) {
|
||||
const detailId = Number(item && item.id);
|
||||
if (Number.isFinite(detailId) && this.detailDisplayIndexMap[detailId]) {
|
||||
return this.detailDisplayIndexMap[detailId];
|
||||
}
|
||||
|
||||
return (pageIndex * this.itemsPerPage) + index + 1;
|
||||
},
|
||||
|
||||
// === 工具方法 ===
|
||||
|
||||
|
||||
@ -46,6 +46,31 @@
|
||||
</u-form-item>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">来货照片</view>
|
||||
<view class="incoming-toolbar">
|
||||
<view class="incoming-picker-trigger" @click="handleChooseIncomingImages">
|
||||
<view class="incoming-picker-icon">+</view>
|
||||
<view class="incoming-picker-texts">
|
||||
<text class="incoming-picker-title">选择来货照片</text>
|
||||
<text class="incoming-picker-desc">创建成功后自动上传并关联</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="pendingIncomingImages.length > 0" class="incoming-list">
|
||||
<view
|
||||
v-for="(item, index) in pendingIncomingImages"
|
||||
:key="`${item.url}-${index}`"
|
||||
class="incoming-item"
|
||||
>
|
||||
<image class="incoming-image" :src="item.url" mode="aspectFill"></image>
|
||||
<view class="incoming-delete" @click="removeIncomingImage(index)">
|
||||
<u-icon name="close" size="18" color="#ffffff"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 装卸信息 -->
|
||||
<view class="section">
|
||||
<view class="section-title">装卸信息</view>
|
||||
@ -81,6 +106,14 @@
|
||||
<u-input v-model="formData.remark" type="textarea" placeholder="请输入备注信息" height="120" />
|
||||
</u-form-item>
|
||||
</view>
|
||||
|
||||
<uploadImgCos
|
||||
ref="incomingUploadRef"
|
||||
business_type="receiving"
|
||||
:business_id="incomingBusinessId"
|
||||
:value="incomingUploadValue"
|
||||
style="display: none;"
|
||||
></uploadImgCos>
|
||||
</u-form>
|
||||
</scroll-view>
|
||||
<view class="submit-area">
|
||||
@ -104,6 +137,9 @@
|
||||
data() {
|
||||
return {
|
||||
storeName: "不设置",
|
||||
incomingBusinessId: 0,
|
||||
incomingUploadValue: [],
|
||||
pendingIncomingImages: [],
|
||||
formData: {
|
||||
store_id: null,
|
||||
delivery_method: 'truck',
|
||||
@ -568,6 +604,87 @@
|
||||
console.error('加载货主失败:', error);
|
||||
}
|
||||
},
|
||||
resolveIncomingFileType(filePath) {
|
||||
const path = String(filePath || '').toLowerCase();
|
||||
if (path.endsWith('.png')) {
|
||||
return 'image/png';
|
||||
}
|
||||
if (path.endsWith('.webp')) {
|
||||
return 'image/webp';
|
||||
}
|
||||
return 'image/jpeg';
|
||||
},
|
||||
async handleChooseIncomingImages() {
|
||||
const maxCount = 6;
|
||||
const remainCount = maxCount - this.pendingIncomingImages.length;
|
||||
if (remainCount <= 0) {
|
||||
this.showToastMessage('最多上传6张来货照片');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const chooseResult = await new Promise((resolve, reject) => {
|
||||
uni.chooseImage({
|
||||
count: remainCount,
|
||||
sourceType: ['camera', 'album'],
|
||||
sizeType: ['compressed'],
|
||||
success: resolve,
|
||||
fail: reject
|
||||
});
|
||||
});
|
||||
|
||||
const tempFiles = Array.isArray(chooseResult && chooseResult.tempFiles) ? chooseResult.tempFiles : [];
|
||||
const tempFilePaths = Array.isArray(chooseResult && chooseResult.tempFilePaths) ? chooseResult.tempFilePaths : [];
|
||||
const appendedFiles = tempFilePaths.map((path, index) => ({
|
||||
url: path,
|
||||
name: String(path || '').split(/[\\/]/).pop() || `incoming_${Date.now()}_${index}.jpg`,
|
||||
type: tempFiles[index] && tempFiles[index].type ? tempFiles[index].type : this.resolveIncomingFileType(path),
|
||||
size: Number(tempFiles[index] && tempFiles[index].size ? tempFiles[index].size : 0)
|
||||
}));
|
||||
|
||||
this.pendingIncomingImages = [...this.pendingIncomingImages, ...appendedFiles].slice(0, maxCount);
|
||||
} catch (error) {
|
||||
const errMsg = String(error && (error.errMsg || error.message) || '').toLowerCase();
|
||||
if (errMsg.includes('cancel')) {
|
||||
return;
|
||||
}
|
||||
this.showToastMessage('选择图片失败,请重试');
|
||||
}
|
||||
},
|
||||
removeIncomingImage(index) {
|
||||
if (index < 0 || index >= this.pendingIncomingImages.length) {
|
||||
return;
|
||||
}
|
||||
this.pendingIncomingImages.splice(index, 1);
|
||||
},
|
||||
async uploadPendingIncomingImages(receivingId) {
|
||||
if (!receivingId || this.pendingIncomingImages.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.incomingBusinessId = Number(receivingId) || 0;
|
||||
this.incomingUploadValue = [];
|
||||
await this.$nextTick();
|
||||
|
||||
const uploadRef = this.$refs.incomingUploadRef;
|
||||
if (!uploadRef || typeof uploadRef.handleAfterRead !== 'function') {
|
||||
throw new Error('来货照片上传组件不可用');
|
||||
}
|
||||
|
||||
await uploadRef.handleAfterRead({
|
||||
file: this.pendingIncomingImages.map(item => ({
|
||||
url: item.url,
|
||||
name: item.name,
|
||||
type: item.type,
|
||||
size: item.size
|
||||
}))
|
||||
});
|
||||
|
||||
const successFiles = typeof uploadRef.getSuccessFiles === 'function' ? uploadRef.getSuccessFiles() : [];
|
||||
if (successFiles.length !== this.pendingIncomingImages.length) {
|
||||
throw new Error('来货照片上传失败');
|
||||
}
|
||||
},
|
||||
async scan(data) {
|
||||
// 解析广播扫描数据
|
||||
// 携带REC标识头数据,自动填充录像设备
|
||||
@ -619,6 +736,9 @@
|
||||
|
||||
const result = await this.$http("storage.receiving.create",submitData);
|
||||
if(result.code==200){
|
||||
if (this.pendingIncomingImages.length > 0) {
|
||||
await this.uploadPendingIncomingImages(result.id);
|
||||
}
|
||||
this.showToastMessage('创建成功', 'success');
|
||||
}else{
|
||||
throw new Error("创建失败"+result.message);
|
||||
@ -626,7 +746,7 @@
|
||||
}
|
||||
setTimeout(() => {
|
||||
uni.navigateTo({
|
||||
url: `./receivingDetail?id=${result.id}`
|
||||
url: `./receivingDetail?id=${result.id}&tab=content`
|
||||
});
|
||||
}, 1500);
|
||||
|
||||
@ -647,6 +767,9 @@
|
||||
this.$refs.formRef.resetFields();
|
||||
this.storeName = "不设置";
|
||||
this.formData.store_id = null;
|
||||
this.incomingBusinessId = 0;
|
||||
this.incomingUploadValue = [];
|
||||
this.pendingIncomingImages = [];
|
||||
this.showToastMessage('已重置表单');
|
||||
} else {
|
||||
this.showToastMessage('已取消', 'none', {
|
||||
@ -775,4 +898,91 @@
|
||||
.store-select-placeholder {
|
||||
color: #c0c4cc;
|
||||
}
|
||||
|
||||
.incoming-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.incoming-picker-trigger {
|
||||
width: 100%;
|
||||
min-height: 104rpx;
|
||||
padding: 20rpx 24rpx;
|
||||
border: 2rpx dashed #d7e8ff;
|
||||
border-radius: 16rpx;
|
||||
background: linear-gradient(180deg, #f8fbff 0%, #f3f8ff 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.incoming-picker-icon {
|
||||
width: 52rpx;
|
||||
height: 52rpx;
|
||||
border-radius: 26rpx;
|
||||
background: #2979ff;
|
||||
color: #ffffff;
|
||||
font-size: 36rpx;
|
||||
line-height: 52rpx;
|
||||
text-align: center;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 8rpx 20rpx rgba(41, 121, 255, 0.16);
|
||||
}
|
||||
|
||||
.incoming-picker-texts {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6rpx;
|
||||
}
|
||||
|
||||
.incoming-picker-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.incoming-picker-desc {
|
||||
font-size: 24rpx;
|
||||
color: #909399;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.incoming-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.incoming-item {
|
||||
position: relative;
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
border-radius: 12rpx;
|
||||
overflow: hidden;
|
||||
background: #f5f7fa;
|
||||
border: 1px solid #ebeef5;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.incoming-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.incoming-delete {
|
||||
position: absolute;
|
||||
top: 8rpx;
|
||||
right: 8rpx;
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
border-radius: 16rpx;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
@ -77,6 +77,7 @@
|
||||
return {
|
||||
receivingId: null,
|
||||
currentTab: 0,
|
||||
hasInitializedDefaultTab: false,
|
||||
receivingListHeaderTop: 0,
|
||||
receivingListHeaderGap: 0,
|
||||
qrcodeUrl: null,
|
||||
@ -355,6 +356,10 @@
|
||||
creator_name: res.data.creator_snapshot ?
|
||||
JSON.parse(res.data.creator_snapshot).name : ''
|
||||
};
|
||||
if (!this.hasInitializedDefaultTab) {
|
||||
this.currentTab = this.receivingInfo.status === 'receiving' ? 1 : 0;
|
||||
this.hasInitializedDefaultTab = true;
|
||||
}
|
||||
this.details = res.data.details || [];
|
||||
|
||||
// 默认选中第一个明细
|
||||
@ -539,24 +544,25 @@
|
||||
},
|
||||
// 处理添加明细事件 - 从detail-container组件接收
|
||||
async handleAddDetail() {
|
||||
this.speakMessage('添加成功');
|
||||
try {
|
||||
const result = await this.$http('storage.receiving.addDetail', {
|
||||
receiving_id: this.receivingId
|
||||
});
|
||||
|
||||
if (result.code === 200) {
|
||||
this.speakMessage('添加成功');
|
||||
this.showToastMessage('添加成功', 'success', {
|
||||
speak: false
|
||||
});
|
||||
const selectId = result.data && result.data.selectId;
|
||||
await this.loadReceivingInfo();
|
||||
|
||||
if (result.data.selectId) {
|
||||
const newDetail = this.details.find(item => item.id === result.data.selectId);
|
||||
if (selectId) {
|
||||
const newDetail = this.details.find(item => item.id === selectId);
|
||||
if (newDetail) {
|
||||
this.selectedDetail = newDetail;
|
||||
}
|
||||
}
|
||||
this.initData();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('添加明细失败:', error);
|
||||
@ -934,18 +940,68 @@
|
||||
};
|
||||
await this.handleSelectDetailChange(updateData);
|
||||
},
|
||||
async tryGetStock(data) {
|
||||
if(!this.selectedDetail){
|
||||
async ensureSelectedDetailForScan() {
|
||||
if (this.selectedDetail && this.selectedDetail.id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
const addResult = await this.$http('storage.receiving.addDetail', {
|
||||
receiving_id: this.receivingId
|
||||
});
|
||||
|
||||
if (addResult.code !== 200) {
|
||||
uni.showToast({
|
||||
title: addResult.message || '新增商品明细失败',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
const selectId = addResult.data && addResult.data.selectId;
|
||||
await this.loadReceivingInfo();
|
||||
|
||||
if (selectId) {
|
||||
const detail = this.details.find(item => item.id === selectId);
|
||||
if (detail) {
|
||||
this.selectedDetail = detail;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.selectedDetail && this.details.length > 0) {
|
||||
this.selectedDetail = this.details[this.details.length - 1];
|
||||
}
|
||||
|
||||
return !!(this.selectedDetail && this.selectedDetail.id);
|
||||
} catch (error) {
|
||||
console.error('扫码自动新增明细失败:', error);
|
||||
uni.showToast({
|
||||
title: '新增商品明细失败',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
},
|
||||
async tryGetStock(data) {
|
||||
const keyword = String(data || '').trim();
|
||||
if (!keyword) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.selectedDetail) {
|
||||
const ready = await this.ensureSelectedDetailForScan();
|
||||
if (!ready) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const stocks = await this.$http("stock.warehouse.search", {
|
||||
keyword: data,
|
||||
keyword,
|
||||
store_id: this.receivingInfo.store_id
|
||||
});
|
||||
|
||||
if (stocks.code == 200) {
|
||||
if (stocks.total == 1) {
|
||||
const updateData = this.buildStockUpdateData(stocks.data[0], data);
|
||||
const updateData = this.buildStockUpdateData(stocks.data[0], keyword);
|
||||
this.tmp_storeName = stocks.data[0].store_stock.store_remask;
|
||||
await this.handleSelectDetailChange(updateData);
|
||||
} else if (stocks.total > 1) {
|
||||
@ -955,7 +1011,7 @@
|
||||
} else {
|
||||
const updateData = {
|
||||
...this.selectedDetail, // 保留原有的所有属性
|
||||
barcode: data,
|
||||
barcode: keyword,
|
||||
system_product_id:null,
|
||||
product_name:"新商品",
|
||||
|
||||
@ -999,6 +1055,10 @@
|
||||
onLoad(options) {
|
||||
if (options.id) {
|
||||
this.receivingId = parseInt(options.id);
|
||||
if (options.tab === 'content') {
|
||||
this.currentTab = 1;
|
||||
this.hasInitializedDefaultTab = true;
|
||||
}
|
||||
this.initData();
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user