feat:doSubmit调用pushToShop API(form-urlencoded)推送到店铺
This commit is contained in:
parent
8adcaaf021
commit
aa15fd476b
@ -2001,38 +2001,67 @@ export default {
|
|||||||
try {
|
try {
|
||||||
console.log('【上传】MinIO图片URL列表:', imageUrls)
|
console.log('【上传】MinIO图片URL列表:', imageUrls)
|
||||||
|
|
||||||
uni.hideLoading()
|
// 品相纯数字
|
||||||
|
const conditionDisplay = (this.currentTab === 'isbn' ? this.conditionValue : this.noIsbnConditionValue).replace('~', '')
|
||||||
|
|
||||||
// 构建上传数据
|
// 构建 form-data 参数
|
||||||
const formData = {
|
const userId = uni.getStorageSync('userId') || ''
|
||||||
token: uni.getStorageSync('token'),
|
const apiData = {
|
||||||
userId: uni.getStorageSync('userId'),
|
userid: userId,
|
||||||
warehouseId: warehouseData.warehouseId,
|
warehouse_id: String(warehouseData.warehouseId || ''),
|
||||||
warehouseCode: warehouseData.warehouseCode,
|
location_id: String(warehouseData.locationId || ''),
|
||||||
locationId: warehouseData.locationId,
|
isbn: '',
|
||||||
locationCode: warehouseData.locationCode,
|
price: '',
|
||||||
conditionValue: this.currentTab === 'isbn' ? this.conditionValue : this.noIsbnConditionValue,
|
stock: '',
|
||||||
images: imageUrls
|
appearance: conditionDisplay,
|
||||||
|
product_name: '',
|
||||||
|
photos: imageUrls
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.currentTab === 'isbn') {
|
if (this.currentTab === 'isbn') {
|
||||||
formData.isbn = this.isbn
|
apiData.isbn = this.isbn || ''
|
||||||
formData.bookName = this.bookName
|
apiData.price = this.price || ''
|
||||||
formData.price = this.price
|
apiData.stock = String(this.stock ?? '')
|
||||||
formData.stock = this.stock
|
apiData.product_name = this.bookName || ''
|
||||||
formData.author = this.author
|
|
||||||
formData.publisher = this.publisher
|
|
||||||
formData.fixPrice = this.fixPrice
|
|
||||||
formData.printTime = this.printTime
|
|
||||||
} else {
|
} else {
|
||||||
formData.bookName = this.noIsbnBookName
|
apiData.isbn = this.noIsbnIsbn || this.noIsbnUnifyIsbn || ''
|
||||||
formData.price = this.noIsbnPrice
|
apiData.price = this.noIsbnPrice || ''
|
||||||
formData.stock = this.noIsbnStock
|
apiData.stock = String(this.noIsbnStock ?? '')
|
||||||
formData.author = this.noIsbnAuthor
|
apiData.product_name = this.noIsbnBookName || ''
|
||||||
formData.publisher = this.noIsbnPublisher
|
}
|
||||||
formData.originalPrice = this.noIsbnOriginalPrice
|
|
||||||
formData.isbn = this.noIsbnIsbn || this.noIsbnUnifyIsbn
|
// 调用 API 推送到店铺
|
||||||
formData.printTime = this.noIsbnPrintTime
|
const apiUrl = 'http://192.168.101.213:9090/api/product/pushToShop'
|
||||||
|
console.log('【上传】推送API:', apiUrl, apiData)
|
||||||
|
|
||||||
|
// 使用 uni.request 以 form-urlencoded 方式发送
|
||||||
|
const res = await new Promise(function (resolve, reject) {
|
||||||
|
uni.request({
|
||||||
|
url: apiUrl,
|
||||||
|
method: 'POST',
|
||||||
|
header: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
data: {
|
||||||
|
userid: apiData.userid,
|
||||||
|
warehouse_id: apiData.warehouse_id,
|
||||||
|
location_id: apiData.location_id,
|
||||||
|
isbn: apiData.isbn,
|
||||||
|
price: apiData.price,
|
||||||
|
stock: apiData.stock,
|
||||||
|
appearance: apiData.appearance,
|
||||||
|
product_name: apiData.product_name,
|
||||||
|
photos: apiData.photos.join(',')
|
||||||
|
},
|
||||||
|
success: function (r) { resolve(r) },
|
||||||
|
fail: function (e) { reject(e) }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('【上传】API响应:', res.statusCode, res.data)
|
||||||
|
|
||||||
|
uni.hideLoading()
|
||||||
|
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
throw new Error('API返回: HTTP ' + res.statusCode + ' ' + JSON.stringify(res.data || ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存上传记录到本地
|
// 保存上传记录到本地
|
||||||
@ -2041,7 +2070,9 @@ export default {
|
|||||||
id: Date.now(),
|
id: Date.now(),
|
||||||
time: new Date().toLocaleString(),
|
time: new Date().toLocaleString(),
|
||||||
type: this.currentTab,
|
type: this.currentTab,
|
||||||
data: formData
|
apiUrl: apiUrl,
|
||||||
|
apiResponse: res.data,
|
||||||
|
data: apiData
|
||||||
})
|
})
|
||||||
uni.setStorageSync('uploadHistory', uploadHistory.slice(0, 100))
|
uni.setStorageSync('uploadHistory', uploadHistory.slice(0, 100))
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user