This commit is contained in:
雷欧(林平凡)
2025-08-20 18:00:56 +08:00
parent 3a441bddc2
commit af966956a2
2 changed files with 85 additions and 15 deletions

View File

@@ -6,7 +6,7 @@
<el-option v-for="(opt, idx) in wenanOptions" :key="idx" :label="opt.label" :value="idx" />
</el-select>
</el-form-item>
<el-form-item label="闲管家账号">
<el-form-item label="闲管家账号" v-if="!hideAppid">
<el-select v-model="form.appid" filterable placeholder="选择ERP应用" :loading="erpAccountLoading" @change="onAppidChange">
<el-option v-for="a in erpAccountsOptions" :key="a.value" :label="a.label" :value="a.value" />
</el-select>
@@ -149,7 +149,8 @@ export default {
name: 'PublishDialog',
props: {
visible: { type: Boolean, default: false },
initialData: { type: Object, default: () => ({}) }
initialData: { type: Object, default: () => ({}) },
hideAppid: { type: Boolean, default: false }
},
data() {
return {
@@ -162,9 +163,9 @@ export default {
form: {
appid: '',
userName: '',
province: 440000,
city: 440400,
district: 440402,
province: null,
city: null,
district: null,
title: '',
content: '',
wenanIndex: 0,
@@ -291,6 +292,11 @@ export default {
if (typeof d.originalPrice === 'number') {
this.form.originalPrice = d.originalPrice;
}
// 预设:会员名、省市区
if (d.userName) this.form.userName = d.userName;
if (d.province) this.form.province = d.province;
if (d.city) this.form.city = d.city;
if (d.district) this.form.district = d.district;
await this.loadProvinces();
await this.loadERPAccounts();
await this.loadUsernames();
@@ -307,25 +313,45 @@ export default {
handleCopyImageUrl(imageUrl) { if (navigator.clipboard) { navigator.clipboard.writeText(imageUrl).then(() => { this.$modal.msgSuccess('图片链接复制成功'); }).catch(() => { this.$message.error('复制失败'); }); } },
handlePreviewImage(imageUrl) { window.open(imageUrl, '_blank'); },
async loadProvinces(echo = true) {
try { const res = await getProvinces(); if (res.code === 200) this.regionOptions.provinces = res.data || []; else this.$modal.msgError(res.msg || '加载省份失败'); } catch(e){ this.$modal.msgError('加载省份失败'); }
if (echo && this.form.province) { await this.loadCities(this.form.province, true); } else { this.regionOptions.cities = []; this.regionOptions.areas = []; this.form.city = null; this.form.district = null; }
try {
const res = await getProvinces();
if (res.code === 200) this.regionOptions.provinces = res.data || []; else this.$modal.msgError(res.msg || '加载省份失败');
} catch(e){ this.$modal.msgError('加载省份失败'); }
if (!this.form.province && this.regionOptions.provinces.length) {
this.form.province = this.regionOptions.provinces[0].value;
}
if (this.form.province) { await this.loadCities(this.form.province, true); } else { this.regionOptions.cities = []; this.regionOptions.areas = []; this.form.city = null; this.form.district = null; }
},
async onProvinceChange() { await this.loadCities(this.form.province, false); },
async onCityChange() { await this.loadAreas(this.form.province, this.form.city, false); },
async loadCities(provId, echo = false) {
if (!provId) { this.regionOptions.cities = []; this.regionOptions.areas = []; this.form.city = null; this.form.district = null; return; }
try { const res = await getCities(provId); if (res.code === 200) this.regionOptions.cities = res.data || []; else this.$modal.msgError(res.msg || '加载城市失败'); } catch(e){ this.$modal.msgError('加载城市失败'); }
if (echo && this.form.city) { await this.loadAreas(provId, this.form.city, true); } else { this.regionOptions.areas = []; this.form.district = null; }
if (!this.form.city && this.regionOptions.cities.length) {
this.form.city = this.regionOptions.cities[0].value;
}
if (this.form.city) { await this.loadAreas(provId, this.form.city, true); } else { this.regionOptions.areas = []; this.form.district = null; }
},
async loadAreas(provId, cityId, echo = false) {
if (!provId || !cityId) { this.regionOptions.areas = []; this.form.district = null; return; }
try { const res = await getAreas(provId, cityId); if (res.code === 200) this.regionOptions.areas = res.data || []; else this.$modal.msgError(res.msg || '加载区县失败'); } catch(e){ this.$modal.msgError('加载区县失败'); }
if (!echo) { this.form.district = null; }
if (!this.form.district && this.regionOptions.areas.length) {
this.form.district = this.regionOptions.areas[0].value;
} else if (!echo) {
this.form.district = null;
}
},
async loadERPAccounts() {
this.erpAccountLoading = true;
try { const res = await getERPAccounts(); if (res.code === 200) this.erpAccountsOptions = res.data || []; else this.$modal.msgError(res.msg || '加载应用失败'); } catch(e){ this.$modal.msgError('加载应用失败'); }
this.erpAccountLoading = false; if (!this.form.appid && this.erpAccountsOptions.length) { this.form.appid = this.erpAccountsOptions[0].value; }
try {
const res = await getERPAccounts();
if (res.code === 200) this.erpAccountsOptions = res.data || []; else this.$modal.msgError(res.msg || '加载应用失败');
} catch(e){ this.$modal.msgError('加载应用失败'); }
this.erpAccountLoading = false;
// 如果隐藏appid选择则不强制赋值给表单由后端使用默认账号
if (!this.hideAppid && !this.form.appid && this.erpAccountsOptions.length) {
this.form.appid = this.erpAccountsOptions[0].value;
}
},
onAppidChange() { this.form.userName = ''; this.loadUsernames(); this.loadCategories(); this.loadProperties(); },
async loadUsernames() {

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() {