<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.identity.User name') + '/' +  t('user.identity.grouping') })"
        />

        <!-- 表格 -->
        <!-- 要使用`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 { userIdentity } from '/@/api/controllerUrls'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'

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

const baTable = new baTableClass(
    new baTableApi(userIdentity),
    {
        // pk: 'id',
        column: [
            {
                label: t('user.identity.id'),
                fixed: true,
                prop: 'id',
                align: 'center',
                width: 68,
                operator: 'RANGE',
                sortable: 'custom',
            },
            {
                label: t('user.identity.User name'),
                prop: 'username',
                align: 'left',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
            },
            {
                label: t('state'),
                prop: 'status',
                align: 'center',
                render: 'tag',
                custom: { disable: 'danger', enable: 'success' },
                replaceValue: { disable: t('Disable'), enable: t('Enable') },
                width: 70,
            },
            {
                label: t('user.identity.real_name'),
                prop: 'real_name',
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                width: 70,
            },
            {
                label: t('user.identity.Identity No'),
                prop: 'identity',
                align: 'left',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
            },
            {
                label: t('user.identity.identity_img'),
                prop: 'identity_img',
                align: 'center',
                render: 'image',
                operator: false,
            },
            {
                label: t('user.identity.Real name authentication'),
                prop: 'real_name_status',
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tag',
                custom: { '0': 'info', '1': 'success', '2': 'danger' },
                replaceValue: {
                    '0': t('user.identity.unchecked'),
                    '1': t('user.identity.verified'),
                    '2': t('user.identity.identity_refuse'),
                },
                width: 90,
            },
            {
                label: t('user.identity.grouping'),
                prop: 'group.name', // group.name
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                // render: 'tag',
                width: 90,
            },
            {
                label: t('user.identity.Pilot License'),
                prop: 'pilot_license',
                align: 'center',
                render: 'image',
                operator: false,
            },
            {
                label: t('user.identity.certification'),
                prop: 'certified',
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tag',
                custom: { '0': 'info', '1': 'success', '2': 'danger' },
                replaceValue: {
                    '0': t('user.identity.unchecked'),
                    '1': t('user.identity.verified'),
                    '2': t('user.identity.refuse'),
                },
                width: 90,
            },
            {
                label: t('user.identity.Gender'),
                prop: 'gender',
                align: 'center',
                render: 'tag',
                custom: { '0': 'info', '1': '', '2': 'success' },
                replaceValue: { '0': t('unknown'), '1': t('user.identity.male'), '2': t('user.identity.female') },
                width: 60,
            },
            {
                label: t('user.identity.mobile'),
                prop: 'mobile',
                align: 'center',
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
            },
            {
                label: t('operate'),
                fixed: 'right',
                align: 'center',
                width: '100',
                render: 'buttons',
                buttons: defaultOptButtons(['edit', 'delete']),
                operator: false,
            },
        ],
        dblClickNotEditColumn: [
            undefined,
            'operate',
            'identity',
            'status',
            'identity_img',
            'pilot_license',
            'certified',
            'mobile',
            'gender'],
    },
    {
        defaultItems: {
            status: 'enable',
        },
    },
)

baTable.mount()
baTable.getIndex()

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: 'user/identity',
})
</script>

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