Commit dd18a2ca authored by hzl's avatar hzl

feat: 处理资源组多选逻辑

parent ec541dd1
<template> <template>
<div class="resource-group-selector"> <div class="resource-group-selector">
<el-select <el-select
v-model="selectedGroup" v-model="selectedGroup"
filterable filterable
placeholder="请选择资源组" multiple
@change="handleChange"> placeholder="请选择资源组"
<el-option @change="handleChange">
v-for="group in resourceGroups" <el-option
:key="group.id" v-for="group in resourceGroups"
:label="group.name" :key="group.id"
:value="group.id"> :label="group.name"
</el-option> :value="group.id">
</el-select> </el-option>
</el-select>
</div> </div>
</template> </template>
...@@ -23,7 +24,7 @@ export default { ...@@ -23,7 +24,7 @@ export default {
props: { props: {
value: { value: {
type: [Number, String], type: [Number, String, Array],
default: null default: null
} }
}, },
...@@ -31,7 +32,7 @@ export default { ...@@ -31,7 +32,7 @@ export default {
data() { data() {
return { return {
resourceGroups: [], resourceGroups: [],
selectedGroup: null selectedGroup: []
} }
}, },
...@@ -39,7 +40,13 @@ export default { ...@@ -39,7 +40,13 @@ export default {
value: { value: {
immediate: true, immediate: true,
handler(newVal) { handler(newVal) {
this.selectedGroup = newVal if (Array.isArray(newVal)) {
this.selectedGroup = newVal
} else if (newVal !== null && newVal !== undefined) {
this.selectedGroup = [newVal]
} else {
this.selectedGroup = []
}
} }
} }
}, },
......
...@@ -191,9 +191,9 @@ ...@@ -191,9 +191,9 @@
@change="handleAdvertiserChange"> @change="handleAdvertiserChange">
<el-option <el-option
v-for="item in advertiserOptions" v-for="item in advertiserOptions"
:key="item" :key="item.advertiserId"
:label="item" :label="item.advertiserName"
:value="item"> :value="item.advertiserId">
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
...@@ -387,8 +387,8 @@ ...@@ -387,8 +387,8 @@
<description-group-selector v-model="form.description_groups" /> <description-group-selector v-model="form.description_groups" />
</el-form-item> </el-form-item>
<el-form-item label="资源组" prop="resource_group_id"> <el-form-item label="资源组" prop="resource_groups">
<resource-group-selector v-model="form.resource_group_id" /> <resource-group-selector v-model="form.resource_groups" />
</el-form-item> </el-form-item>
</div> </div>
...@@ -732,7 +732,7 @@ export default { ...@@ -732,7 +732,7 @@ export default {
material_groups: [], material_groups: [],
title_groups: [], title_groups: [],
description_groups: [], description_groups: [],
resource_group_id: null, resource_groups: [],
// 修改字段名为tiktok_json // 修改字段名为tiktok_json
tiktok_json: { tiktok_json: {
optimizationGoal: 'VALUE', optimizationGoal: 'VALUE',
...@@ -1037,7 +1037,7 @@ export default { ...@@ -1037,7 +1037,7 @@ export default {
material_groups: [], material_groups: [],
title_groups: [], title_groups: [],
description_groups: [], description_groups: [],
resource_group_id: null, resource_groups: [],
// 修改字段名为tiktok_json // 修改字段名为tiktok_json
tiktok_json: { tiktok_json: {
optimizationGoal: 'VALUE', optimizationGoal: 'VALUE',
...@@ -1086,7 +1086,7 @@ export default { ...@@ -1086,7 +1086,7 @@ export default {
material_groups: [], material_groups: [],
title_groups: [], title_groups: [],
description_groups: [], description_groups: [],
resource_group_id: null, resource_groups: [],
// 修改字段名为tiktok_json // 修改字段名为tiktok_json
tiktok_json: { tiktok_json: {
optimizationGoal: 'VALUE', optimizationGoal: 'VALUE',
...@@ -1194,7 +1194,7 @@ export default { ...@@ -1194,7 +1194,7 @@ export default {
daily_budget: this.form.daily_budget, daily_budget: this.form.daily_budget,
bidding_type: this.form.bidding_type, bidding_type: this.form.bidding_type,
target_roas: this.form.target_roas, target_roas: this.form.target_roas,
resource_group_id: this.form.resource_group_id, resource_groups: this.form.resource_groups,
} }
// 根据模板类型传递不同的字段 // 根据模板类型传递不同的字段
...@@ -1363,10 +1363,10 @@ export default { ...@@ -1363,10 +1363,10 @@ export default {
this.form.material_groups = Array.isArray(template.material_groups) ? [...template.material_groups] : []; this.form.material_groups = Array.isArray(template.material_groups) ? [...template.material_groups] : [];
this.form.title_groups = Array.isArray(template.title_groups) ? [...template.title_groups] : []; this.form.title_groups = Array.isArray(template.title_groups) ? [...template.title_groups] : [];
this.form.description_groups = Array.isArray(template.description_groups) ? [...template.description_groups] : []; this.form.description_groups = Array.isArray(template.description_groups) ? [...template.description_groups] : [];
this.form.resource_group_id = template.resource_group_id || null; this.form.resource_groups = Array.isArray(template.resource_groups) ? [...template.resource_groups] : (template.resource_group_id ? [template.resource_group_id] : []);
console.log('模板数据中的resource_group_id:', template.resource_group_id); console.log('模板数据中的resource_group_id:', template.resource_group_id);
console.log('设置后的form.resource_group_id:', this.form.resource_group_id); console.log('设置后的form.resource_groups:', this.form.resource_groups);
// 处理tiktok_json字段(所有平台都需要处理) // 处理tiktok_json字段(所有平台都需要处理)
try { try {
...@@ -1455,6 +1455,13 @@ export default { ...@@ -1455,6 +1455,13 @@ export default {
const response = await axios.get(process.env.PUTIN_API + '/campaign-tasks/getTiktokAdvertiserId'); const response = await axios.get(process.env.PUTIN_API + '/campaign-tasks/getTiktokAdvertiserId');
if (response.data && response.data.status === 200) { if (response.data && response.data.status === 200) {
this.advertiserOptions = response.data.result.data || []; this.advertiserOptions = response.data.result.data || [];
// 如果有账户列表,默认选择第一个
if (this.advertiserOptions.length > 0) {
this.form.tiktok_json.advertiserId = this.advertiserOptions[0].advertiserId;
// 异步调用第一个账户的计划列表,不等待完成
this.fetchCampaignList(this.advertiserOptions[0].advertiserId);
}
} else { } else {
this.$message.error(response.data.msg || '获取账户列表失败'); this.$message.error(response.data.msg || '获取账户列表失败');
} }
......
...@@ -139,11 +139,23 @@ ...@@ -139,11 +139,23 @@
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="资源组" width="150"> <el-table-column label="资源组" width="200">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag v-if="scope.row.resource_group_id" type="success" size="small"> <div v-if="scope.row.resource_groups && scope.row.resource_groups.length > 0">
{{ getResourceGroupName(scope.row.resource_group_id) }} <el-tag
</el-tag> v-for="group in scope.row.resource_groups"
:key="group"
type="success"
size="small"
style="margin: 2px">
{{ getResourceGroupName(group) }}
</el-tag>
</div>
<div v-else-if="scope.row.resource_group_id">
<el-tag type="success" size="small">
{{ getResourceGroupName(scope.row.resource_group_id) }}
</el-tag>
</div>
<span v-else style="color: #999; font-size: 12px;">未选择</span> <span v-else style="color: #999; font-size: 12px;">未选择</span>
</template> </template>
</el-table-column> </el-table-column>
...@@ -237,12 +249,15 @@ ...@@ -237,12 +249,15 @@
v-model="tiktokAdvertiserId" v-model="tiktokAdvertiserId"
placeholder="请选择账户" placeholder="请选择账户"
:loading="advertiserLoading" :loading="advertiserLoading"
@change="handleAdvertiserChange"> @change="handleAdvertiserChange"
filterable>
<el-option <el-option
v-for="item in advertiserOptions" v-for="item in advertiserOptions"
:key="item" :key="item.advertiserId"
:label="item" :label="item.advertiserName"
:value="item"> :value="item.advertiserId">
<span style="float: left">{{ item.advertiserName }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ item.advertiserId }}</span>
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
...@@ -379,8 +394,8 @@ ...@@ -379,8 +394,8 @@
<description-group-selector v-model="form.description_groups" /> <description-group-selector v-model="form.description_groups" />
</el-form-item> </el-form-item>
<el-form-item label="资源组" prop="resource_group_id"> <el-form-item label="资源组" prop="resource_groups">
<resource-group-selector v-model="form.resource_group_id" /> <resource-group-selector v-model="form.resource_groups" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
...@@ -430,7 +445,7 @@ export default { ...@@ -430,7 +445,7 @@ export default {
dialogTitle: '', dialogTitle: '',
form: { form: {
name: '', name: '',
platform: 1, platform: 2, // 默认选择TikTok平台
campaign_type: 1, campaign_type: 1,
appStore: 3, appStore: 3,
daily_budget: 0, daily_budget: 0,
...@@ -441,7 +456,7 @@ export default { ...@@ -441,7 +456,7 @@ export default {
material_groups: [], material_groups: [],
title_groups: [], title_groups: [],
description_groups: [], description_groups: [],
resource_group_id: null, resource_groups: [],
// 初始化tiktok_json为对象而不是null // 初始化tiktok_json为对象而不是null
tiktok_json: { tiktok_json: {
optimizationGoal: 'VALUE', optimizationGoal: 'VALUE',
...@@ -808,7 +823,7 @@ export default { ...@@ -808,7 +823,7 @@ export default {
this.dialogTitle = '新增模板' this.dialogTitle = '新增模板'
this.form = { this.form = {
name: '', name: '',
platform: 1, platform: 2, // 默认选择TikTok平台
campaign_type: 1, campaign_type: 1,
appStore: 3, appStore: 3,
daily_budget: 0, daily_budget: 0,
...@@ -819,7 +834,7 @@ export default { ...@@ -819,7 +834,7 @@ export default {
material_groups: [], material_groups: [],
title_groups: [], title_groups: [],
description_groups: [], description_groups: [],
resource_group_id: null, resource_groups: [],
// 初始化为对象而不是null // 初始化为对象而不是null
tiktok_json: { tiktok_json: {
optimizationGoal: 'VALUE', optimizationGoal: 'VALUE',
...@@ -837,11 +852,9 @@ export default { ...@@ -837,11 +852,9 @@ export default {
} }
this.dialogVisible = true this.dialogVisible = true
// 如果默认选择的是TikTok平台,获取广告主列表 // 默认选择TikTok平台,获取广告主列表
if (this.form.platform === 2) { this.fetchAdvertiserList();
this.fetchAdvertiserList(); },
}
},
// 平台变化时的处理 // 平台变化时的处理
async handlePlatformChange(value) { async handlePlatformChange(value) {
...@@ -949,7 +962,7 @@ export default { ...@@ -949,7 +962,7 @@ export default {
material_groups: Array.isArray(row.material_groups) ? [...row.material_groups] : [], material_groups: Array.isArray(row.material_groups) ? [...row.material_groups] : [],
title_groups: Array.isArray(row.title_groups) ? [...row.title_groups] : [], title_groups: Array.isArray(row.title_groups) ? [...row.title_groups] : [],
description_groups: Array.isArray(row.description_groups) ? [...row.description_groups] : [], description_groups: Array.isArray(row.description_groups) ? [...row.description_groups] : [],
resource_group_id: row.resource_group_id || null resource_groups: Array.isArray(row.resource_groups) ? [...row.resource_groups] : (row.resource_group_id ? [row.resource_group_id] : [])
}; };
// 使用Vue.set确保响应式更新 // 使用Vue.set确保响应式更新
...@@ -1000,7 +1013,7 @@ export default { ...@@ -1000,7 +1013,7 @@ export default {
material_groups: Array.isArray(this.form.material_groups) ? [...this.form.material_groups] : [], material_groups: Array.isArray(this.form.material_groups) ? [...this.form.material_groups] : [],
title_groups: Array.isArray(this.form.title_groups) ? [...this.form.title_groups] : [], title_groups: Array.isArray(this.form.title_groups) ? [...this.form.title_groups] : [],
description_groups: Array.isArray(this.form.description_groups) ? [...this.form.description_groups] : [], description_groups: Array.isArray(this.form.description_groups) ? [...this.form.description_groups] : [],
resource_group_id: this.form.resource_group_id resource_groups: this.form.resource_groups
}; };
// 如果是TikTok平台,处理tiktok_json // 如果是TikTok平台,处理tiktok_json
...@@ -1098,6 +1111,13 @@ export default { ...@@ -1098,6 +1111,13 @@ export default {
const response = await axios.get(process.env.PUTIN_API + '/campaign-tasks/getTiktokAdvertiserId'); const response = await axios.get(process.env.PUTIN_API + '/campaign-tasks/getTiktokAdvertiserId');
if (response.data && response.data.status === 200) { if (response.data && response.data.status === 200) {
this.advertiserOptions = response.data.result.data || []; this.advertiserOptions = response.data.result.data || [];
// 如果有账户列表,默认选择第一个
if (this.advertiserOptions.length > 0) {
this.tiktokAdvertiserId = this.advertiserOptions[0].advertiserId;
// 异步调用第一个账户的计划列表,不等待完成
this.fetchCampaignList(this.advertiserOptions[0].advertiserId);
}
} else { } else {
this.$message.error(response.data.msg || '获取账户列表失败'); this.$message.error(response.data.msg || '获取账户列表失败');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment