<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' , 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('user.pilot.User name') + '/' +  t('user.pilot.grouping') })"
        />

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

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

const { t } = useI18n()
const tableRef = ref()

const baTable = new baTableClass(
    new baTableApi(userPilot),
    {
        column: [
            {
                label: t('user.pilot.id'),
                fixed: true,
                prop: 'id',
                align: 'center',
                width: 68,
                operator: 'RANGE',
                sortable: 'custom',
            },
            {
                label: t('user.pilot.User name'),
                prop: 'username',
                align: 'left',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
            },
            {
                label: t('user.pilot.grouping'),
                prop: 'group.name', // group.name
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tag',
                width: 90,
            },
            {
                label: t('user.pilot.real_name'),
                prop: 'real_name',
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                width: 70,
            },
            {
                label: t('user.pilot.Identity No'),
                prop: 'identity',
                align: 'left',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
            },
            {
                label: t('user.pilot.Pilot License'),
                prop: 'pilot_license',
                align: 'center',
                render: 'image',
                operator: false,
            },
            {
                label: t('user.pilot.License Type'),
                prop: 'license_type',
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tag',
                custom: { '0': 'info', '1': 'success', '2': 'danger' },
                replaceValue: {
                    '0': t('user.pilot.NULL'),
                    '1': t('user.pilot.AOPA'),
                    '2': t('user.pilot.ASFC'),
                    '3': t('user.pilot.DJI UTC'),
                },
                width: 90,
            },
            {
                label: t('user.pilot.city'),
                prop: 'city',
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
            },
            {
                label: t('user.pilot.address'),
                prop: 'address',
                align: 'left',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
            },

            {
                label: t('user.pilot.Gender'),
                prop: 'gender',
                align: 'center',
                render: 'tag',
                custom: { '0': 'info', '1': '', '2': 'success' },
                replaceValue: { '0': t('unknown'), '1': t('user.pilot.male'), '2': t('user.pilot.female') },
                width: 60,
            },
            {
                label: t('user.pilot.mobile'),
                prop: 'mobile',
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
            },
            {
                label: t('user.pilot.certification'),
                prop: 'certified',
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tag',
                custom: { '0': 'info', '1': 'success', '2': 'danger' },
                replaceValue: {
                    '0': t('user.pilot.unchecked'),
                    '1': t('user.pilot.verified'),
                    '2': t('user.pilot.refuse'),
                },
                width: 90,
            },
        ],
        dblClickNotEditColumn: [
            undefined,
            'identity',
            'status',
            'identity_img',
            'pilot_license',
            'certified',
            'mobile',
            'gender'],
    },
    {
        defaultItems: {
            status: 'enable',
            license_type: '0',
        },
    },
)

baTable.mount()
baTable.getIndex()

provide('baTable', baTable)

</script>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
    name: 'user/pilot',
})
</script>

<style scoped lang="scss">
.table-header-operate {
    margin-left: 12px;
}

.table-header-operate-text {
    margin-left: 6px;
}
</style>
