1
This commit is contained in:
@@ -1,5 +1,56 @@
|
|||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 列表
|
||||||
|
export function listFavoriteProduct(query) {
|
||||||
|
return request({
|
||||||
|
url: '/jarvis/favoriteProduct/list',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 详情
|
||||||
|
export function getFavoriteProduct(id) {
|
||||||
|
return request({
|
||||||
|
url: `/jarvis/favoriteProduct/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增
|
||||||
|
export function addFavoriteProduct(data) {
|
||||||
|
return request({
|
||||||
|
url: '/jarvis/favoriteProduct',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改
|
||||||
|
export function updateFavoriteProduct(data) {
|
||||||
|
return request({
|
||||||
|
url: '/jarvis/favoriteProduct',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
export function delFavoriteProduct(ids) {
|
||||||
|
return request({
|
||||||
|
url: `/jarvis/favoriteProduct/${ids}`,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新置顶状态
|
||||||
|
export function updateTopStatus(id, isTop) {
|
||||||
|
return request({
|
||||||
|
url: `/jarvis/favoriteProduct/updateTopStatus/${id}/${isTop}`,
|
||||||
|
method: 'put'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 添加到常用商品
|
// 添加到常用商品
|
||||||
export function addToFavorites(data) {
|
export function addToFavorites(data) {
|
||||||
return request({
|
return request({
|
||||||
@@ -9,17 +60,24 @@ export function addToFavorites(data) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新发品信息(商品ID、状态等)
|
// 根据skuid查询是否已存在
|
||||||
export function updateProductInfo(data) {
|
export function getBySkuid(skuid) {
|
||||||
return request({
|
return request({
|
||||||
url: '/jarvis/favoriteProduct/updateProductInfo',
|
url: `/jarvis/favoriteProduct/getBySkuid/${encodeURIComponent(skuid)}`,
|
||||||
method: 'put',
|
method: 'get'
|
||||||
data
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户的常用商品列表
|
||||||
|
export function getUserFavorites() {
|
||||||
|
return request({
|
||||||
|
url: '/jarvis/favoriteProduct/userFavorites',
|
||||||
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从常用商品快速发品
|
// 从常用商品快速发品
|
||||||
export function quickPublish(id, appid) {
|
export function quickPublishFromFavorite(id, appid) {
|
||||||
return request({
|
return request({
|
||||||
url: `/jarvis/favoriteProduct/quickPublish/${id}`,
|
url: `/jarvis/favoriteProduct/quickPublish/${id}`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
@@ -27,4 +85,11 @@ export function quickPublish(id, appid) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新发品信息(商品ID、状态等)
|
||||||
|
export function updateProductInfo(data) {
|
||||||
|
return request({
|
||||||
|
url: '/jarvis/favoriteProduct/updateProductInfo',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -112,9 +112,32 @@
|
|||||||
<el-input type="textarea" :rows="3" v-model="form.channelPvJson" placeholder='示例: [{"property_id":"p","property_name":"颜色","value_id":"v","value_name":"红"}]' />
|
<el-input type="textarea" :rows="3" v-model="form.channelPvJson" placeholder='示例: [{"property_id":"p","property_name":"颜色","value_id":"v","value_name":"红"}]' />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
<el-alert
|
||||||
|
v-if="createdProduct"
|
||||||
|
:title="`商品ID:${createdProduct.productId || '-'}`"
|
||||||
|
type="success"
|
||||||
|
:closable="false"
|
||||||
|
show-icon
|
||||||
|
style="margin: 10px 0;"
|
||||||
|
>
|
||||||
|
<template slot="description">
|
||||||
|
<div style="display:flex; align-items:center; flex-wrap:wrap; gap:12px;">
|
||||||
|
<span>状态:{{ createdProduct.productStatus || '-' }}</span>
|
||||||
|
<span>商家编码:{{ createdProduct.outerId || '-' }}</span>
|
||||||
|
<el-button type="text" size="mini" @click="copyText(String(createdProduct.productId || ''))">复制ID</el-button>
|
||||||
|
<el-button type="text" size="mini" @click="copyText(String(createdProduct.outerId || ''))">复制商家编码</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-alert>
|
||||||
<div slot="footer" class="dialog-footer">
|
<div slot="footer" class="dialog-footer">
|
||||||
<el-button @click="closeDialog">取 消</el-button>
|
<el-button @click="closeDialog">取 消</el-button>
|
||||||
<el-button type="primary" :loading="loading" @click="submitPublish">确 认</el-button>
|
<el-button type="primary" :loading="loading" @click="submitPublish">确 认</el-button>
|
||||||
|
<el-button
|
||||||
|
type="warning"
|
||||||
|
v-if="createdProduct && createdProduct.productId"
|
||||||
|
:loading="publishLoading"
|
||||||
|
@click="publishNow"
|
||||||
|
>上 架</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
@@ -132,6 +155,8 @@ export default {
|
|||||||
return {
|
return {
|
||||||
internalVisible: false,
|
internalVisible: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
publishLoading: false,
|
||||||
|
createdProduct: null,
|
||||||
wenanOptions: [],
|
wenanOptions: [],
|
||||||
productImages: [],
|
productImages: [],
|
||||||
form: {
|
form: {
|
||||||
@@ -236,6 +261,22 @@ export default {
|
|||||||
'form.channelCatId'(val) { this.loadProperties(); }
|
'form.channelCatId'(val) { this.loadProperties(); }
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
copyText(text) {
|
||||||
|
const val = String(text || '').trim();
|
||||||
|
if (!val) { this.$modal.msgWarning('无可复制的内容'); return; }
|
||||||
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
|
navigator.clipboard.writeText(val).then(() => { this.$modal.msgSuccess('复制成功'); }).catch(() => { this.fallbackCopy(val); });
|
||||||
|
} else {
|
||||||
|
this.fallbackCopy(val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fallbackCopy(text) {
|
||||||
|
const ta = document.createElement('textarea');
|
||||||
|
ta.value = text; ta.style.position = 'fixed'; ta.style.left = '-9999px';
|
||||||
|
document.body.appendChild(ta); ta.focus(); ta.select();
|
||||||
|
try { document.execCommand('copy'); this.$modal.msgSuccess('复制成功'); } catch(e){ this.$modal.msgError('复制失败'); }
|
||||||
|
document.body.removeChild(ta);
|
||||||
|
},
|
||||||
async bootstrap() {
|
async bootstrap() {
|
||||||
// 初始化表单与文案/图片
|
// 初始化表单与文案/图片
|
||||||
const d = this.initialData || {};
|
const d = this.initialData || {};
|
||||||
@@ -349,25 +390,32 @@ export default {
|
|||||||
const outerId = res.data && (res.data.outerId || (res.data.data && res.data.data.outerId));
|
const outerId = res.data && (res.data.outerId || (res.data.data && res.data.data.outerId));
|
||||||
if (outerId) this.$modal.msgSuccess(`发品成功,商家编码:${outerId}`); else this.$modal.msgSuccess('发品提交成功');
|
if (outerId) this.$modal.msgSuccess(`发品成功,商家编码:${outerId}`); else this.$modal.msgSuccess('发品提交成功');
|
||||||
} catch(e){ this.$modal.msgSuccess('发品提交成功'); }
|
} catch(e){ this.$modal.msgSuccess('发品提交成功'); }
|
||||||
// 自动上架(需要返回的 productId 与 userName)
|
// 记录创建成功的商品,保留弹窗供手动“上架”
|
||||||
try {
|
const productId = this.extractProductId(res.data) || (res.data && (res.data.product_id || (res.data.data && res.data.data.product_id)));
|
||||||
const productId = this.extractProductId(res.data);
|
const productStatus = res.data && (res.data.product_status || (res.data.data && res.data.data.product_status));
|
||||||
if (productId && this.form.userName) {
|
const outerId2 = res.data && (res.data.outerId || res.data.outer_id || (res.data.data && (res.data.data.outerId || res.data.data.outer_id)));
|
||||||
const pubRes = await publishProduct({ productId, userName: this.form.userName, appid: this.form.appid });
|
this.createdProduct = { productId, productStatus, outerId: outerId2 };
|
||||||
if (pubRes && pubRes.code === 200) {
|
|
||||||
const code = (pubRes.data && pubRes.data.code) ?? pubRes.code;
|
|
||||||
if (code === 0 || code === 200) this.$modal.msgSuccess('上架成功'); else this.$modal.msgWarning('上架已提交或状态未知');
|
|
||||||
} else {
|
|
||||||
this.$modal.msgError((pubRes && pubRes.msg) || '上架失败');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) { /* 忽略上架异常,仅提示 */ }
|
|
||||||
this.$emit('success', res);
|
this.$emit('success', res);
|
||||||
this.closeDialog();
|
|
||||||
} else { this.$modal.msgError(res.msg || '发品失败'); }
|
} else { this.$modal.msgError(res.msg || '发品失败'); }
|
||||||
}).catch(err => { this.loading = false; console.error('发品失败', err); this.$modal.msgError('发品失败,请稍后重试'); });
|
}).catch(err => { this.loading = false; console.error('发品失败', err); this.$modal.msgError('发品失败,请稍后重试'); });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
async publishNow() {
|
||||||
|
if (!this.createdProduct || !this.createdProduct.productId) return;
|
||||||
|
this.publishLoading = true;
|
||||||
|
try {
|
||||||
|
const pubRes = await publishProduct({ productId: this.createdProduct.productId, userName: this.form.userName, appid: this.form.appid });
|
||||||
|
if (pubRes && pubRes.code === 200) {
|
||||||
|
const code = (pubRes.data && pubRes.data.code) ?? pubRes.code;
|
||||||
|
if (code === 0 || code === 200) this.$modal.msgSuccess('上架成功'); else this.$modal.msgWarning('上架已提交或状态未知');
|
||||||
|
} else {
|
||||||
|
this.$modal.msgError((pubRes && pubRes.msg) || '上架失败');
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
this.$modal.msgError('上架失败');
|
||||||
|
}
|
||||||
|
this.publishLoading = false;
|
||||||
|
},
|
||||||
extractProductId(resp) {
|
extractProductId(resp) {
|
||||||
try {
|
try {
|
||||||
if (!resp) return null;
|
if (!resp) return null;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const getters = {
|
|||||||
permission_routes: state => state.permission.routes,
|
permission_routes: state => state.permission.routes,
|
||||||
topbarRouters: state => state.permission.topbarRouters,
|
topbarRouters: state => state.permission.topbarRouters,
|
||||||
defaultRoutes: state => state.permission.defaultRoutes,
|
defaultRoutes: state => state.permission.defaultRoutes,
|
||||||
sidebarRouters: state => state.permission.sidebarRouters
|
sidebarRouters: state => state.permission.sidebarRouters,
|
||||||
|
favoriteProductRefreshKey: state => state.app.favoriteProductRefreshKey
|
||||||
}
|
}
|
||||||
export default getters
|
export default getters
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ const state = {
|
|||||||
hide: false
|
hide: false
|
||||||
},
|
},
|
||||||
device: 'desktop',
|
device: 'desktop',
|
||||||
size: Cookies.get('size') || 'medium'
|
size: Cookies.get('size') || 'medium',
|
||||||
|
// 全局刷新标记:常用商品列表
|
||||||
|
favoriteProductRefreshKey: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const mutations = {
|
const mutations = {
|
||||||
@@ -37,6 +39,9 @@ const mutations = {
|
|||||||
},
|
},
|
||||||
SET_SIDEBAR_HIDE: (state, status) => {
|
SET_SIDEBAR_HIDE: (state, status) => {
|
||||||
state.sidebar.hide = status
|
state.sidebar.hide = status
|
||||||
|
},
|
||||||
|
INCREMENT_FAVORITE_PRODUCT_REFRESH_KEY: (state) => {
|
||||||
|
state.favoriteProductRefreshKey++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +60,9 @@ const actions = {
|
|||||||
},
|
},
|
||||||
toggleSideBarHide({ commit }, status) {
|
toggleSideBarHide({ commit }, status) {
|
||||||
commit('SET_SIDEBAR_HIDE', status)
|
commit('SET_SIDEBAR_HIDE', status)
|
||||||
|
},
|
||||||
|
triggerFavoriteProductRefresh({ commit }) {
|
||||||
|
commit('INCREMENT_FAVORITE_PRODUCT_REFRESH_KEY')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -367,9 +367,13 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listFavoriteProduct, getFavoriteProduct, delFavoriteProduct, addFavoriteProduct, updateFavoriteProduct, updateTopStatus, quickPublishFromFavorite } from "@/api/system/favoriteProduct";
|
import { listFavoriteProduct, getFavoriteProduct, delFavoriteProduct, addFavoriteProduct, updateFavoriteProduct, updateTopStatus, quickPublishFromFavorite } from "@/api/system/favoriteProduct";
|
||||||
|
import { mapGetters, mapActions } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "FavoriteProduct",
|
name: "FavoriteProduct",
|
||||||
|
computed: {
|
||||||
|
...mapGetters(['favoriteProductRefreshKey'])
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
// 遮罩层
|
// 遮罩层
|
||||||
@@ -439,6 +443,12 @@ export default {
|
|||||||
created() {
|
created() {
|
||||||
this.getList();
|
this.getList();
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
favoriteProductRefreshKey() {
|
||||||
|
// 全局刷新标记变更时,自动刷新列表
|
||||||
|
this.getList();
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/** 查询常用商品列表 */
|
/** 查询常用商品列表 */
|
||||||
getList() {
|
getList() {
|
||||||
|
|||||||
@@ -199,6 +199,7 @@
|
|||||||
<el-button @click="childDetailVisible = false">关 闭</el-button>
|
<el-button @click="childDetailVisible = false">关 闭</el-button>
|
||||||
<el-button type="primary" @click="openQuickLink(currentChild)" v-if="currentChild.jsonQueryResult">一键转链</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="success" @click="addToFavorites(currentChild)" v-if="currentChild.jsonQueryResult">添加到常用</el-button>
|
||||||
|
<el-button type="warning" @click="quickLinkAndAddToFavorites(currentChild)" v-if="currentChild.jsonQueryResult">转链并入常用</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
@@ -275,8 +276,47 @@
|
|||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -451,6 +491,8 @@ export default {
|
|||||||
openPublishFromXb(child) {
|
openPublishFromXb(child) {
|
||||||
const parsedQuery = this.safeJsonParse(child.jsonQueryResult);
|
const parsedQuery = this.safeJsonParse(child.jsonQueryResult);
|
||||||
const images = (parsedQuery && parsedQuery.images && Array.isArray(parsedQuery.images)) ? parsedQuery.images : [];
|
const images = (parsedQuery && parsedQuery.images && Array.isArray(parsedQuery.images)) ? parsedQuery.images : [];
|
||||||
|
// 记录当前线报项,便于发品成功后加入常用
|
||||||
|
this.currentXbMessageItem = child;
|
||||||
this.publishInitialData = {
|
this.publishInitialData = {
|
||||||
title: this.decodeUnicode(child.skuName) || '',
|
title: this.decodeUnicode(child.skuName) || '',
|
||||||
content: '',
|
content: '',
|
||||||
@@ -737,6 +779,63 @@ export default {
|
|||||||
this.$modal.msgError('生成转链内容失败: ' + error.message);
|
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) {
|
parseQuickLinkResult(result) {
|
||||||
try {
|
try {
|
||||||
@@ -846,7 +945,7 @@ export default {
|
|||||||
expressFee: this.cents(this.quickLinkPublishDialog.form.expressFee) || undefined,
|
expressFee: this.cents(this.quickLinkPublishDialog.form.expressFee) || undefined,
|
||||||
stock: this.quickLinkPublishDialog.form.stock || undefined,
|
stock: this.quickLinkPublishDialog.form.stock || undefined,
|
||||||
outerId: this.quickLinkPublishDialog.form.outerId || 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,
|
itemBizType: this.quickLinkPublishDialog.form.itemBizType || undefined,
|
||||||
spBizType: this.quickLinkPublishDialog.form.spBizType || undefined,
|
spBizType: this.quickLinkPublishDialog.form.spBizType || undefined,
|
||||||
channelCatId: this.quickLinkPublishDialog.form.channelCatId || undefined,
|
channelCatId: this.quickLinkPublishDialog.form.channelCatId || undefined,
|
||||||
@@ -912,6 +1011,13 @@ export default {
|
|||||||
onQuickLinkAppidChange(appid) {
|
onQuickLinkAppidChange(appid) {
|
||||||
this.quickLinkPublishDialog.form.appid = appid;
|
this.quickLinkPublishDialog.form.appid = appid;
|
||||||
this.loadUserNameOptions(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) {
|
loadUserNameOptions(appid) {
|
||||||
@@ -925,6 +1031,12 @@ export default {
|
|||||||
this.userNameLoading = false;
|
this.userNameLoading = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/** 类目选择变化时,清空属性 JSON 并拉取属性 */
|
||||||
|
onQuickLinkCategoryChange() {
|
||||||
|
this.quickLinkPublishDialog.form.channelPvJson = '';
|
||||||
|
this.selectedPv = {};
|
||||||
|
this.loadQuickLinkProperties();
|
||||||
|
},
|
||||||
/** 切换省 */
|
/** 切换省 */
|
||||||
async onQuickLinkProvinceChange(province) {
|
async onQuickLinkProvinceChange(province) {
|
||||||
this.quickLinkPublishDialog.form.city = null;
|
this.quickLinkPublishDialog.form.city = null;
|
||||||
@@ -995,16 +1107,21 @@ export default {
|
|||||||
onQuickLinkSpBizTypeChange(spBizType) {
|
onQuickLinkSpBizTypeChange(spBizType) {
|
||||||
this.quickLinkPublishDialog.form.channelPvJson = ''; // 清空属性
|
this.quickLinkPublishDialog.form.channelPvJson = ''; // 清空属性
|
||||||
this.selectedPv = {};
|
this.selectedPv = {};
|
||||||
|
// 行业类型变化后,若已选商品类型且已选应用,则拉取类目
|
||||||
|
this.loadCategoryOptions(this.quickLinkPublishDialog.form.itemBizType);
|
||||||
},
|
},
|
||||||
/** 加载类目选项 */
|
/** 加载类目选项 */
|
||||||
loadCategoryOptions(itemBizType) {
|
loadCategoryOptions(itemBizType) {
|
||||||
this.categoryOptions = [];
|
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;
|
this.categoryLoading = true;
|
||||||
const params = {
|
const params = { itemBizType, spBizType, appid };
|
||||||
itemBizType,
|
|
||||||
spBizType: this.quickLinkPublishDialog.form.spBizType,
|
|
||||||
appid: this.quickLinkPublishDialog.form.appid
|
|
||||||
};
|
|
||||||
getCategories(params).then(response => {
|
getCategories(params).then(response => {
|
||||||
if (response.code === 200) this.categoryOptions = response.data || [];
|
if (response.code === 200) this.categoryOptions = response.data || [];
|
||||||
else this.$modal.msgError(response.msg || '加载类目失败');
|
else this.$modal.msgError(response.msg || '加载类目失败');
|
||||||
@@ -1018,13 +1135,15 @@ export default {
|
|||||||
loadQuickLinkProperties() {
|
loadQuickLinkProperties() {
|
||||||
this.quickLinkPublishDialog.pvOptions = [];
|
this.quickLinkPublishDialog.pvOptions = [];
|
||||||
this.selectedPv = {};
|
this.selectedPv = {};
|
||||||
if (this.quickLinkPublishDialog.form.channelCatId) {
|
const channelCatId = this.quickLinkPublishDialog.form.channelCatId;
|
||||||
this.$axios.get('/api/property/options', { params: { channelCatId: this.quickLinkPublishDialog.form.channelCatId } }).then(response => {
|
if (!channelCatId) return;
|
||||||
this.quickLinkPublishDialog.pvOptions = response.data || [];
|
// 保护:若类目ID非数字或空,直接返回
|
||||||
}).catch(error => {
|
if (channelCatId === '' || channelCatId == null) return;
|
||||||
this.$modal.msgError('加载属性失败: ' + error.message);
|
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) {
|
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) {
|
handlePreviewImage(imageUrl) {
|
||||||
@@ -1454,7 +1604,7 @@ export default {
|
|||||||
|
|
||||||
// 构建常用商品数据
|
// 构建常用商品数据
|
||||||
const favoriteData = {
|
const favoriteData = {
|
||||||
skuid: currentItem.skuid || '',
|
skuid: this.getJsonValue(currentItem.jsonQueryResult, 'spuid') || currentItem.spuid || currentItem.skuid || '',
|
||||||
productName: currentItem.skuName || currentItem.productName || '',
|
productName: currentItem.skuName || currentItem.productName || '',
|
||||||
shopName: this.getShopName(currentItem),
|
shopName: this.getShopName(currentItem),
|
||||||
shopId: this.getShopId(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) {
|
getShopName(item) {
|
||||||
if (item.jsonShopInfo) {
|
if (item.jsonShopInfo) {
|
||||||
@@ -1520,7 +1685,8 @@ export default {
|
|||||||
async addToFavorites(child) {
|
async addToFavorites(child) {
|
||||||
try {
|
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) {
|
if (existingProduct && existingProduct.data) {
|
||||||
this.$modal.msgWarning("该商品已在常用列表中");
|
this.$modal.msgWarning("该商品已在常用列表中");
|
||||||
return;
|
return;
|
||||||
@@ -1528,7 +1694,7 @@ export default {
|
|||||||
|
|
||||||
// 构建常用商品数据
|
// 构建常用商品数据
|
||||||
const favoriteData = {
|
const favoriteData = {
|
||||||
skuid: child.skuid,
|
skuid: spuid,
|
||||||
productName: child.skuName,
|
productName: child.skuName,
|
||||||
shopName: this.getJsonValue(child.jsonQueryResult, 'shopInfo.shopName') || '',
|
shopName: this.getJsonValue(child.jsonQueryResult, 'shopInfo.shopName') || '',
|
||||||
shopId: this.getJsonValue(child.jsonQueryResult, 'shopInfo.shopId') || '',
|
shopId: this.getJsonValue(child.jsonQueryResult, 'shopInfo.shopId') || '',
|
||||||
|
|||||||
Reference in New Issue
Block a user