﻿<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('config.gameConfig.quick Search Fields') })"
        ></TableHeader>

        <Table ref="tableRef"></Table>

        <PopupForm />
    </div>
</template>

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

defineOptions({
    name: 'config/gameConfig',
})

const { t } = useI18n()
const tableRef = useTemplateRef('tableRef')
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])

const baTable = new baTableClass(
    new baTableApi('/admin/config.GameConfig/'),
    {
        pk: 'id',
        filter: { page: 1, limit: 50 },
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('config.gameConfig.id'), prop: 'id', align: 'center', width: 80, operator: 'RANGE', sortable: 'custom' },
            {
                label: t('config.gameConfig.config_key'),
                prop: 'config_key',
                align: 'center',
                minWidth: 200,
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                showOverflowTooltip: true,
            },
            {
                label: t('config.gameConfig.config_value'),
                prop: 'config_value',
                align: 'center',
                minWidth: 160,
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                showOverflowTooltip: true,
            },
            {
                label: t('config.gameConfig.value_type'),
                prop: 'value_type',
                align: 'center',
                width: 110,
                operator: 'eq',
                render: 'tag',
                custom: {
                    string: 'primary',
                    int: 'success',
                    decimal: 'warning',
                    json: 'info',
                },
                replaceValue: {
                    string: t('config.gameConfig.value_type string'),
                    int: t('config.gameConfig.value_type int'),
                    decimal: t('config.gameConfig.value_type decimal'),
                    json: t('config.gameConfig.value_type json'),
                },
            },
            {
                label: t('config.gameConfig.remark'),
                prop: 'remark',
                align: 'center',
                minWidth: 200,
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                showOverflowTooltip: true,
            },
            {
                label: t('config.gameConfig.create_time'),
                prop: 'create_time',
                align: 'center',
                render: 'datetime',
                operator: 'RANGE',
                comSearchRender: 'datetime',
                sortable: 'custom',
                width: 170,
                timeFormat: 'yyyy-mm-dd hh:MM:ss',
            },
            {
                label: t('config.gameConfig.update_time'),
                prop: 'update_time',
                align: 'center',
                render: 'datetime',
                operator: 'RANGE',
                comSearchRender: 'datetime',
                sortable: 'custom',
                width: 170,
                timeFormat: 'yyyy-mm-dd hh:MM:ss',
            },
            { label: t('Operate'), align: 'center', width: 80, render: 'buttons', buttons: optButtons, operator: false, fixed: 'right' },
        ],
        dblClickNotEditColumn: [undefined],
    },
    {
        defaultItems: { value_type: 'string', remark: '' },
    }
)

provide('baTable', baTable)

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

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


