1
This commit is contained in:
@@ -367,9 +367,13 @@
|
||||
|
||||
<script>
|
||||
import { listFavoriteProduct, getFavoriteProduct, delFavoriteProduct, addFavoriteProduct, updateFavoriteProduct, updateTopStatus, quickPublishFromFavorite } from "@/api/system/favoriteProduct";
|
||||
import { mapGetters, mapActions } from 'vuex'
|
||||
|
||||
export default {
|
||||
name: "FavoriteProduct",
|
||||
computed: {
|
||||
...mapGetters(['favoriteProductRefreshKey'])
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
@@ -439,6 +443,12 @@ export default {
|
||||
created() {
|
||||
this.getList();
|
||||
},
|
||||
watch: {
|
||||
favoriteProductRefreshKey() {
|
||||
// 全局刷新标记变更时,自动刷新列表
|
||||
this.getList();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/** 查询常用商品列表 */
|
||||
getList() {
|
||||
|
||||
@@ -199,6 +199,7 @@
|
||||
<el-button @click="childDetailVisible = false">关 闭</el-button>
|
||||
<el-button type="primary" @click="openQuickLink(currentChild)" v-if="currentChild.jsonQueryResult">一键转链</el-button>
|
||||
<el-button type="success" @click="addToFavorites(currentChild)" v-if="currentChild.jsonQueryResult">添加到常用</el-button>
|
||||
<el-button type="warning" @click="quickLinkAndAddToFavorites(currentChild)" v-if="currentChild.jsonQueryResult">转链并入常用</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
@@ -275,8 +276,47 @@
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 一键转链对话框 -->
|
||||
<el-dialog class="quick-link-dialog" title="一键转链" :visible.sync="quickLinkVisible" width="1000px" append-to-body>
|
||||
<div v-if="quickLinkProduct">
|
||||
<el-alert type="info" :closable="false" title="当前商品">
|
||||
<template slot="description">
|
||||
<div>
|
||||
<div><strong>名称:</strong>{{ decodeUnicode(quickLinkProduct.skuName) || '-' }}</div>
|
||||
<div><strong>店铺:</strong>{{ getJsonValue(quickLinkProduct.jsonQueryResult, 'shopInfo.shopName') || '-' }}</div>
|
||||
<div><strong>线报价:</strong>{{ quickLinkProduct.firstPrice ? `¥${quickLinkProduct.firstPrice}` : '-' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-alert>
|
||||
</div>
|
||||
<div style="margin: 10px 0;">
|
||||
<el-button type="primary" :loading="quickLinkLoading" @click="generateQuickLink">生成转链内容</el-button>
|
||||
<el-button @click="quickLinkVisible = false">关闭</el-button>
|
||||
</div>
|
||||
<div v-if="Array.isArray(parsedQuickLinkResult) && parsedQuickLinkResult.length">
|
||||
<el-alert title="转链结果" type="success" :closable="false" show-icon />
|
||||
<el-card v-for="(it, idx) in parsedQuickLinkResult" :key="idx" shadow="never" style="margin-top: 10px;">
|
||||
<div style="display:flex; justify-content:space-between; align-items:center; gap:12px; flex-wrap:wrap;">
|
||||
<div style="flex:1 1 auto; min-width: 300px;">
|
||||
<div><strong>SPUID:</strong>{{ it.spuid || '-' }}</div>
|
||||
<div style="margin-top:4px;"><strong>名称:</strong>{{ decodeUnicode(it.skuName || it.title) || '-' }}</div>
|
||||
<div style="margin-top:4px;"><strong>店铺:</strong>{{ it.shopName || '-' }}<span v-if="it.shopId"> (ID: {{ it.shopId }})</span></div>
|
||||
<div style="margin-top:4px;"><strong>价格:</strong>{{ it.price ? `¥${it.price}` : '-' }} <span v-if="it.commissionShare" style="color:#67c23a;">/ 佣金比 {{ it.commissionShare }}%</span></div>
|
||||
<div style="margin-top:4px;"><strong>链接:</strong><el-link v-if="it.materialUrl || it.url" :href="it.materialUrl || it.url" target="_blank">查看</el-link><span v-else>-</span></div>
|
||||
</div>
|
||||
<div style="flex:0 0 auto;">
|
||||
<el-button type="success" size="mini" @click="addQuickLinkItemToFavorites(it)">加入常用</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="quickLinkVisible = false">关 闭</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 公共发品对话框组件复用 -->
|
||||
<PublishDialog :visible.sync="publishDialogVisible" :initial-data="publishInitialData" />
|
||||
<PublishDialog :visible.sync="publishDialogVisible" :initial-data="publishInitialData" @success="onPublishDialogSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -451,6 +491,8 @@ export default {
|
||||
openPublishFromXb(child) {
|
||||
const parsedQuery = this.safeJsonParse(child.jsonQueryResult);
|
||||
const images = (parsedQuery && parsedQuery.images && Array.isArray(parsedQuery.images)) ? parsedQuery.images : [];
|
||||
// 记录当前线报项,便于发品成功后加入常用
|
||||
this.currentXbMessageItem = child;
|
||||
this.publishInitialData = {
|
||||
title: this.decodeUnicode(child.skuName) || '',
|
||||
content: '',
|
||||
@@ -737,6 +779,63 @@ export default {
|
||||
this.$modal.msgError('生成转链内容失败: ' + error.message);
|
||||
});
|
||||
},
|
||||
|
||||
/** 一键转链并自动加入常用(使用返回结构) */
|
||||
async quickLinkAndAddToFavorites(message) {
|
||||
try {
|
||||
this.quickLinkProduct = message;
|
||||
this.quickLinkLoading = true;
|
||||
const payload = {
|
||||
skuName: message.skuName,
|
||||
shopName: this.getJsonValue(message.jsonQueryResult, 'shopInfo.shopName'),
|
||||
firstPrice: message.firstPrice,
|
||||
commission: this.getJsonValue(message.jsonQueryResult, 'commissionInfo.commission'),
|
||||
commissionShare: this.getJsonValue(message.jsonQueryResult, 'commissionInfo.commissionShare'),
|
||||
spuid: this.getJsonValue(message.jsonQueryResult, 'spuid'),
|
||||
url: this.getJsonValue(message.jsonQueryResult, 'url'),
|
||||
wenan: message.wenan,
|
||||
images: message.images
|
||||
};
|
||||
const resp = await this.$axios.post('/api/quickLink/generate', payload);
|
||||
this.quickLinkLoading = false;
|
||||
const resultStr = resp && resp.data && (resp.data.result || resp.data.msg);
|
||||
if (!resultStr) { this.$modal.msgError('生成转链失败'); return; }
|
||||
let arr = [];
|
||||
try { arr = JSON.parse(resultStr); } catch(e) { this.$modal.msgError('返回数据格式错误'); return; }
|
||||
if (!Array.isArray(arr) || arr.length === 0) { this.$modal.msgWarning('无可用转链结果'); return; }
|
||||
const r0 = arr[0];
|
||||
// 直接用返回的结构添加到常用(使用spuid)
|
||||
const spuid = r0.spuid || this.getJsonValue(message.jsonQueryResult, 'spuid') || '';
|
||||
const favoriteData = {
|
||||
skuid: spuid,
|
||||
productName: r0.skuName || r0.title || message.skuName || '',
|
||||
shopName: r0.shopName || '',
|
||||
shopId: r0.shopId || '',
|
||||
productUrl: r0.materialUrl || r0.url || '',
|
||||
productImage: Array.isArray(r0.images) && r0.images.length ? r0.images[0] : '',
|
||||
price: r0.price || message.firstPrice || '',
|
||||
commissionInfo: r0.commissionShare ? `${r0.commissionShare}%` : (r0.commission || ''),
|
||||
category: '',
|
||||
brand: '',
|
||||
remark: '来自一键转链',
|
||||
isTop: 0,
|
||||
sortWeight: 0
|
||||
};
|
||||
// 查重
|
||||
const exist = await getBySkuid(spuid);
|
||||
if (exist && exist.data) { this.$modal.msgWarning('该商品已在常用列表中'); return; }
|
||||
const addRes = await addToFavorites(favoriteData);
|
||||
if (addRes && addRes.code === 200) {
|
||||
this.$modal.msgSuccess('转链成功并已加入常用');
|
||||
this.$store.dispatch('app/triggerFavoriteProductRefresh');
|
||||
} else {
|
||||
this.$modal.msgError((addRes && addRes.msg) || '加入常用失败');
|
||||
}
|
||||
} catch(e) {
|
||||
this.quickLinkLoading = false;
|
||||
this.$modal.msgError('转链或加入常用失败');
|
||||
}
|
||||
},
|
||||
/** 解析转链结果 */
|
||||
parseQuickLinkResult(result) {
|
||||
try {
|
||||
@@ -846,7 +945,7 @@ export default {
|
||||
expressFee: this.cents(this.quickLinkPublishDialog.form.expressFee) || undefined,
|
||||
stock: this.quickLinkPublishDialog.form.stock || undefined,
|
||||
outerId: this.quickLinkPublishDialog.form.outerId || undefined, // 如果为空,后端自动生成
|
||||
skuid: this.currentXbMessageItem?.skuid || undefined, // 传递skuid给后端
|
||||
skuid: this.getJsonValue(this.currentXbMessageItem?.jsonQueryResult, 'spuid') || this.currentXbMessageItem?.spuid || this.currentXbMessageItem?.skuid || undefined, // 优先使用spuid
|
||||
itemBizType: this.quickLinkPublishDialog.form.itemBizType || undefined,
|
||||
spBizType: this.quickLinkPublishDialog.form.spBizType || undefined,
|
||||
channelCatId: this.quickLinkPublishDialog.form.channelCatId || undefined,
|
||||
@@ -912,6 +1011,13 @@ export default {
|
||||
onQuickLinkAppidChange(appid) {
|
||||
this.quickLinkPublishDialog.form.appid = appid;
|
||||
this.loadUserNameOptions(appid);
|
||||
// 应用切换时,重置类目与属性
|
||||
this.quickLinkPublishDialog.form.channelCatId = null;
|
||||
this.quickLinkPublishDialog.form.channelPvJson = '';
|
||||
this.categoryOptions = [];
|
||||
this.selectedPv = {};
|
||||
// 有必要时重新拉取类目
|
||||
this.loadCategoryOptions(this.quickLinkPublishDialog.form.itemBizType);
|
||||
},
|
||||
/** 加载会员名选项 */
|
||||
loadUserNameOptions(appid) {
|
||||
@@ -925,6 +1031,12 @@ export default {
|
||||
this.userNameLoading = false;
|
||||
});
|
||||
},
|
||||
/** 类目选择变化时,清空属性 JSON 并拉取属性 */
|
||||
onQuickLinkCategoryChange() {
|
||||
this.quickLinkPublishDialog.form.channelPvJson = '';
|
||||
this.selectedPv = {};
|
||||
this.loadQuickLinkProperties();
|
||||
},
|
||||
/** 切换省 */
|
||||
async onQuickLinkProvinceChange(province) {
|
||||
this.quickLinkPublishDialog.form.city = null;
|
||||
@@ -995,16 +1107,21 @@ export default {
|
||||
onQuickLinkSpBizTypeChange(spBizType) {
|
||||
this.quickLinkPublishDialog.form.channelPvJson = ''; // 清空属性
|
||||
this.selectedPv = {};
|
||||
// 行业类型变化后,若已选商品类型且已选应用,则拉取类目
|
||||
this.loadCategoryOptions(this.quickLinkPublishDialog.form.itemBizType);
|
||||
},
|
||||
/** 加载类目选项 */
|
||||
loadCategoryOptions(itemBizType) {
|
||||
this.categoryOptions = [];
|
||||
// 需要具备 itemBizType、spBizType、appid
|
||||
const spBizType = this.quickLinkPublishDialog.form.spBizType;
|
||||
const appid = this.quickLinkPublishDialog.form.appid;
|
||||
if (!itemBizType || !spBizType || !appid) {
|
||||
this.categoryLoading = false;
|
||||
return;
|
||||
}
|
||||
this.categoryLoading = true;
|
||||
const params = {
|
||||
itemBizType,
|
||||
spBizType: this.quickLinkPublishDialog.form.spBizType,
|
||||
appid: this.quickLinkPublishDialog.form.appid
|
||||
};
|
||||
const params = { itemBizType, spBizType, appid };
|
||||
getCategories(params).then(response => {
|
||||
if (response.code === 200) this.categoryOptions = response.data || [];
|
||||
else this.$modal.msgError(response.msg || '加载类目失败');
|
||||
@@ -1018,13 +1135,15 @@ export default {
|
||||
loadQuickLinkProperties() {
|
||||
this.quickLinkPublishDialog.pvOptions = [];
|
||||
this.selectedPv = {};
|
||||
if (this.quickLinkPublishDialog.form.channelCatId) {
|
||||
this.$axios.get('/api/property/options', { params: { channelCatId: this.quickLinkPublishDialog.form.channelCatId } }).then(response => {
|
||||
this.quickLinkPublishDialog.pvOptions = response.data || [];
|
||||
}).catch(error => {
|
||||
this.$modal.msgError('加载属性失败: ' + error.message);
|
||||
});
|
||||
}
|
||||
const channelCatId = this.quickLinkPublishDialog.form.channelCatId;
|
||||
if (!channelCatId) return;
|
||||
// 保护:若类目ID非数字或空,直接返回
|
||||
if (channelCatId === '' || channelCatId == null) return;
|
||||
this.$axios.get('/api/property/options', { params: { channelCatId } }).then(response => {
|
||||
this.quickLinkPublishDialog.pvOptions = response.data || [];
|
||||
}).catch(error => {
|
||||
this.$modal.msgError('加载属性失败: ' + (error && error.message ? error.message : ''));
|
||||
});
|
||||
},
|
||||
/** 切换属性 */
|
||||
onQuickLinkPvChange(value) {
|
||||
@@ -1150,6 +1269,37 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
/** 从转链结果加入常用 */
|
||||
async addQuickLinkItemToFavorites(it) {
|
||||
try {
|
||||
const spuid = it.spuid || '';
|
||||
if (!spuid) { this.$modal.msgError('缺少SPUID'); return; }
|
||||
const exist = await getBySkuid(spuid);
|
||||
if (exist && exist.data) { this.$modal.msgWarning('该商品已在常用列表中'); return; }
|
||||
const favoriteData = {
|
||||
skuid: spuid,
|
||||
productName: it.skuName || it.title || '',
|
||||
shopName: it.shopName || '',
|
||||
shopId: it.shopId || '',
|
||||
productUrl: it.materialUrl || it.url || '',
|
||||
productImage: Array.isArray(it.images) && it.images.length ? it.images[0] : '',
|
||||
price: it.price || '',
|
||||
commissionInfo: it.commissionShare ? `${it.commissionShare}%` : (it.commission || ''),
|
||||
remark: '来自一键转链',
|
||||
isTop: 0,
|
||||
sortWeight: 0
|
||||
};
|
||||
const addRes = await addToFavorites(favoriteData);
|
||||
if (addRes && addRes.code === 200) {
|
||||
this.$modal.msgSuccess('已加入常用');
|
||||
this.$store.dispatch('app/triggerFavoriteProductRefresh');
|
||||
} else {
|
||||
this.$modal.msgError((addRes && addRes.msg) || '加入常用失败');
|
||||
}
|
||||
} catch(e) {
|
||||
this.$modal.msgError('加入常用失败');
|
||||
}
|
||||
},
|
||||
|
||||
/** 预览图片 */
|
||||
handlePreviewImage(imageUrl) {
|
||||
@@ -1454,7 +1604,7 @@ export default {
|
||||
|
||||
// 构建常用商品数据
|
||||
const favoriteData = {
|
||||
skuid: currentItem.skuid || '',
|
||||
skuid: this.getJsonValue(currentItem.jsonQueryResult, 'spuid') || currentItem.spuid || currentItem.skuid || '',
|
||||
productName: currentItem.skuName || currentItem.productName || '',
|
||||
shopName: this.getShopName(currentItem),
|
||||
shopId: this.getShopId(currentItem),
|
||||
@@ -1479,6 +1629,21 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
/** 接收通用发品弹窗成功事件:等待接口返回后自动加常用,但不关闭页面 */
|
||||
onPublishDialogSuccess(res) {
|
||||
try {
|
||||
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));
|
||||
if (productId) {
|
||||
this.addToFavoritesAfterPublish(productId, productStatus, outerId);
|
||||
// 触发全局常用商品列表刷新
|
||||
this.$store.dispatch('app/triggerFavoriteProductRefresh');
|
||||
}
|
||||
} catch (e) { /* 忽略解析异常 */ }
|
||||
},
|
||||
|
||||
/** 获取店铺名称 */
|
||||
getShopName(item) {
|
||||
if (item.jsonShopInfo) {
|
||||
@@ -1520,7 +1685,8 @@ export default {
|
||||
async addToFavorites(child) {
|
||||
try {
|
||||
// 检查是否已经添加到常用
|
||||
const existingProduct = await getBySkuid(child.skuid);
|
||||
const spuid = this.getJsonValue(child.jsonQueryResult, 'spuid') || child.spuid || child.skuid;
|
||||
const existingProduct = await getBySkuid(spuid);
|
||||
if (existingProduct && existingProduct.data) {
|
||||
this.$modal.msgWarning("该商品已在常用列表中");
|
||||
return;
|
||||
@@ -1528,7 +1694,7 @@ export default {
|
||||
|
||||
// 构建常用商品数据
|
||||
const favoriteData = {
|
||||
skuid: child.skuid,
|
||||
skuid: spuid,
|
||||
productName: child.skuName,
|
||||
shopName: this.getJsonValue(child.jsonQueryResult, 'shopInfo.shopName') || '',
|
||||
shopId: this.getJsonValue(child.jsonQueryResult, 'shopInfo.shopId') || '',
|
||||
|
||||
Reference in New Issue
Block a user