<template>
  <a-select
    @change="onUpdate"
    :model-value="modelValue"
    :options="authorOptions"
    placeholder="请选择作者"
    allow-search
    :max-tag-count="1"
    :multiple="multiple"
    allow-clear />
</template>
<script setup>
import { ref, onMounted, defineProps, defineEmits } from 'vue'
import commonApi from '@/views/v1/api/common'

const authorOptions = ref([])

const props = defineProps({
  modelValue: {
    type: [String, Number, Array],
    default: '',
  },
  multiple: {
    type: Boolean,
    default: false,
  },
})

const emit = defineEmits(['update:modelValue'])
const onUpdate = (val) => {
  emit('update:modelValue', val)
}

// 获取后台归属人列表
const getDesignAuthOptions = async () => {
  const res = await commonApi.getDesignAuthOptions()
  if (res.code == 200) {
    authorOptions.value = authorOptions.value.concat(
      [
        {
          label: '全部',
          value: '-1',
        },
        {
          value: '0',
          label: '未分配',
        },
      ],
      res.data
    )
  }
}
onMounted(() => {
  getDesignAuthOptions()
})
</script>
