This commit is contained in:
2025-08-20 23:12:44 +08:00
2 changed files with 85 additions and 15 deletions

View File

@@ -362,15 +362,21 @@
<el-button type="primary" @click="submitQuickPublish" :loading="quickPublishLoading"> </el-button>
</div>
</el-dialog>
<!-- 通用发品对话框从常用商品直接进入不显示ERP应用选择 -->
<PublishDialog :visible.sync="publishDialogVisible" :initial-data="publishInitialData" :hideAppid="true" />
</div>
</template>
<script>
import { listFavoriteProduct, getFavoriteProduct, delFavoriteProduct, addFavoriteProduct, updateFavoriteProduct, updateTopStatus, quickPublishFromFavorite } from "@/api/system/favoriteProduct";
import { generatePromotionContent } from "@/api/system/jdorder";
import { mapGetters, mapActions } from 'vuex'
import PublishDialog from '@/components/PublishDialog.vue'
export default {
name: "FavoriteProduct",
components: { PublishDialog },
computed: {
...mapGetters(['favoriteProductRefreshKey'])
},
@@ -437,7 +443,10 @@ export default {
{ label: '闲鱼', value: 'xianyu' },
{ label: '淘宝', value: 'taobao' },
{ label: '京东', value: 'jd' }
]
],
// 通用发品弹窗
publishDialogVisible: false,
publishInitialData: {}
};
},
created() {
@@ -603,9 +612,44 @@ export default {
},
/** 快速发品 */
handleQuickPublish(row) {
this.selectedProduct = row;
this.quickPublishForm.appid = '';
this.quickPublishVisible = true;
// 先用商品链接生成完整商品信息,再打开通用发品弹窗
const id = row.id || this.ids;
getFavoriteProduct(id).then(async res => {
const p = res && res.data ? res.data : (row || {});
try {
let detail = null;
if (p.productUrl) {
const r = await generatePromotionContent({ promotionContent: p.productUrl });
const resultStr = (r && (r.msg || r.data)) || '';
try { const arr = typeof resultStr === 'string' ? JSON.parse(resultStr) : resultStr; if (Array.isArray(arr) && arr.length) detail = arr[0]; } catch(e) {}
}
const images = Array.isArray(detail && detail.images) && detail.images.length ? detail.images : (p.productImage ? [p.productImage] : []);
const wenanArr = Array.isArray(detail && detail.wenan) ? detail.wenan : [];
const wenanOptions = wenanArr.map((w, i) => ({ label: w.type || `版本${i+1}` , content: w.content || '' }));
this.publishInitialData = {
title: (detail && (detail.skuName || detail.title)) || p.productName || '',
content: (wenanOptions[0] && wenanOptions[0].content) || '',
images: images,
originalPrice: detail && detail.price ? Number(detail.price) : (p.price ? Number(p.price) : undefined),
wenanOptions: wenanOptions,
// 预设:同一用户经常固定账号与地区,优先从常用商品扩展字段取值(如有)
userName: p.userName || '',
province: p.province || null,
city: p.city || null,
district: p.district || null
};
this.publishDialogVisible = true;
} catch (e) {
const imagesFallback = p.productImage ? [p.productImage] : [];
this.publishInitialData = { title: p.productName || '', images: imagesFallback, content: '' };
this.publishDialogVisible = true;
}
}).catch(() => {
// 失败也尽量用行数据打开
const images = row && row.productImage ? [row.productImage] : [];
this.publishInitialData = { title: row.productName || '', images, content: '' };
this.publishDialogVisible = true;
});
},
/** 提交快速发品 */
submitQuickPublish() {