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