<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('aerocraft.flightPlan.quick Search Fields') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" size="small"/>

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted } from 'vue'
import baTableClass from '/@/utils/baTable'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { aerocraftFlightPlan} from '/@/api/controllerUrls'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'

const { t } = useI18n()
const tableRef = ref()
const optButtons = defaultOptButtons(['edit', 'delete'])
const baTable = new baTableClass(
    new baTableApi(aerocraftFlightPlan),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('aerocraft.flightPlan.applyfor_no'), prop: 'applyfor_no', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('aerocraft.flightPlan.username'), prop: 'username', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('aerocraft.flightPlan.group_id'), prop: 'group_id', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('aerocraft.flightPlan.user_id'), prop: 'user_id', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: 'custom' },
            { label: t('aerocraft.flightPlan.business_id'), prop: 'business_id', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('aerocraft.flightPlan.business_certified_img'), prop: 'business_certified_img', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('aerocraft.flightPlan.real_name'), prop: 'real_name', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('aerocraft.flightPlan.real_name_status'), prop: 'real_name_status', align: 'center', render: 'tag', operator: '=', sortable: false, replaceValue: { 0: t('aerocraft.flightPlan.real_name_status 0'), 1: t('aerocraft.flightPlan.real_name_status 1'), 2: t('aerocraft.flightPlan.real_name_status 2') } },
            { label: t('aerocraft.flightPlan.certified'), prop: 'certified', align: 'center', render: 'tag', operator: '=', sortable: false, replaceValue: { 0: t('aerocraft.flightPlan.certified 0'), 1: t('aerocraft.flightPlan.certified 1'), 2: t('aerocraft.flightPlan.certified 2') } },
            { label: t('aerocraft.flightPlan.mobile'), prop: 'mobile', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('aerocraft.flightPlan.city'), prop: 'city_text', align: 'center', operator: false },
            { label: t('aerocraft.flightPlan.departure_point'), prop: 'departure_point', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('aerocraft.flightPlan.type'), prop: 'type', align: 'center', render: 'tag', operator: '=', sortable: false, replaceValue: { 0: t('aerocraft.flightPlan.type 0'), 1: t('aerocraft.flightPlan.type 1'), 2: t('aerocraft.flightPlan.type 2') } },
            { label: t('aerocraft.flightPlan.range'), prop: 'range', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('aerocraft.flightPlan.height'), prop: 'height', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('aerocraft.flightPlan.start_time'), prop: 'start_time', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('aerocraft.flightPlan.end_time'), prop: 'end_time', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('aerocraft.flightPlan.staff'), prop: 'staff', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('aerocraft.flightPlan.staff_license'), prop: 'staff_license', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('aerocraft.flightPlan.aerocraft_img'), prop: 'aerocraft_img', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('aerocraft.flightPlan.status'), prop: 'status', align: 'center', render: 'tag', operator: '=', sortable: false, replaceValue: { 0: t('aerocraft.flightPlan.status 0'), 1: t('aerocraft.flightPlan.status 1'), 2: 'status 2' } },
            { label: t('aerocraft.flightPlan.updatetime'), prop: 'updatetime', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            { label: t('aerocraft.flightPlan.createtime'), prop: 'createtime', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
        ],
        dblClickNotEditColumn: [undefined],
        defaultOrder: { prop: 'applyfor_no', order: 'desc' },
    },
    {
        defaultItems: { user_id: 0, business_id: 0, business_certified_img: null, real_name: null, real_name_status: '0', certified: '0', mobile: 0, city: null, departure_point: 0, type: null, range: 0, height: 0, start_time: 0, end_time: 0, staff: null, staff_license: null, aerocraft_sn: null, aerocraft_img: null, status: '0' },
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'aerocraft/flightPlan',
})
</script>

<style scoped lang="scss"></style>
