fix:确认上传逐条创建/追加波次,提交入库只做绑定+入库

This commit is contained in:
ShenQiLun 2026-06-26 11:58:44 +08:00
parent d618f03013
commit 4d4446820c

View File

@ -2223,6 +2223,8 @@ export default {
} }
this.pendingProductList.push(entry) this.pendingProductList.push(entry)
this.pendingCount = this.pendingProductList.length this.pendingCount = this.pendingProductList.length
// /
await this.appendWaveItem(warehouseData, productId, stock, price)
if (this.pendingCount >= 200) { if (this.pendingCount >= 200) {
uni.showToast({ title: '本波次已满200件请先提交入库', icon: 'none', duration: 2000 }) uni.showToast({ title: '本波次已满200件请先提交入库', icon: 'none', duration: 2000 })
} }
@ -2386,6 +2388,8 @@ export default {
} }
this.pendingProductList.push(entry) this.pendingProductList.push(entry)
this.pendingCount = this.pendingProductList.length this.pendingCount = this.pendingProductList.length
// /
await this.appendWaveItem(this.noIsbnWarehouseData, productId, this.noIsbnStock ?? '1', salePrice)
if (this.pendingCount >= 200) { if (this.pendingCount >= 200) {
uni.showToast({ title: '本波次已满200件请先提交入库', icon: 'none', duration: 2000 }) uni.showToast({ title: '本波次已满200件请先提交入库', icon: 'none', duration: 2000 })
} }
@ -2542,57 +2546,50 @@ export default {
} }
}, },
// // /+releaserelease
async submitReceive() { async appendWaveItem(warehouseData, productId, stock, price) {
var list = this.pendingProductList var timestamp = String(Math.floor(Date.now() / 1000))
if (list.length === 0) { var token = uni.getStorageSync('token') || ''
uni.showToast({ title: '没有待入库的商品', icon: 'none' }) var waveId = uni.getStorageSync('reuseWaveId') || ''
var orderId = uni.getStorageSync('reuseOrderId') || ''
// release
if (waveId && orderId) {
var carInfo = {
car_id: uni.getStorageSync('reuseCarId') || '',
car_code: uni.getStorageSync('reuseCarCode') || ''
}
if (carInfo.car_id) {
var releaseNo = await this.callWaveReleaseApi(timestamp, waveId, orderId, carInfo, productId, stock, price)
if (releaseNo) {
uni.setStorageSync('reuseWaveNo', releaseNo)
}
}
return return
} }
// // + release
var warehouseData = list[0].warehouseData
var timestamp = String(Math.floor(Date.now() / 1000))
const token = uni.getStorageSync('token') || ''
//
var carInfo = await this.callCarListApi(timestamp) var carInfo = await this.callCarListApi(timestamp)
if (!carInfo) return if (!carInfo) return
uni.showLoading({ title: '波次处理中...', mask: true })
//
var items = []
for (var i = 0; i < list.length; i++) {
var item = list[i]
items.push({
product_id: String(item.productId),
quantity: String(item.stock),
unit_price: String(item.price)
})
}
var params = { var params = {
app_key: 'psi', app_key: 'psi',
client_id: 'psi', client_id: 'psi',
warehouse_id: String(warehouseData.warehouseId || ''), warehouse_id: String(warehouseData.warehouseId || ''),
'items[0][product_id]': String(productId),
'items[0][quantity]': String(stock),
'items[0][unit_price]': String(price),
direction: '1', direction: '1',
car_id: String(carInfo.car_id), car_id: String(carInfo.car_id),
car_code: String(carInfo.car_code), car_code: String(carInfo.car_code),
timestamp: timestamp, timestamp: timestamp,
sign_method: 'md5' sign_method: 'md5'
} }
// items
for (var j = 0; j < items.length; j++) {
params['items[' + j + '][product_id]'] = items[j].product_id
params['items[' + j + '][quantity]'] = items[j].quantity
params['items[' + j + '][unit_price]'] = items[j].unit_price
}
var sign = calculateSign(params) var sign = calculateSign(params)
params.sign = sign params.sign = sign
try { try {
const waveRes = await new Promise(function (resolve, reject) { var res = await new Promise(function (resolve, reject) {
uni.request({ uni.request({
url: 'https://psi.api.buzhiyushu.cn/api/purchase-order/create-with-wave', url: 'https://psi.api.buzhiyushu.cn/api/purchase-order/create-with-wave',
method: 'POST', method: 'POST',
@ -2605,41 +2602,50 @@ export default {
fail: function (e) { reject(e) } fail: function (e) { reject(e) }
}) })
}) })
if (res.statusCode === 200 && res.data) {
var d = res.data
if (typeof d === 'string') { try { d = JSON.parse(d) } catch (e) { d = {} } }
if (d.code === 200 && d.data && d.data.wave_id && d.data.order_id) {
uni.setStorageSync('reuseWaveId', d.data.wave_id)
uni.setStorageSync('reuseOrderId', d.data.order_id)
uni.setStorageSync('reuseCarId', String(carInfo.car_id))
uni.setStorageSync('reuseCarCode', String(carInfo.car_code))
var releaseNo = await this.callWaveReleaseApi(timestamp, d.data.wave_id, d.data.order_id, carInfo, productId, stock, price)
if (releaseNo) {
uni.setStorageSync('reuseWaveNo', releaseNo)
}
}
}
} catch (e) {
console.warn('【创建波次】失败:', e)
}
},
if (waveRes.statusCode !== 200 || !waveRes.data) { // +
uni.hideLoading() async submitReceive() {
uni.showToast({ title: '创建波次失败 HTTP ' + waveRes.statusCode, icon: 'none', duration: 3000 }) var list = this.pendingProductList
return if (list.length === 0) {
} uni.showToast({ title: '没有待入库的商品', icon: 'none' })
var waveResp = waveRes.data
if (typeof waveResp === 'string') {
try { waveResp = JSON.parse(waveResp) } catch (e) { waveResp = {} }
}
if (!(waveResp.code === 200 && waveResp.data && waveResp.data.wave_id && waveResp.data.order_id)) {
uni.hideLoading()
uni.showToast({ title: '创建波次: ' + (waveResp.msg || '返回数据异常'), icon: 'none', duration: 3000 })
return return
} }
var waveId = waveResp.data.wave_id var releaseWaveNo = uni.getStorageSync('reuseWaveNo') || ''
var orderId = waveResp.data.order_id
// wave_no
var releaseWaveNo = await this.callWaveReleaseApi(timestamp, waveId, orderId, carInfo, list[0].productId, list[0].stock, list[0].price)
if (!releaseWaveNo) { if (!releaseWaveNo) {
uni.hideLoading() uni.showToast({ title: '没有可用波次,请先确认上传', icon: 'none' })
return return
} }
// var timestamp = String(Math.floor(Date.now() / 1000))
uni.showLoading({ title: '提交入库中...', mask: true })
// wave_no release
var bindResult = await this.callBindWaveApi(timestamp, releaseWaveNo) var bindResult = await this.callBindWaveApi(timestamp, releaseWaveNo)
if (!bindResult) { if (!bindResult) {
uni.hideLoading() uni.hideLoading()
return return
} }
// //
uni.showLoading({ title: '提交入库中...', mask: true })
for (var k = 0; k < list.length; k++) { for (var k = 0; k < list.length; k++) {
var p = list[k] var p = list[k]
await this.callReceiveSubmitApi(timestamp, bindResult, p.productId, p.stock, p.warehouseData) await this.callReceiveSubmitApi(timestamp, bindResult, p.productId, p.stock, p.warehouseData)
@ -2648,13 +2654,14 @@ export default {
uni.hideLoading() uni.hideLoading()
uni.showToast({ title: '入库完成,共 ' + list.length + ' 件', icon: 'success' }) uni.showToast({ title: '入库完成,共 ' + list.length + ' 件', icon: 'success' })
// //
this.pendingProductList = [] this.pendingProductList = []
this.pendingCount = 0 this.pendingCount = 0
} catch (e) { uni.removeStorageSync('reuseWaveNo')
uni.hideLoading() uni.removeStorageSync('reuseWaveId')
uni.showToast({ title: '提交入库失败: ' + (e.message || ''), icon: 'none', duration: 3000 }) uni.removeStorageSync('reuseOrderId')
} uni.removeStorageSync('reuseCarId')
uni.removeStorageSync('reuseCarCode')
}, },
// syncBook // syncBook