1
This commit is contained in:
@@ -409,12 +409,16 @@ export default {
|
|||||||
try {
|
try {
|
||||||
// 调用转链接口查询商品信息
|
// 调用转链接口查询商品信息
|
||||||
const res = await generatePromotionContent({ promotionContent: materialUrl })
|
const res = await generatePromotionContent({ promotionContent: materialUrl })
|
||||||
|
console.log('查询商品信息返回:', res)
|
||||||
|
|
||||||
if (res && res.code === 200) {
|
if (res && res.code === 200) {
|
||||||
let productInfo = null
|
let productInfo = null
|
||||||
// 解析返回结果(参考xbmessage中的处理)
|
// 解析返回结果(参考xbmessage中的处理)
|
||||||
try {
|
try {
|
||||||
const resultStr = res.data
|
// 优先使用data,如果没有则使用msg(根据实际返回格式)
|
||||||
|
let resultStr = res.data || res.msg
|
||||||
|
|
||||||
|
// 如果是字符串,需要解析
|
||||||
let parsed = null
|
let parsed = null
|
||||||
if (typeof resultStr === 'string') {
|
if (typeof resultStr === 'string') {
|
||||||
parsed = JSON.parse(resultStr)
|
parsed = JSON.parse(resultStr)
|
||||||
@@ -422,34 +426,50 @@ export default {
|
|||||||
parsed = resultStr
|
parsed = resultStr
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提取第一个商品信息
|
console.log('解析后的数据:', parsed)
|
||||||
|
|
||||||
|
// 提取第一个商品信息(支持多种返回格式)
|
||||||
if (Array.isArray(parsed) && parsed.length > 0) {
|
if (Array.isArray(parsed) && parsed.length > 0) {
|
||||||
|
// 格式1:直接是数组
|
||||||
productInfo = parsed[0]
|
productInfo = parsed[0]
|
||||||
} else if (parsed.list && Array.isArray(parsed.list) && parsed.list.length > 0) {
|
} else if (parsed && typeof parsed === 'object') {
|
||||||
productInfo = parsed.list[0]
|
// 格式2:对象中包含list数组
|
||||||
} else if (parsed.data && Array.isArray(parsed.data) && parsed.data.length > 0) {
|
if (parsed.list && Array.isArray(parsed.list) && parsed.list.length > 0) {
|
||||||
productInfo = parsed.data[0]
|
productInfo = parsed.list[0]
|
||||||
} else if (parsed.materialUrl || parsed.owner) {
|
}
|
||||||
productInfo = parsed
|
// 格式3:对象中包含data数组
|
||||||
|
else if (parsed.data && Array.isArray(parsed.data) && parsed.data.length > 0) {
|
||||||
|
productInfo = parsed.data[0]
|
||||||
|
}
|
||||||
|
// 格式4:对象本身包含商品信息
|
||||||
|
else if (parsed.materialUrl || parsed.owner || parsed.skuName) {
|
||||||
|
productInfo = parsed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('提取的商品信息:', productInfo)
|
||||||
|
|
||||||
if (productInfo) {
|
if (productInfo) {
|
||||||
// 自动填充商品信息
|
// 自动填充商品信息
|
||||||
this.createForm.skuName = productInfo.skuName || productInfo.title || productInfo.productName || ''
|
this.createForm.skuName = productInfo.skuName || productInfo.title || productInfo.productName || productInfo.cleanSkuName || ''
|
||||||
this.createForm.owner = productInfo.owner || (productInfo.popId ? 'pop' : 'g') || 'g'
|
// owner字段:'p'表示POP,'g'表示自营,其他默认'g'
|
||||||
|
const ownerValue = productInfo.owner || (productInfo.popId ? 'pop' : 'g') || 'g'
|
||||||
|
this.createForm.owner = ownerValue === 'p' ? 'pop' : (ownerValue === 'pop' ? 'pop' : 'g')
|
||||||
|
|
||||||
// 如果有materialUrl,更新它(可能是提取后的SKU ID)
|
// 如果有materialUrl,可以用于后续创建礼金
|
||||||
if (productInfo.materialUrl || productInfo.url) {
|
if (productInfo.materialUrl && !this.createForm.materialUrl.includes('jingfen.jd.com')) {
|
||||||
// 不覆盖用户输入的,但如果用户输入的是完整链接,可以使用查询到的
|
// 如果用户输入的是普通链接,可以使用查询到的materialUrl(jingfen链接)
|
||||||
|
// 但为了不丢失用户输入,这里先不更新
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$modal.msgSuccess('商品信息查询成功')
|
this.$modal.msgSuccess('商品信息查询成功:' + (this.createForm.owner === 'g' ? '自营' : 'POP'))
|
||||||
} else {
|
} else {
|
||||||
|
console.warn('未找到商品信息,完整返回:', parsed)
|
||||||
this.$modal.msgWarning('未找到商品信息,请检查链接是否正确')
|
this.$modal.msgWarning('未找到商品信息,请检查链接是否正确')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('解析商品信息失败', e)
|
console.error('解析商品信息失败', e, '原始数据:', res)
|
||||||
this.$modal.msgWarning('返回数据格式异常,请手动填写商品信息')
|
this.$modal.msgWarning('返回数据格式异常:' + e.message + ',请手动填写商品信息')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.$modal.msgError('查询商品信息失败:' + (res.msg || '未知错误'))
|
this.$modal.msgError('查询商品信息失败:' + (res.msg || '未知错误'))
|
||||||
|
|||||||
Reference in New Issue
Block a user