<template>
  <a-select :model-value="modelValue" @change="onUpdate" placeholder="请选择媒体类型" :multiple="multiple" allow-clear>
    <a-option
      :maxTagCount="1"
      v-for="item in mediaOptions"
      :key="item.id"
      :value="item.id"
      :label="`${item.id}:${item.name}`" />
  </a-select>
</template>
<script setup>
import { ref, onMounted, defineProps, defineEmits } from 'vue'
import advertCommonApi from '@/views/v1/api/advert/common'

const props = defineProps({
  modelValue: {
    type: [String, Number, Array],
    default: '',
  },
  multiple: {
    type: Boolean,
    default: false,
  },
})
const mediaOptions = ref([])
const emit = defineEmits(['update:modelValue'])
const onUpdate = (val) => {
  emit('update:modelValue', val)
}
onMounted(() => {
  getMediaOptions()
})
// 获取媒体列表
const getMediaOptions = async () => {
  const resp = await advertCommonApi.getMediaOptionsApi()
  if (resp.code === 200) {
    mediaOptions.value = resp.data
  }
}
</script>
