国家
This commit is contained in:
@@ -99,7 +99,9 @@
|
||||
:config="wizardConfig"
|
||||
:wizardStartDate.sync="wizardStartDate"
|
||||
:selectedFieldIds.sync="selectedFieldIds"
|
||||
:selectedCountryIds.sync="selectedCountryIds"
|
||||
:availableFields="availableFields"
|
||||
:availableCountries="availableCountries"
|
||||
:fieldsLoading="fieldsLoading"
|
||||
:fieldsSaving="fieldsSaving"
|
||||
:currentJournalName="wizardJournal ? wizardJournal.title : ''"
|
||||
@@ -110,6 +112,7 @@
|
||||
:title="`${$t('autoPromotion.journalManage')}: ${wizardJournal ? wizardJournal.title : ''}`"
|
||||
@open-template-selector="openTemplateSelector"
|
||||
@confirm-fields="savePromotionFieldsNow"
|
||||
@confirm-countries="savePromotionCountriesNow"
|
||||
@cancel="showWizardDialog = false"
|
||||
@confirm="saveWizardConfig"
|
||||
/>
|
||||
@@ -156,7 +159,9 @@ export default {
|
||||
selectedTemplateName: '',
|
||||
selectedStyleName: '',
|
||||
selectedFieldIds: [],
|
||||
selectedCountryIds: [],
|
||||
availableFields: [],
|
||||
availableCountries: [],
|
||||
fieldsLoading: false,
|
||||
fieldsSaving: false,
|
||||
templateDialogInitialStyleId: '',
|
||||
@@ -326,10 +331,33 @@ export default {
|
||||
if (values.length && Array.isArray(values[0])) return values[0];
|
||||
return null;
|
||||
},
|
||||
/** 与 getJournalPromotionFields 返回体对齐;后端未返回时为空数组 */
|
||||
parseCountryIdsFromPromotionPayload(selectedPayload) {
|
||||
if (!selectedPayload || typeof selectedPayload !== 'object') return [];
|
||||
const raw =
|
||||
selectedPayload.country_fetch_ids != null
|
||||
? selectedPayload.country_fetch_ids
|
||||
: selectedPayload.country_ids != null
|
||||
? selectedPayload.country_ids
|
||||
: '';
|
||||
if (typeof raw === 'string' && raw.trim()) {
|
||||
return raw.split(',').map((s) => s.trim()).filter(Boolean).map(String);
|
||||
}
|
||||
return [];
|
||||
},
|
||||
journalPromotionFieldsPayload(journalId) {
|
||||
return {
|
||||
journal_id: String(journalId),
|
||||
fetch_ids: (this.selectedFieldIds || []).join(','),
|
||||
country_fetch_ids: (this.selectedCountryIds || []).join(',')
|
||||
};
|
||||
},
|
||||
async loadPromotionFields(journalId) {
|
||||
this.fieldsLoading = true;
|
||||
this.availableFields = [];
|
||||
this.availableCountries = [];
|
||||
this.selectedFieldIds = [];
|
||||
this.selectedCountryIds = [];
|
||||
try {
|
||||
const availableRes = await this.$api.post('api/email_client/getAvailableFields', { journal_id: String(journalId) });
|
||||
|
||||
@@ -344,8 +372,10 @@ export default {
|
||||
const label = item.field || item.title || item.name || item.label || String(id);
|
||||
return { id: String(id), label };
|
||||
});
|
||||
this.availableCountries = this.availableFields.map((x) => ({ id: String(x.id), label: x.label }));
|
||||
} catch (e) {
|
||||
this.availableFields = [];
|
||||
this.availableCountries = [];
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -364,10 +394,12 @@ export default {
|
||||
} else if (typeof selectedPayload.fetch_ids === 'string') {
|
||||
this.selectedFieldIds = selectedPayload.fetch_ids.split(',').map((s) => s.trim()).filter(Boolean);
|
||||
}
|
||||
this.selectedCountryIds = this.parseCountryIdsFromPromotionPayload(selectedPayload);
|
||||
console.log('[getJournalPromotionFields] parsed selected:', this.selectedFieldIds);
|
||||
} catch (e) {
|
||||
console.error('[getJournalPromotionFields] error:', e);
|
||||
this.selectedFieldIds = [];
|
||||
this.selectedCountryIds = [];
|
||||
}
|
||||
|
||||
this.fieldsLoading = false;
|
||||
@@ -376,10 +408,10 @@ export default {
|
||||
if (!this.wizardJournal || !this.wizardJournal.journal_id) return;
|
||||
this.fieldsSaving = true;
|
||||
try {
|
||||
await this.$api.post('api/email_client/setJournalPromotionFields', {
|
||||
journal_id: String(this.wizardJournal.journal_id),
|
||||
fetch_ids: (this.selectedFieldIds || []).join(',')
|
||||
});
|
||||
await this.$api.post(
|
||||
'api/email_client/setJournalPromotionFields',
|
||||
this.journalPromotionFieldsPayload(this.wizardJournal.journal_id)
|
||||
);
|
||||
this.$message.success(this.$t('autoPromotion.fieldsSaved'));
|
||||
} catch (e) {
|
||||
this.$message.error(this.$t('autoPromotion.saveFailed'));
|
||||
@@ -387,6 +419,21 @@ export default {
|
||||
this.fieldsSaving = false;
|
||||
}
|
||||
},
|
||||
async savePromotionCountriesNow() {
|
||||
if (!this.wizardJournal || !this.wizardJournal.journal_id) return;
|
||||
this.fieldsSaving = true;
|
||||
try {
|
||||
await this.$api.post(
|
||||
'api/email_client/setJournalPromotionFields',
|
||||
this.journalPromotionFieldsPayload(this.wizardJournal.journal_id)
|
||||
);
|
||||
this.$message.success(this.$t('autoPromotion.countriesSaved'));
|
||||
} catch (e) {
|
||||
this.$message.error(this.$t('autoPromotion.saveFailed'));
|
||||
} finally {
|
||||
this.fieldsSaving = false;
|
||||
}
|
||||
},
|
||||
|
||||
async handleSolicitAction(journal) {
|
||||
if (!this.isSolicitConfigured(journal)) {
|
||||
@@ -437,7 +484,9 @@ export default {
|
||||
this.selectedStyleName = s.styleName || '';
|
||||
this.selectedTemplateThumbHtml = `<div style="zoom:0.18; pointer-events:none; user-select:none;">${s.html || ''}</div>`;
|
||||
this.selectedFieldIds = [];
|
||||
this.selectedCountryIds = [];
|
||||
this.availableFields = [];
|
||||
this.availableCountries = [];
|
||||
if (journal && journal.journal_id) {
|
||||
await this.loadPromotionFields(journal.journal_id);
|
||||
}
|
||||
@@ -473,10 +522,10 @@ export default {
|
||||
start_promotion: this.wizardConfig.enabled ? '1' : '0',
|
||||
user_id: userId
|
||||
});
|
||||
await this.$api.post('api/email_client/setJournalPromotionFields', {
|
||||
journal_id: String(this.wizardJournal.journal_id),
|
||||
fetch_ids: (this.selectedFieldIds || []).join(',')
|
||||
});
|
||||
await this.$api.post(
|
||||
'api/email_client/setJournalPromotionFields',
|
||||
this.journalPromotionFieldsPayload(this.wizardJournal.journal_id)
|
||||
);
|
||||
await this.refreshJournalByDetail(this.wizardJournal);
|
||||
this.$message.success(this.$t('autoPromotion.configSaved'));
|
||||
this.showWizardDialog = false;
|
||||
|
||||
Reference in New Issue
Block a user