fix:确认上传逐条创建/追加波次,提交入库只做绑定+入库
This commit is contained in:
parent
d618f03013
commit
4d4446820c
@ -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 {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 提交入库:批量创建波次 → 释放 → 绑定 → 入库
|
// 确认上传时创建/追加波次(首次创建+release,后续release追加)
|
||||||
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 成功后调用)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user