|
@@ -5,7 +5,7 @@
|
|
|
* @Author: xinyan
|
|
|
*/
|
|
|
import { computed, onMounted, reactive, ref, toRefs, watch } from 'vue';
|
|
|
-import { getAdGroupList, getRelationCampaign } from '/@/views/efTools/automation/api';
|
|
|
+import { getAdGroupList, getRelationCampaign, updateAdCampaign } from '/@/views/efTools/automation/api';
|
|
|
import { storeToRefs } from 'pinia';
|
|
|
import { useShopInfo } from '/@/stores/shopInfo';
|
|
|
import { ElMessage } from 'element-plus';
|
|
@@ -26,14 +26,13 @@ const props = defineProps({
|
|
|
required: true,
|
|
|
},
|
|
|
});
|
|
|
-const emits = defineEmits(['update:modelValue']);
|
|
|
+const emits = defineEmits(['update:modelValue', 'confirmSuccess']);
|
|
|
const shopInfo = useShopInfo();
|
|
|
const { profile } = storeToRefs(shopInfo);
|
|
|
const { templateId } = toRefs(props);
|
|
|
-// const { activeModel } = toRefs(props);
|
|
|
-const activeModel = ref('specified');
|
|
|
+const { activeModel } = toRefs(props);
|
|
|
|
|
|
-const dialogVisible = ref(true);
|
|
|
+const dialogVisible = ref(false);
|
|
|
const targetRuleDialogVisible = ref(false);
|
|
|
|
|
|
// 定向规则
|
|
@@ -106,6 +105,13 @@ const gridOptions = reactive({
|
|
|
labelField: 'name',
|
|
|
reserve: true,
|
|
|
checkStrictly: false,
|
|
|
+ checkMethod: ({ row }) => {
|
|
|
+ if (activeModel.value === 'specified') {
|
|
|
+ // 如果是 specified 模式,只有已选择的行可以被取消选中
|
|
|
+ return row.isSelected;
|
|
|
+ }
|
|
|
+ return true; // 其他模式下都可以选中
|
|
|
+ }
|
|
|
},
|
|
|
columns: computed(() => [
|
|
|
{
|
|
@@ -114,7 +120,12 @@ const gridOptions = reactive({
|
|
|
slots: { default: 'campaignName_default' },
|
|
|
treeNode: activeModel.value == 'specified' || activeModel.value == 'adGroup'
|
|
|
},
|
|
|
- { type: 'checkbox', width: 55, fixed: 'right' },
|
|
|
+ {
|
|
|
+ type: 'checkbox',
|
|
|
+ width: 55,
|
|
|
+ fixed: 'right',
|
|
|
+ slots: activeModel.value == 'specified' ? { header: 'checkbox_header', checkbox: 'checkbox_cell' } : ''
|
|
|
+ },
|
|
|
]),
|
|
|
data: []
|
|
|
});
|
|
@@ -166,13 +177,49 @@ async function fetchAdCampaign() {
|
|
|
}
|
|
|
|
|
|
// 处理表格复选框选择变化(是否为树形结构)
|
|
|
-const handleGridChange = (event) => {
|
|
|
- if (activeModel.value == 'specified' || activeModel.value == 'adGroup') {
|
|
|
- handleSelectionChange(event);
|
|
|
+// const handleGridChange = (event) => {
|
|
|
+// if (activeModel.value == 'specified' || activeModel.value == 'adGroup') {
|
|
|
+// handleSelectionChange(event);
|
|
|
+// } else {
|
|
|
+// handelSelect(event);
|
|
|
+// }
|
|
|
+// };
|
|
|
+
|
|
|
+function handleGridChange({ records, row, checked }) {
|
|
|
+ if (activeModel.value === 'specified') {
|
|
|
+ if (row) {
|
|
|
+ if (!checked) {
|
|
|
+ row.isSelected = false;
|
|
|
+ updateSelectedAds();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 全选/取消全选
|
|
|
+ records.forEach(record => {
|
|
|
+ if (record.isSelected) {
|
|
|
+ record.isSelected = checked;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ updateSelectedAds();
|
|
|
+ }
|
|
|
+ } else if (activeModel.value === 'adGroup') {
|
|
|
+ handleSelectionChange({ records });
|
|
|
} else {
|
|
|
- handelSelect(event);
|
|
|
+ handelSelect({ records });
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
+
|
|
|
+function toggleCheckboxEvent(row) {
|
|
|
+ if (activeModel.value === 'specified') {
|
|
|
+ if (row.isSelected) {
|
|
|
+ // 只有已选择的行可以被取消选中
|
|
|
+ xGridOne.value.setCheckboxRow(row, false);
|
|
|
+ handleGridChange({ records: [row], row, checked: false });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 其他模式下正常切换复选框状态
|
|
|
+ xGridOne.value.toggleCheckboxRow(row);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
// 非树形结构的表格选择变化
|
|
|
function handelSelect({ records }) {
|
|
@@ -190,6 +237,7 @@ function updateSelectedAds() {
|
|
|
campaignGroupInfo: ad.campaignGroupInfo.filter(group => group.isSelected),
|
|
|
page: currentPage.value
|
|
|
}));
|
|
|
+ console.log('selectedAds.value', selectedAds.value);
|
|
|
}
|
|
|
|
|
|
// 树形结构的表格选择变化
|
|
@@ -242,7 +290,9 @@ function handleSelectTarget(row) {
|
|
|
campaignType: parent.campaignType,
|
|
|
campaignId: parent.campaignId,
|
|
|
adGroupId: row.adGroupId,
|
|
|
- isSelected: row.isSelected || false, // 同步 isSelected 状态
|
|
|
+ isSelected: row.isSelected || false,
|
|
|
+ keywordInfo: row.keywordInfo || [],
|
|
|
+ campaignTargetInfo: row.campaignTargetInfo || [],
|
|
|
};
|
|
|
targetRuleDialogVisible.value = true;
|
|
|
}
|
|
@@ -320,32 +370,59 @@ function cancel() {
|
|
|
dialogVisible.value = false;
|
|
|
}
|
|
|
|
|
|
-//TODO: 确认按钮-商品
|
|
|
+//TODO: 确认按钮-adGroupInfo
|
|
|
async function confirm() {
|
|
|
const campaignItems = selectedAds.value.map(ad => ({
|
|
|
campaignId: ad.campaignId,
|
|
|
campaignType: ad.campaignType
|
|
|
}));
|
|
|
- const adGroupInfo = [];
|
|
|
- const campaignTargetInfo = [
|
|
|
- { targetId: '492707808377423', adGroup_id: '448117369011017', bid: 0.45 },
|
|
|
- ];
|
|
|
|
|
|
- const campaignInfo = selectedTargetedRow.value.keywordInfo.map(keyword => ({
|
|
|
- keywordId: keyword.keywordId,
|
|
|
- adGroup_id: keyword.adGroup_id,
|
|
|
- bid: keyword.bid
|
|
|
- }));
|
|
|
+ let campaignKeywordInfo = [];
|
|
|
+ let campaignTargetInfo = [];
|
|
|
+
|
|
|
+ selectedAds.value.forEach(campaign => {
|
|
|
+ campaign.campaignGroupInfo.forEach(group => {
|
|
|
+ if (group.keywordInfo && group.keywordInfo.length > 0) {
|
|
|
+ campaignKeywordInfo = campaignKeywordInfo.concat(
|
|
|
+ group.keywordInfo.map(keyword => ({
|
|
|
+ keywordId: keyword.keywordId,
|
|
|
+ adGroup_id: group.adGroupId,
|
|
|
+ bid: keyword.bid
|
|
|
+ }))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (group.campaignTargetInfo && group.campaignTargetInfo.length > 0) {
|
|
|
+ campaignTargetInfo = campaignTargetInfo.concat(
|
|
|
+ group.campaignTargetInfo.map(target => ({
|
|
|
+ targetId: target.targetId,
|
|
|
+ adGroup_id: group.adGroupId,
|
|
|
+ bid: target.bid
|
|
|
+ }))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
const requestData = {
|
|
|
profileId: profile.value.profile_id,
|
|
|
templateId: templateId.value,
|
|
|
- campaignItems,
|
|
|
- adGroupInfo,
|
|
|
+ campaignItems: campaignItems,
|
|
|
+ adGroupInfo: [],
|
|
|
campaignTargetInfo,
|
|
|
- campaignInfo
|
|
|
+ campaignKeywordInfo
|
|
|
};
|
|
|
console.log('requestData', requestData);
|
|
|
+ try {
|
|
|
+ const response = await updateAdCampaign(requestData);
|
|
|
+ if (response.code === 2000) {
|
|
|
+ dialogVisible.value = false;
|
|
|
+ emits('confirmSuccess');
|
|
|
+ ElMessage({ message: '创建成功', type: 'success', });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('API error:', error);
|
|
|
+ ElMessage({ message: '创建失败', type: 'error', });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 获取广告组下拉框
|
|
@@ -479,6 +556,27 @@ onMounted(() => {
|
|
|
<span v-else-if="row.adGroupName">已选择定向</span>
|
|
|
</span>
|
|
|
</template>
|
|
|
+ <template #checkbox_header="{ checked, indeterminate }">
|
|
|
+ <span class="custom-checkbox" @click.stop="toggleAllCheckboxEvent">
|
|
|
+ <i v-if="indeterminate" class="vxe-icon-square-minus-fill" style="color: #0d84ff"></i>
|
|
|
+ <i v-else-if="checked" class="vxe-icon-square-checked-fill" style="color: #0d84ff"></i>
|
|
|
+ <i v-else class="vxe-icon-checkbox-unchecked" style="color: #0d84ff"></i>
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ <template #checkbox_cell="{ row, checked, indeterminate }">
|
|
|
+ <span class="custom-checkbox" @click.stop="toggleCheckboxEvent(row)">
|
|
|
+ <i v-if="indeterminate" class="vxe-icon-square-minus-fill" style="color: #0d84ff"></i>
|
|
|
+ <i v-else-if="checked" class="vxe-icon-square-checked-fill" style="color: #0d84ff"></i>
|
|
|
+ <el-tooltip v-else
|
|
|
+ class="box-item"
|
|
|
+ content="请选择定向"
|
|
|
+ effect="dark"
|
|
|
+ placement="top"
|
|
|
+ >
|
|
|
+ <i class="vxe-icon-checkbox-unchecked" style="color: #0d84ff"></i>
|
|
|
+ </el-tooltip>
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
</vxe-grid>
|
|
|
<div class="pagination-container mt-4">
|
|
|
<el-pagination
|