This commit is contained in:
2025-08-20 23:19:51 +08:00
parent fe9eff8131
commit fd53ce5c98

View File

@@ -130,7 +130,7 @@
<script>
import { generatePromotionContent } from "@/api/system/jdorder";
import { addToFavorites } from "@/api/system/favoriteProduct";
import { addToFavorites, getBySkuid } from "@/api/system/favoriteProduct";
import PublishDialog from '@/components/PublishDialog.vue'
export default {
@@ -150,6 +150,8 @@ export default {
activeWenanTab: {},
publishDialogVisible: false,
publishInitialData: {},
// 记录正在发品的商品,用于发品成功后自动加入常用
currentPublishProduct: null,
regionOptions: {
provinces: [],
cities: [],
@@ -378,6 +380,8 @@ export default {
openPublish(product, productIndex) {
const wenanIndex = this.activeWenanTab[productIndex] || 0;
const wenanOptions = Array.isArray(product.wenan) ? product.wenan.map((w, i) => ({ label: w.type || `版本${i+1}`, content: w.content || '' })) : [];
// 记录当前发品的商品
this.currentPublishProduct = product;
this.publishInitialData = {
title: product.skuName || '',
content: (product && product.wenan && product.wenan[wenanIndex] ? (product.wenan[wenanIndex].content || '') : ''),
@@ -387,7 +391,48 @@ export default {
};
this.publishDialogVisible = true;
},
handlePublishSuccess() { /* 可按需刷新列表或做其他处理 */ },
async handlePublishSuccess(res) {
try {
const p = this.currentPublishProduct || {};
const data = res && res.data ? res.data : {};
const productId = data.product_id || data.productId || (data.data && (data.data.product_id || data.data.productId));
const productStatus = data.product_status || data.productStatus || (data.data && (data.data.product_status || data.data.productStatus));
const outerId = data.outer_id || data.outerId || (data.data && (data.data.outer_id || data.data.outerId));
// 取spuid优先
const spuid = p.spuid || p.skuId || p.skuid || '';
if (!spuid) return;
// 查重,避免重复加入
try {
const exist = await getBySkuid(spuid);
if (exist && exist.data) {
// 已存在则不重复添加
return;
}
} catch (e) { /* 忽略查重异常 */ }
const favoriteData = {
skuid: spuid,
productName: p.skuName || p.title || '',
shopName: p.shopName || '',
productUrl: p.url || '',
productImage: Array.isArray(p.images) && p.images.length ? p.images[0] : '',
price: (p.price != null ? String(p.price) : (p.lowestCouponPrice != null ? String(p.lowestCouponPrice) : '')),
commissionInfo: p.commissionShare ? `${p.commissionShare}%` : (p.commission != null ? String(p.commission) : ''),
remark: `自动添加 - 发品时间: ${new Date().toLocaleString()}${outerId ? `, 商家编码: ${outerId}` : ''}`,
productId: productId,
productStatus: productStatus
};
const addRes = await addToFavorites(favoriteData);
if (addRes && addRes.code === 200) {
this.$store && this.$store.dispatch && this.$store.dispatch('app/triggerFavoriteProductRefresh');
}
} catch (e) {
// 忽略自动加入失败,不影响发品流程
}
},
onWenanChange(val) {
if (this.publishDialog.wenanOptions && this.publishDialog.wenanOptions[val]) {