import { TASK_TYPE } from '@/utils/dictionary.js'
import TableTags from '@/components/DataTable/tools/Tags.vue'
import TableAction from '@/components/DataTable/tools/Action.vue'
import { h, ref, reactive } from 'vue'

/* 注册table */
const tableRef = ref()
const searchParams = ref()

function handleSearch(params) {
  searchParams.value = { ...params }
  tableRef.value.reFetch({ searchParams })
}

/**
 * @description: 获取数据及操作
 * @param {*} row 单行数据
 * @param {*} type 操作类型 create:创建，preview:预览，edit:编辑
 * @return {*}
 */
function getRowData(row, type) {
  data.rowData = row
  data.detailDrawer = true
  data.detailType = type
}

const data = reactive({
  tableRef,
  searchParams,
  rowData: {},
  detailDrawer: false,
  detailType: 'inspection',
  handleSearch,

  columns: [
    {
      title: '序号',
      key: 'key',
      render: (_, index) => {
        return `${index + 1}`
      },
      align: 'center'
    },
    {
      title: '报告编号',
      key: 'reportNo',
      align: 'center'
    },
    {
      title: '生成时间',
      key: 'generateTime',
      align: 'center'
    },
    {
      title: '任务名称',
      key: 'missionName',
      align: 'center'
    },
    {
      title: '巡检机场',
      key: 'airportName',
      align: 'center'
    },
    {
      title: '任务类型',
      key: 'type',
      align: 'center',
      render(row) {
        return h(TableTags, {
          data: row.type,
          filters: TASK_TYPE
        })
      }
    },
    {
      title: '巡检时间',
      key: 'executionStartTime',
      align: 'center'
    },
    {
      title: '查看',
      align: 'center',
      width: 150,
      fixed: 'right',
      render(row) {
        return h(TableAction, {
          actions: [
            {
              label: '巡检报告',
              type: 'button',
              props: {
                type: 'primary',
                text: true,
                onClick: getRowData.bind(null, row, 'inspection')
              },
              auth: 'basic_list'
            },
            {
              label: '处理报告',
              type: 'button',
              props: {
                type: 'primary',
                text: true,
                onClick: getRowData.bind(null, row, 'result')
              },
              auth: 'basic_list'
            }
          ],
          align: 'center'
        })
      }
    }

  ]
})

export default data
