1
This commit is contained in:
@@ -33,17 +33,22 @@
|
||||
<el-card v-if="productList.length > 0" shadow="never" style="margin-bottom: 20px;">
|
||||
<div slot="header">
|
||||
<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>
|
||||
<el-table
|
||||
ref="productTable"
|
||||
:data="productList"
|
||||
border
|
||||
highlight-current-row
|
||||
@current-change="handleProductSelect"
|
||||
@selection-change="handleSelectionChange"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-table-column type="selection" width="55" :reserve-selection="true" />
|
||||
<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">
|
||||
<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>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品类型" width="100">
|
||||
<el-table-column label="商品类型" width="80">
|
||||
<template slot-scope="scope">
|
||||
<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' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</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>
|
||||
<template slot-scope="scope">
|
||||
{{ scope.row.skuId || scope.row.skuid || '-' }}
|
||||
</template>
|
||||
</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">
|
||||
<template slot-scope="scope">
|
||||
<span v-if="scope.row.price">¥{{ formatPrice(scope.row.price) }}</span>
|
||||
<span v-else style="color: #909399;">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="佣金" width="100">
|
||||
<el-table-column label="佣金比例" width="100">
|
||||
<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>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="100">
|
||||
<el-table-column label="佣金金额" width="120">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="mini"
|
||||
@click="selectProduct(scope.row)"
|
||||
:disabled="form.selectedProduct && form.selectedProduct === scope.row"
|
||||
>
|
||||
{{ form.selectedProduct && form.selectedProduct === scope.row ? '已选中' : '选择' }}
|
||||
</el-button>
|
||||
<span v-if="scope.row.commission">
|
||||
¥{{ formatCommissionAmount(scope.row.commission, scope.row.price) }}
|
||||
</span>
|
||||
<span v-else style="color: #909399;">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</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">
|
||||
<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>
|
||||
<el-descriptions :column="3" border>
|
||||
<el-descriptions-item label="商品名称" :span="3">
|
||||
{{ form.skuName }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="商品类型">
|
||||
<el-tag :type="form.owner === 'g' ? 'success' : 'warning'">
|
||||
{{ form.owner === 'g' ? '自营' : 'POP' }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="SKU ID">
|
||||
{{ form.selectedProduct.skuId || form.selectedProduct.skuid || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="商品价格">
|
||||
<span v-if="form.selectedProduct.price">¥{{ formatPrice(form.selectedProduct.price) }}</span>
|
||||
<span v-else>-</span>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<el-table :data="selectedProducts" border style="margin-top: 10px;" max-height="300">
|
||||
<el-table-column type="index" label="序号" width="60" />
|
||||
<el-table-column label="商品名称" prop="skuName" min-width="250" show-overflow-tooltip>
|
||||
<template slot-scope="scope">
|
||||
{{ scope.row.skuName || scope.row.title || scope.row.productName || scope.row.cleanSkuName || '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="SPU ID" width="120">
|
||||
<template slot-scope="scope">{{ scope.row.spuid || scope.row.spuId || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="SKU ID" width="120">
|
||||
<template slot-scope="scope">{{ scope.row.skuId || scope.row.skuid || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="类型" width="80">
|
||||
<template slot-scope="scope">
|
||||
<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' }}
|
||||
</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-row :gutter="20">
|
||||
@@ -166,7 +190,7 @@
|
||||
</div>
|
||||
<div style="text-align: right;">
|
||||
<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> 批量创建并替换
|
||||
</el-button>
|
||||
</div>
|
||||
@@ -281,10 +305,11 @@ export default {
|
||||
owner: 'g',
|
||||
amount: 1.8, // 默认1.8元
|
||||
quantity: 12, // 默认每个礼金数量为12
|
||||
queryResult: null, // 保存查询到的商品信息
|
||||
selectedProduct: null // 用户选中的商品
|
||||
queryResult: null, // 保存查询到的商品信息(保留兼容性)
|
||||
selectedProduct: null // 用户选中的商品(保留兼容性,用于单个商品)
|
||||
},
|
||||
productList: [], // 查询到的商品列表
|
||||
selectedProducts: [], // 用户选中的商品列表(多选)
|
||||
rules: {
|
||||
materialUrl: [{ required: true, message: '请输入商品链接或SKU', trigger: 'blur' }],
|
||||
amount: [{ required: true, message: '请输入礼金金额', trigger: 'blur' }],
|
||||
@@ -359,12 +384,12 @@ export default {
|
||||
if (products.length > 0) {
|
||||
this.productList = products
|
||||
|
||||
// 如果只有一个商品,自动选中
|
||||
if (products.length === 1) {
|
||||
this.selectProduct(products[0])
|
||||
}
|
||||
// 默认全选所有商品
|
||||
this.$nextTick(() => {
|
||||
this.selectAllProducts()
|
||||
})
|
||||
|
||||
this.$modal.msgSuccess(`查询成功,找到 ${products.length} 个商品,请选择一个用于创建礼金`)
|
||||
this.$modal.msgSuccess(`查询成功,找到 ${products.length} 个商品,已默认全选`)
|
||||
} else {
|
||||
this.$modal.msgWarning('未找到商品信息,请检查链接是否正确')
|
||||
}
|
||||
@@ -383,7 +408,7 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
/** 选择商品 */
|
||||
/** 选择商品(单选,保留兼容性) */
|
||||
selectProduct(product) {
|
||||
this.form.selectedProduct = product
|
||||
this.form.queryResult = product
|
||||
@@ -394,13 +419,86 @@ export default {
|
||||
this.$modal.msgSuccess('已选择商品:' + this.form.skuName + '(' + (this.form.owner === 'g' ? '自营' : 'POP') + ')')
|
||||
},
|
||||
|
||||
/** 表格行选择变化 */
|
||||
handleProductSelect(currentRow) {
|
||||
if (currentRow) {
|
||||
this.selectProduct(currentRow)
|
||||
/** 表格多选变化 */
|
||||
handleSelectionChange(selection) {
|
||||
this.selectedProducts = selection
|
||||
// 如果只选中一个,同步到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) {
|
||||
if (!price) return '0.00'
|
||||
@@ -411,6 +509,29 @@ export default {
|
||||
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 */
|
||||
detectUrls(text) {
|
||||
if (!text || text.trim().length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user