fix:确认上传逐条创建/追加波次,提交入库只做绑定+入库
This commit is contained in:
parent
d618f03013
commit
4d4446820c
@ -2223,6 +2223,8 @@ export default {
|
||||
}
|
||||
this.pendingProductList.push(entry)
|
||||
this.pendingCount = this.pendingProductList.length
|
||||
// 创建/追加波次
|
||||
await this.appendWaveItem(warehouseData, productId, stock, price)
|
||||
if (this.pendingCount >= 200) {
|
||||
uni.showToast({ title: '本波次已满200件,请先提交入库', icon: 'none', duration: 2000 })
|
||||
}
|
||||
@ -2386,6 +2388,8 @@ export default {
|
||||
}
|
||||
this.pendingProductList.push(entry)
|
||||
this.pendingCount = this.pendingProductList.length
|
||||
// 创建/追加波次
|
||||
await this.appendWaveItem(this.noIsbnWarehouseData, productId, this.noIsbnStock ?? '1', salePrice)
|
||||
if (this.pendingCount >= 200) {
|
||||
uni.showToast({ title: '本波次已满200件,请先提交入库', icon: 'none', duration: 2000 })
|
||||
}
|
||||
@ -2542,57 +2546,50 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
// 提交入库:批量创建波次 → 释放 → 绑定 → 入库
|
||||
async submitReceive() {
|
||||
var list = this.pendingProductList
|
||||
if (list.length === 0) {
|
||||
uni.showToast({ title: '没有待入库的商品', icon: 'none' })
|
||||
// 确认上传时创建/追加波次(首次创建+release,后续release追加)
|
||||
async appendWaveItem(warehouseData, productId, stock, price) {
|
||||
var timestamp = String(Math.floor(Date.now() / 1000))
|
||||
var token = uni.getStorageSync('token') || ''
|
||||
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
|
||||
}
|
||||
|
||||
// 用第一个商品的仓库数据(假设同批次仓库一致)
|
||||
var warehouseData = list[0].warehouseData
|
||||
var timestamp = String(Math.floor(Date.now() / 1000))
|
||||
const token = uni.getStorageSync('token') || ''
|
||||
|
||||
// 查询小车列表
|
||||
// 首次 → 创建波次 + release
|
||||
var carInfo = await this.callCarListApi(timestamp)
|
||||
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 = {
|
||||
app_key: 'psi',
|
||||
client_id: 'psi',
|
||||
warehouse_id: String(warehouseData.warehouseId || ''),
|
||||
'items[0][product_id]': String(productId),
|
||||
'items[0][quantity]': String(stock),
|
||||
'items[0][unit_price]': String(price),
|
||||
direction: '1',
|
||||
car_id: String(carInfo.car_id),
|
||||
car_code: String(carInfo.car_code),
|
||||
timestamp: timestamp,
|
||||
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)
|
||||
params.sign = sign
|
||||
|
||||
try {
|
||||
const waveRes = await new Promise(function (resolve, reject) {
|
||||
var res = await new Promise(function (resolve, reject) {
|
||||
uni.request({
|
||||
url: 'https://psi.api.buzhiyushu.cn/api/purchase-order/create-with-wave',
|
||||
method: 'POST',
|
||||
@ -2605,58 +2602,68 @@ export default {
|
||||
fail: function (e) { reject(e) }
|
||||
})
|
||||
})
|
||||
|
||||
if (waveRes.statusCode !== 200 || !waveRes.data) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '创建波次失败 HTTP ' + waveRes.statusCode, icon: 'none', duration: 3000 })
|
||||
return
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
var waveId = waveResp.data.wave_id
|
||||
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) {
|
||||
uni.hideLoading()
|
||||
return
|
||||
}
|
||||
|
||||
// 绑定波次
|
||||
var bindResult = await this.callBindWaveApi(timestamp, releaseWaveNo)
|
||||
if (!bindResult) {
|
||||
uni.hideLoading()
|
||||
return
|
||||
}
|
||||
|
||||
// 提交入库(批量逐条提交)
|
||||
uni.showLoading({ title: '提交入库中...', mask: true })
|
||||
for (var k = 0; k < list.length; k++) {
|
||||
var p = list[k]
|
||||
await this.callReceiveSubmitApi(timestamp, bindResult, p.productId, p.stock, p.warehouseData)
|
||||
}
|
||||
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '入库完成,共 ' + list.length + ' 件', icon: 'success' })
|
||||
|
||||
// 清空待入库列表
|
||||
this.pendingProductList = []
|
||||
this.pendingCount = 0
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '提交入库失败: ' + (e.message || ''), icon: 'none', duration: 3000 })
|
||||
console.warn('【创建波次】失败:', e)
|
||||
}
|
||||
},
|
||||
|
||||
// 提交入库:绑定波次 + 提交入库(波次已通过确认上传累积)
|
||||
async submitReceive() {
|
||||
var list = this.pendingProductList
|
||||
if (list.length === 0) {
|
||||
uni.showToast({ title: '没有待入库的商品', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
var releaseWaveNo = uni.getStorageSync('reuseWaveNo') || ''
|
||||
if (!releaseWaveNo) {
|
||||
uni.showToast({ title: '没有可用波次,请先确认上传', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
var timestamp = String(Math.floor(Date.now() / 1000))
|
||||
uni.showLoading({ title: '提交入库中...', mask: true })
|
||||
|
||||
// 绑定波次(wave_no已通过确认上传时的 release 获取)
|
||||
var bindResult = await this.callBindWaveApi(timestamp, releaseWaveNo)
|
||||
if (!bindResult) {
|
||||
uni.hideLoading()
|
||||
return
|
||||
}
|
||||
|
||||
// 逐条提交入库
|
||||
for (var k = 0; k < list.length; k++) {
|
||||
var p = list[k]
|
||||
await this.callReceiveSubmitApi(timestamp, bindResult, p.productId, p.stock, p.warehouseData)
|
||||
}
|
||||
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '入库完成,共 ' + list.length + ' 件', icon: 'success' })
|
||||
|
||||
// 清空待入库列表及波次缓存
|
||||
this.pendingProductList = []
|
||||
this.pendingCount = 0
|
||||
uni.removeStorageSync('reuseWaveNo')
|
||||
uni.removeStorageSync('reuseWaveId')
|
||||
uni.removeStorageSync('reuseOrderId')
|
||||
uni.removeStorageSync('reuseCarId')
|
||||
uni.removeStorageSync('reuseCarCode')
|
||||
},
|
||||
|
||||
// 调用波次接口(syncBook 成功后调用)
|
||||
async callWaveApi(warehouseData, productId) {
|
||||
var timestamp = String(Math.floor(Date.now() / 1000))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user