index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <el-select
  3. v-model="adGroupId"
  4. filterable
  5. remote
  6. :remote-method="searchAdGroupName"
  7. :style="{ width }"
  8. clearable
  9. collapse-tags
  10. :multiple="multiple"
  11. @change="changeAdGroup"
  12. placeholder="请选择广告组">
  13. <el-option v-for="info in adGroupList" :key="info.adGroupId" :label="info.adGroupName" :value="info.adGroupId"></el-option>
  14. </el-select>
  15. </template>
  16. <script lang="ts" setup>
  17. import { ref, onMounted, watch } from 'vue'
  18. import { getAdGroupList } from './api'
  19. interface Props {
  20. modelValue: string | string[]
  21. query: {
  22. profileId: string
  23. campaignType: string
  24. campaignId: string
  25. }
  26. width: string,
  27. multiple: boolean
  28. }
  29. const props = withDefaults(defineProps<Props>(), {
  30. width: '',
  31. multiple: false
  32. })
  33. const adGroupId = ref(props.modelValue)
  34. const adGroupList = ref([])
  35. const emits = defineEmits(['update:modelValue', 'change-ad-group'])
  36. const searchAdGroupName = async (adGroupName: string) => {
  37. if (!adGroupName) {
  38. return
  39. }
  40. const { profileId, campaignType, campaignId } = props.query
  41. await setAdGroupList({ profileId, campaignType, campaignId, adGroupName })
  42. }
  43. const changeAdGroup = () => {
  44. emits('update:modelValue', adGroupId.value)
  45. emits('change-ad-group', adGroupId.value)
  46. }
  47. const setAdGroupList = async (params: any) => {
  48. if(!params.campaignId) return
  49. const resp = await getAdGroupList(params)
  50. adGroupList.value = resp.data
  51. if(adGroupList.value.length === 1) {
  52. adGroupId.value = adGroupList.value[0].adGroupId
  53. changeAdGroup()
  54. }
  55. }
  56. watch(
  57. [() => props.query.campaignType, () => props.query.campaignId],
  58. async () => {
  59. await setAdGroupList(props.query)
  60. },
  61. { immediate: true }
  62. )
  63. watch(
  64. () => props.modelValue,
  65. () => { adGroupId.value = props.modelValue }
  66. )
  67. </script>
  68. <style scoped></style>