targetRuleDialog.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: targetRuleDialog.vue
  4. * @Description: 关联广告活动-选择定向弹窗
  5. * @Author: xinyan
  6. */
  7. import { onMounted, reactive, ref, watch } from 'vue';
  8. import { MatchType } from '../../utils/enum';
  9. import { getTargetingRuleList } from '/@/views/efTools/automation/api';
  10. import { ElMessage } from 'element-plus';
  11. const props = defineProps({
  12. modelValue: {
  13. type: Boolean,
  14. required: true,
  15. },
  16. selectedTargetedRow: {
  17. type: Object,
  18. required: true,
  19. },
  20. });
  21. const emits = defineEmits(['update:modelValue', 'confirm:targetRule']);
  22. const targetRuleDialogVisible = ref(props.modelValue);
  23. const { selectedTargetedRow } = toRefs(props);
  24. const adGroupId = ref(props.adGroupId);
  25. const campaignKeywordInfo = ref(null);
  26. // 查询、筛选条件
  27. const matchType = ref('');
  28. const keyWord = ref('');
  29. const gridOptions = reactive({
  30. height: 550,
  31. showOverflow: true,
  32. loading: false,
  33. rowConfig: {
  34. isHover: true,
  35. height: 34
  36. },
  37. columns: [
  38. { field: 'keywordText', title: '关键词', width: 220 },
  39. {
  40. field: 'matchType',
  41. title: '匹配方式',
  42. formatter: ({ cellValue }) => getMatchTypeLabel(cellValue).label,
  43. },
  44. { type: 'checkbox', align: 'right', width: 55 }
  45. ],
  46. data: []
  47. });
  48. async function fetchTargetRuleList() {
  49. try {
  50. gridOptions.loading = true;
  51. const resp = await getTargetingRuleList({
  52. campaignType: selectedTargetedRow.value.campaignType,
  53. campaignId: selectedTargetedRow.value.parentCampaignId,
  54. adGroupId: selectedTargetedRow.value.adGroupId,
  55. matchType: matchType.value,
  56. search: keyWord.value,
  57. });
  58. gridOptions.data = resp.data.targetData;
  59. gridOptions.loading = false;
  60. } catch (error) {
  61. ElMessage.error('请求定向数据失败');
  62. }
  63. }
  64. function handleCheckChange({ records }) {
  65. campaignKeywordInfo.value = records;
  66. }
  67. function getMatchTypeLabel(type: string) {
  68. const matchType = MatchType.find(item => item.value === type);
  69. if (matchType) {
  70. return { label: matchType.label, type: type };
  71. }
  72. return { label: type, type: '' };
  73. }
  74. function cancel() {
  75. targetRuleDialogVisible.value = false;
  76. }
  77. async function confirm() {
  78. targetRuleDialogVisible.value = false;
  79. emits('confirm:targetRule', campaignKeywordInfo.value);
  80. }
  81. const headerCellStyle = () => {
  82. return {
  83. fontSize: '13px',
  84. height: '34px',
  85. };
  86. };
  87. const cellStyle = () => {
  88. return {
  89. fontSize: '13px',
  90. //fontWeight: '500',
  91. };
  92. };
  93. watch(() => props.modelValue, (newValue) => {
  94. targetRuleDialogVisible.value = newValue;
  95. });
  96. watch(targetRuleDialogVisible, (newValue) => {
  97. emits('update:modelValue', newValue);
  98. });
  99. watch(() => props.selectedTargetedRow, () => {
  100. fetchTargetRuleList();
  101. });
  102. onMounted(() => {
  103. //fetchTargetRuleList();
  104. });
  105. </script>
  106. <template>
  107. <el-dialog v-model="targetRuleDialogVisible"
  108. style="border-radius: 10px;"
  109. title="关联广告活动 > 选择定向"
  110. width="1158px">
  111. <div>
  112. <el-select
  113. v-model="matchType"
  114. placeholder="全部匹配方式"
  115. style="width: 128px; margin-bottom: 10px"
  116. @change="fetchTargetRuleList"
  117. >
  118. <el-option
  119. v-for="item in MatchType"
  120. :key="item.value"
  121. :label="item.label"
  122. :value="item.value"
  123. />
  124. </el-select>
  125. </div>
  126. <el-input v-model="keyWord" class="mb-3" clearable placeholder="快速搜索关键词" @change="fetchTargetRuleList" />
  127. <vxe-grid :cell-style="cellStyle" :header-cell-style="headerCellStyle" @checkbox-change="handleCheckChange"
  128. v-bind="gridOptions"></vxe-grid>
  129. <template #footer>
  130. <div class="dialog-footer">
  131. <el-button @click="cancel">取消</el-button>
  132. <el-button type="primary" @click="confirm">确定</el-button>
  133. </div>
  134. </template>
  135. </el-dialog>
  136. </template>
  137. <style scoped>
  138. </style>