import { reactive, ref } from 'vue'
import { TASK_TYPE } from '@/utils/dictionary.js'
import { airportList } from '@/api/dashboard/index.js'
import { dataToSelect } from '@/utils/handleData.js'

const airOptions = ref([])

export const search = reactive([
  {
    label: '任务编号',
    key: 'reportNo',
    props: {
      placeholder: '请输入任务编号'
    }
  },
  {
    label: '任务名称',
    key: 'name',
    props: {
      placeholder: '请输入任务名称'
    }
  },
  {
    label: '巡检机场',
    key: 'airportId',
    type: 'select',
    props: {
      placeholder: '请选择巡检机场',
      options: airOptions
    }
  },
  {
    label: '任务类型',
    key: 'type',
    type: 'select',
    value: 0,
    props: {
      placeholder: '请选择任务状态',
      options: TASK_TYPE
    }
  }
])

export const getAirOptions = async function() {
  const res = await airportList()
  airOptions.value = dataToSelect(res.data, { label: 'name', value: 'id' })
}
