<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('reqInvoiceApply.quick Search Fields') })"
        />

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

        <!-- 表单 -->
        <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 { 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('/admin/ReqInvoiceApply/'),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('reqInvoiceApply.id'), prop: 'id', align: 'center', width: 180, operator: 'RANGE', sortable: 'custom' },
            { label: t('reqInvoiceApply.req_order__sn'), prop: 'reqOrder.sn', align: 'center', operatorPlaceholder: t('Fuzzy query'), render: 'tags', operator: 'LIKE' },
            { label: t('reqInvoiceApply.req_order__name'), prop: 'reqOrder.name', align: 'center', operatorPlaceholder: t('Fuzzy query'), render: 'tags', operator: 'LIKE' },
            { label: t('reqInvoiceApply.req_order__req_corp'), prop: 'reqOrder.req_corp', align: 'center', operatorPlaceholder: t('Fuzzy query'), render: 'tags', operator: 'LIKE' },
            { label: t('reqInvoiceApply.invoice_type'), prop: 'invoice_type', align: 'center', render: 'tag', operator: '=', sortable: false, replaceValue: { '普通发票': t('reqInvoiceApply.invoice_type 普通发票'), '专用发票': t('reqInvoiceApply.invoice_type 专用发票') } },
            { label: t('reqInvoiceApply.invoice_corp'), prop: 'invoice_corp', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('reqInvoiceApply.invoice_corp_sn'), prop: 'invoice_corp_sn', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('reqInvoiceApply.invoice_amount'), prop: 'invoice_amount', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('reqInvoiceApply.status'), prop: 'status', align: 'center', render: 'switch', operator: '=', sortable: false, replaceValue: { '': t('reqInvoiceApply.status '), 1: t('reqInvoiceApply.status 1') } },
            { label: t('reqInvoiceApply.create_time'), prop: 'create_time', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            { label: t('reqInvoiceApply.update_time'), prop: 'update_time', 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, 'status'],
    },
    {
        defaultItems: { invoice_type: '普通发票', invoice_amount: 0, status: '1' },
    }
)

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

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