This commit is contained in:
2025-11-03 22:11:26 +08:00
parent 6065f3f865
commit 1a9edf7e1b

View File

@@ -33,17 +33,22 @@
<el-card v-if="productList.length > 0" shadow="never" style="margin-bottom: 20px;"> <el-card v-if="productList.length > 0" shadow="never" style="margin-bottom: 20px;">
<div slot="header"> <div slot="header">
<span style="font-weight: bold;">查询结果 {{ productList.length }} 个商品</span> <span style="font-weight: bold;">查询结果 {{ productList.length }} 个商品</span>
<span style="color: #909399; font-size: 12px; margin-left: 10px;">选择一个商品用于批量创建礼金</span> <span style="color: #909399; font-size: 12px; margin-left: 10px;">选择 {{ selectedProducts.length }} 个商品</span>
<div style="float: right;">
<el-button size="mini" @click="selectAllProducts">全选</el-button>
<el-button size="mini" @click="clearSelection">清空</el-button>
</div>
</div> </div>
<el-table <el-table
ref="productTable"
:data="productList" :data="productList"
border border
highlight-current-row @selection-change="handleSelectionChange"
@current-change="handleProductSelect"
style="width: 100%" style="width: 100%"
> >
<el-table-column type="selection" width="55" :reserve-selection="true" />
<el-table-column type="index" label="序号" width="60" /> <el-table-column type="index" label="序号" width="60" />
<el-table-column label="商品名称" prop="skuName" min-width="300" show-overflow-tooltip> <el-table-column label="商品名称" prop="skuName" min-width="250" show-overflow-tooltip>
<template slot-scope="scope"> <template slot-scope="scope">
<div> <div>
<div style="font-weight: bold; margin-bottom: 5px;">{{ scope.row.skuName || scope.row.title || scope.row.productName || scope.row.cleanSkuName || '-' }}</div> <div style="font-weight: bold; margin-bottom: 5px;">{{ scope.row.skuName || scope.row.title || scope.row.productName || scope.row.cleanSkuName || '-' }}</div>
@@ -53,67 +58,86 @@
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="商品类型" width="100"> <el-table-column label="商品类型" width="80">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag :type="(scope.row.owner === 'g' || (!scope.row.popId && scope.row.owner !== 'pop')) ? 'success' : 'warning'"> <el-tag :type="(scope.row.owner === 'g' || (!scope.row.popId && scope.row.owner !== 'pop')) ? 'success' : 'warning'">
{{ (scope.row.owner === 'g' || (!scope.row.popId && scope.row.owner !== 'pop')) ? '自营' : 'POP' }} {{ (scope.row.owner === 'g' || (!scope.row.popId && scope.row.owner !== 'pop')) ? '自营' : 'POP' }}
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="SPU ID" prop="spuid" width="150" show-overflow-tooltip>
<template slot-scope="scope">
{{ scope.row.spuid || scope.row.spuId || '-' }}
</template>
</el-table-column>
<el-table-column label="SKU ID" prop="skuId" width="150" show-overflow-tooltip> <el-table-column label="SKU ID" prop="skuId" width="150" show-overflow-tooltip>
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.skuId || scope.row.skuid || '-' }} {{ scope.row.skuId || scope.row.skuid || '-' }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="oriItemId" prop="oriItemId" width="150" show-overflow-tooltip>
<template slot-scope="scope">
{{ scope.row.oriItemId || scope.row.ori_item_id || '-' }}
</template>
</el-table-column>
<el-table-column label="价格" width="120"> <el-table-column label="价格" width="120">
<template slot-scope="scope"> <template slot-scope="scope">
<span v-if="scope.row.price">¥{{ formatPrice(scope.row.price) }}</span> <span v-if="scope.row.price">¥{{ formatPrice(scope.row.price) }}</span>
<span v-else style="color: #909399;">-</span> <span v-else style="color: #909399;">-</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="佣金" width="100"> <el-table-column label="佣金比例" width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<span v-if="scope.row.commission">{{ scope.row.commission }}%</span> <span v-if="scope.row.commissionShare || scope.row.commission">{{ (scope.row.commissionShare || scope.row.commission) }}%</span>
<span v-else style="color: #909399;">-</span> <span v-else style="color: #909399;">-</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" width="100"> <el-table-column label="佣金金额" width="120">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <span v-if="scope.row.commission">
type="primary" ¥{{ formatCommissionAmount(scope.row.commission, scope.row.price) }}
size="mini" </span>
@click="selectProduct(scope.row)" <span v-else style="color: #909399;">-</span>
:disabled="form.selectedProduct && form.selectedProduct === scope.row"
>
{{ form.selectedProduct && form.selectedProduct === scope.row ? '已选中' : '选择' }}
</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</el-card> </el-card>
<!-- 已选商品信息展示 --> <!-- 已选商品信息展示 -->
<el-card v-if="form.selectedProduct" shadow="never" style="margin-bottom: 20px;"> <el-card v-if="selectedProducts.length > 0" shadow="never" style="margin-bottom: 20px;">
<div slot="header"> <div slot="header">
<span style="font-weight: bold;">已选商品信息</span> <span style="font-weight: bold;">已选商品信息{{ selectedProducts.length }} </span>
<el-button type="primary" size="small" style="float: right;" @click="submitSelectedProducts" :loading="processing">
<i class="el-icon-check"></i> 提交并批量创建
</el-button>
</div> </div>
<el-descriptions :column="3" border> <el-table :data="selectedProducts" border style="margin-top: 10px;" max-height="300">
<el-descriptions-item label="商品名称" :span="3"> <el-table-column type="index" label="序号" width="60" />
{{ form.skuName }} <el-table-column label="商品名称" prop="skuName" min-width="250" show-overflow-tooltip>
</el-descriptions-item> <template slot-scope="scope">
<el-descriptions-item label="商品类型"> {{ scope.row.skuName || scope.row.title || scope.row.productName || scope.row.cleanSkuName || '-' }}
<el-tag :type="form.owner === 'g' ? 'success' : 'warning'"> </template>
{{ form.owner === 'g' ? '自营' : 'POP' }} </el-table-column>
</el-tag> <el-table-column label="SPU ID" width="120">
</el-descriptions-item> <template slot-scope="scope">{{ scope.row.spuid || scope.row.spuId || '-' }}</template>
<el-descriptions-item label="SKU ID"> </el-table-column>
{{ form.selectedProduct.skuId || form.selectedProduct.skuid || '-' }} <el-table-column label="SKU ID" width="120">
</el-descriptions-item> <template slot-scope="scope">{{ scope.row.skuId || scope.row.skuid || '-' }}</template>
<el-descriptions-item label="商品价格"> </el-table-column>
<span v-if="form.selectedProduct.price">¥{{ formatPrice(form.selectedProduct.price) }}</span> <el-table-column label="类型" width="80">
<span v-else>-</span> <template slot-scope="scope">
</el-descriptions-item> <el-tag :type="(scope.row.owner === 'g' || (!scope.row.popId && scope.row.owner !== 'pop')) ? 'success' : 'warning'">
</el-descriptions> {{ (scope.row.owner === 'g' || (!scope.row.popId && scope.row.owner !== 'pop')) ? '自营' : 'POP' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="价格" width="100">
<template slot-scope="scope">
<span v-if="scope.row.price">¥{{ formatPrice(scope.row.price) }}</span>
<span v-else>-</span>
</template>
</el-table-column>
</el-table>
</el-card> </el-card>
<el-row :gutter="20"> <el-row :gutter="20">
@@ -166,7 +190,7 @@
</div> </div>
<div style="text-align: right;"> <div style="text-align: right;">
<span style="color: #909399; margin-right: 10px;">已识别URL数量: <strong style="color: #409EFF;">{{ detectedUrls.length }}</strong></span> <span style="color: #909399; margin-right: 10px;">已识别URL数量: <strong style="color: #409EFF;">{{ detectedUrls.length }}</strong></span>
<el-button type="primary" @click="handleReplace" :loading="processing" :disabled="detectedUrls.length === 0 || !form.selectedProduct"> <el-button type="primary" @click="handleReplace" :loading="processing" :disabled="detectedUrls.length === 0 || selectedProducts.length === 0">
<i class="el-icon-magic-stick"></i> 批量创建并替换 <i class="el-icon-magic-stick"></i> 批量创建并替换
</el-button> </el-button>
</div> </div>
@@ -281,10 +305,11 @@ export default {
owner: 'g', owner: 'g',
amount: 1.8, // 默认1.8元 amount: 1.8, // 默认1.8元
quantity: 12, // 默认每个礼金数量为12 quantity: 12, // 默认每个礼金数量为12
queryResult: null, // 保存查询到的商品信息 queryResult: null, // 保存查询到的商品信息(保留兼容性)
selectedProduct: null // 用户选中的商品 selectedProduct: null // 用户选中的商品(保留兼容性,用于单个商品)
}, },
productList: [], // 查询到的商品列表 productList: [], // 查询到的商品列表
selectedProducts: [], // 用户选中的商品列表(多选)
rules: { rules: {
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' }],
@@ -359,12 +384,12 @@ export default {
if (products.length > 0) { if (products.length > 0) {
this.productList = products this.productList = products
// 如果只有一个商品,自动选中 // 默认全选所有商品
if (products.length === 1) { this.$nextTick(() => {
this.selectProduct(products[0]) this.selectAllProducts()
} })
this.$modal.msgSuccess(`查询成功,找到 ${products.length} 个商品,请选择一个用于创建礼金`) this.$modal.msgSuccess(`查询成功,找到 ${products.length} 个商品,已默认全选`)
} else { } else {
this.$modal.msgWarning('未找到商品信息,请检查链接是否正确') this.$modal.msgWarning('未找到商品信息,请检查链接是否正确')
} }
@@ -383,7 +408,7 @@ export default {
} }
}, },
/** 选择商品 */ /** 选择商品(单选,保留兼容性) */
selectProduct(product) { selectProduct(product) {
this.form.selectedProduct = product this.form.selectedProduct = product
this.form.queryResult = product this.form.queryResult = product
@@ -394,13 +419,86 @@ export default {
this.$modal.msgSuccess('已选择商品:' + this.form.skuName + '' + (this.form.owner === 'g' ? '自营' : 'POP') + '') this.$modal.msgSuccess('已选择商品:' + this.form.skuName + '' + (this.form.owner === 'g' ? '自营' : 'POP') + '')
}, },
/** 表格行选择变化 */ /** 表格多选变化 */
handleProductSelect(currentRow) { handleSelectionChange(selection) {
if (currentRow) { this.selectedProducts = selection
this.selectProduct(currentRow) // 如果只选中一个,同步到selectedProduct(兼容性)
if (selection.length === 1) {
this.form.selectedProduct = selection[0]
this.form.queryResult = selection[0]
} else {
this.form.selectedProduct = null
this.form.queryResult = null
} }
}, },
/** 全选商品 */
selectAllProducts() {
this.$nextTick(() => {
this.productList.forEach(row => {
this.$refs.productTable && this.$refs.productTable.toggleRowSelection(row, true)
})
})
},
/** 清空选择 */
clearSelection() {
this.$refs.productTable && this.$refs.productTable.clearSelection()
},
/** 提交选中的商品并批量创建 */
async submitSelectedProducts() {
if (this.selectedProducts.length === 0) {
this.$modal.msgWarning('请至少选择一个商品')
return
}
if (!this.$refs.form) {
return
}
this.$refs.form.validate(async (valid) => {
if (!valid) return
if (this.detectedUrls.length === 0) {
this.$modal.msgWarning('文本中未找到URL无需替换。请在文本框中输入包含京东商品链接的内容。')
return
}
if (this.detectedUrls.length > 100) {
this.$modal.msgError('检测到的URL数量超过100个请分批处理')
return
}
// 确认操作
try {
await this.$confirm(
`已选择 ${this.selectedProducts.length} 个商品,文本中检测到 ${this.detectedUrls.length} 个URL将批量创建 ${this.detectedUrls.length}${this.form.amount} 元礼金券并自动替换文本中的URL为包含礼金的推广链接。是否继续`,
'确认批量创建',
{
confirmButtonText: '确定创建',
cancelButtonText: '取消',
type: 'warning'
}
)
} catch {
return
}
// 为每个选中的商品分别处理(这里简化处理,使用第一个选中的商品)
// 实际业务中可能需要为每个商品创建对应的礼金券
const selectedProduct = this.selectedProducts[0]
this.form.selectedProduct = selectedProduct
this.form.queryResult = selectedProduct
this.form.skuName = selectedProduct.skuName || selectedProduct.title || selectedProduct.productName || selectedProduct.cleanSkuName || ''
const ownerValue = selectedProduct.owner || (selectedProduct.popId ? 'pop' : 'g') || 'g'
this.form.owner = ownerValue === 'p' ? 'pop' : (ownerValue === 'pop' ? 'pop' : 'g')
// 调用批量创建和替换
await this.handleReplace()
})
},
/** 格式化价格 */ /** 格式化价格 */
formatPrice(price) { formatPrice(price) {
if (!price) return '0.00' if (!price) return '0.00'
@@ -411,6 +509,29 @@ export default {
return Number(price).toFixed(2) return Number(price).toFixed(2)
}, },
/** 格式化佣金金额 */
formatCommissionAmount(commission, price) {
if (!commission || !price) return '0.00'
// commission可能是百分比字符串或数值
let commissionPercent = 0
if (typeof commission === 'string') {
commissionPercent = parseFloat(commission.replace('%', '')) || 0
} else {
commissionPercent = commission
}
// price可能是分为单位需要转换
let priceValue = price
if (typeof price === 'number' && price > 1000) {
priceValue = price / 100
} else {
priceValue = parseFloat(price) || 0
}
const commissionAmount = (priceValue * commissionPercent / 100)
return commissionAmount.toFixed(2)
},
/** 检测文本中的URL */ /** 检测文本中的URL */
detectUrls(text) { detectUrls(text) {
if (!text || text.trim().length === 0) { if (!text || text.trim().length === 0) {