1
This commit is contained in:
@@ -152,17 +152,26 @@
|
|||||||
<el-dialog title="创建礼金" :visible.sync="createDialogVisible" width="500px" append-to-body>
|
<el-dialog title="创建礼金" :visible.sync="createDialogVisible" width="500px" append-to-body>
|
||||||
<el-form :model="createForm" :rules="createRules" ref="createForm" label-width="120px">
|
<el-form :model="createForm" :rules="createRules" ref="createForm" label-width="120px">
|
||||||
<el-form-item label="商品链接/SKU" prop="materialUrl">
|
<el-form-item label="商品链接/SKU" prop="materialUrl">
|
||||||
<el-input v-model="createForm.materialUrl" placeholder="请输入商品链接(如:https://item.jd.com/100012043978.html)或SKU ID(如:100012043978)" />
|
<el-input
|
||||||
<div style="color: #909399; font-size: 12px; margin-top: 5px;">支持:京东商品链接或SKU ID(纯数字)</div>
|
v-model="createForm.materialUrl"
|
||||||
|
placeholder="请输入商品链接或SKU ID,回车或点击查询按钮查询商品信息"
|
||||||
|
@keyup.enter.native="queryProductInfo"
|
||||||
|
>
|
||||||
|
<el-button slot="append" icon="el-icon-search" @click="queryProductInfo" :loading="queryLoading">查询</el-button>
|
||||||
|
</el-input>
|
||||||
|
<div style="color: #909399; font-size: 12px; margin-top: 5px;">支持:京东商品链接或SKU ID,输入后点击查询自动获取商品信息</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="商品名称" prop="skuName">
|
<el-form-item label="商品名称" prop="skuName">
|
||||||
<el-input v-model="createForm.skuName" placeholder="商品名称(可选)" />
|
<el-input v-model="createForm.skuName" placeholder="查询商品信息后自动填充" :disabled="true" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="商品类型" prop="owner">
|
<el-form-item label="商品类型" prop="owner">
|
||||||
<el-radio-group v-model="createForm.owner">
|
<el-input :value="createForm.owner === 'g' ? '自营' : (createForm.owner === 'pop' ? 'POP' : '未查询')" disabled>
|
||||||
<el-radio label="g">自营</el-radio>
|
<template slot="prepend">
|
||||||
<el-radio label="pop">POP</el-radio>
|
<i :class="createForm.owner === 'g' ? 'el-icon-success' : (createForm.owner === 'pop' ? 'el-icon-warning' : 'el-icon-question')"
|
||||||
</el-radio-group>
|
:style="{color: createForm.owner === 'g' ? '#67C23A' : (createForm.owner === 'pop' ? '#409EFF' : '#909399')}"></i>
|
||||||
|
</template>
|
||||||
|
</el-input>
|
||||||
|
<div style="color: #909399; font-size: 12px; margin-top: 5px;">查询商品信息后自动识别(自营/POP)</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="礼金金额(元)" prop="amount">
|
<el-form-item label="礼金金额(元)" prop="amount">
|
||||||
<el-input-number v-model="createForm.amount" :min="1" :max="50" :precision="2" :step="0.01" style="width: 100%" />
|
<el-input-number v-model="createForm.amount" :min="1" :max="50" :precision="2" :step="0.01" style="width: 100%" />
|
||||||
@@ -249,7 +258,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listGiftCoupons, getGiftCoupon, getGiftCouponStatistics, exportGiftCoupons } from '@/api/system/giftcoupon'
|
import { listGiftCoupons, getGiftCoupon, getGiftCouponStatistics, exportGiftCoupons } from '@/api/system/giftcoupon'
|
||||||
import { createGiftCoupon, transferWithGift } from '@/api/system/jdorder'
|
import { createGiftCoupon, transferWithGift, generatePromotionContent } from '@/api/system/jdorder'
|
||||||
import ListLayout from '@/components/ListLayout'
|
import ListLayout from '@/components/ListLayout'
|
||||||
import { parseTime } from '@/utils/ruoyi'
|
import { parseTime } from '@/utils/ruoyi'
|
||||||
|
|
||||||
@@ -289,9 +298,10 @@ export default {
|
|||||||
materialUrl: '',
|
materialUrl: '',
|
||||||
skuName: '',
|
skuName: '',
|
||||||
owner: 'g',
|
owner: 'g',
|
||||||
amount: null,
|
amount: 5, // 默认5元
|
||||||
quantity: 10
|
quantity: 10 // 默认10
|
||||||
},
|
},
|
||||||
|
queryLoading: false, // 查询商品信息加载状态
|
||||||
createRules: {
|
createRules: {
|
||||||
materialUrl: [{ required: true, message: '请输入商品链接或SKU', trigger: 'blur' }],
|
materialUrl: [{ required: true, message: '请输入商品链接或SKU', trigger: 'blur' }],
|
||||||
amount: [{ required: true, message: '请输入礼金金额', trigger: 'blur' }],
|
amount: [{ required: true, message: '请输入礼金金额', trigger: 'blur' }],
|
||||||
@@ -382,11 +392,75 @@ export default {
|
|||||||
materialUrl: '',
|
materialUrl: '',
|
||||||
skuName: '',
|
skuName: '',
|
||||||
owner: 'g',
|
owner: 'g',
|
||||||
amount: null,
|
amount: 5, // 默认5元
|
||||||
quantity: 10
|
quantity: 10 // 默认10
|
||||||
}
|
}
|
||||||
this.createDialogVisible = true
|
this.createDialogVisible = true
|
||||||
},
|
},
|
||||||
|
/** 查询商品信息(参考xbmessage中的流程) */
|
||||||
|
async queryProductInfo() {
|
||||||
|
const materialUrl = this.createForm.materialUrl.trim()
|
||||||
|
if (!materialUrl) {
|
||||||
|
this.$modal.msgWarning('请输入商品链接或SKU ID')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.queryLoading = true
|
||||||
|
try {
|
||||||
|
// 调用转链接口查询商品信息
|
||||||
|
const res = await generatePromotionContent({ promotionContent: materialUrl })
|
||||||
|
|
||||||
|
if (res && res.code === 200) {
|
||||||
|
let productInfo = null
|
||||||
|
// 解析返回结果(参考xbmessage中的处理)
|
||||||
|
try {
|
||||||
|
const resultStr = res.data
|
||||||
|
let parsed = null
|
||||||
|
if (typeof resultStr === 'string') {
|
||||||
|
parsed = JSON.parse(resultStr)
|
||||||
|
} else {
|
||||||
|
parsed = resultStr
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取第一个商品信息
|
||||||
|
if (Array.isArray(parsed) && parsed.length > 0) {
|
||||||
|
productInfo = parsed[0]
|
||||||
|
} else if (parsed.list && Array.isArray(parsed.list) && parsed.list.length > 0) {
|
||||||
|
productInfo = parsed.list[0]
|
||||||
|
} else if (parsed.data && Array.isArray(parsed.data) && parsed.data.length > 0) {
|
||||||
|
productInfo = parsed.data[0]
|
||||||
|
} else if (parsed.materialUrl || parsed.owner) {
|
||||||
|
productInfo = parsed
|
||||||
|
}
|
||||||
|
|
||||||
|
if (productInfo) {
|
||||||
|
// 自动填充商品信息
|
||||||
|
this.createForm.skuName = productInfo.skuName || productInfo.title || productInfo.productName || ''
|
||||||
|
this.createForm.owner = productInfo.owner || (productInfo.popId ? 'pop' : 'g') || 'g'
|
||||||
|
|
||||||
|
// 如果有materialUrl,更新它(可能是提取后的SKU ID)
|
||||||
|
if (productInfo.materialUrl || productInfo.url) {
|
||||||
|
// 不覆盖用户输入的,但如果用户输入的是完整链接,可以使用查询到的
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$modal.msgSuccess('商品信息查询成功')
|
||||||
|
} else {
|
||||||
|
this.$modal.msgWarning('未找到商品信息,请检查链接是否正确')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('解析商品信息失败', e)
|
||||||
|
this.$modal.msgWarning('返回数据格式异常,请手动填写商品信息')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.$modal.msgError('查询商品信息失败:' + (res.msg || '未知错误'))
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('查询商品信息异常', e)
|
||||||
|
this.$modal.msgError('查询失败:' + (e.message || '未知错误'))
|
||||||
|
} finally {
|
||||||
|
this.queryLoading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
/** 从链接中提取SKU ID */
|
/** 从链接中提取SKU ID */
|
||||||
extractSkuIdFromUrl(url) {
|
extractSkuIdFromUrl(url) {
|
||||||
if (!url) return null
|
if (!url) return null
|
||||||
|
|||||||
Reference in New Issue
Block a user