<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('platformSettle.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/PlatformSettle/'),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('platformSettle.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
            { label: t('platformSettle.settle_sn'), prop: 'settle_sn', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('platformSettle.xuqiu_order__需求订单编号'), prop: 'xuqiuOrder.需求订单编号', align: 'center', operatorPlaceholder: t('Fuzzy query'), render: 'tags', operator: 'LIKE' },
            { label: t('platformSettle.supplier__name'), prop: 'supplier.name', align: 'center', operatorPlaceholder: t('Fuzzy query'), render: 'tags', operator: 'LIKE' },
            { label: t('platformSettle.total_amount'), prop: 'total_amount', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('platformSettle.settle_status'), prop: 'settle_status', align: 'center', render: 'tag', operator: '=', sortable: false, replaceValue: { '未回款': t('platformSettle.settle_status 未回款'), '部分回款': t('platformSettle.settle_status 部分回款'), '已回款': t('platformSettle.settle_status 已回款') } },
            { label: t('platformSettle.settled_amount'), prop: 'settled_amount', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('platformSettle.invoice_status'), prop: 'invoice_status', align: 'center', render: 'tag', operator: '=', sortable: false, replaceValue: { '未开票': t('platformSettle.invoice_status 未开票'), '部分开票': t('platformSettle.invoice_status 部分开票'), '已开票': t('platformSettle.invoice_status 已开票') } },
            { label: t('platformSettle.invoiced_amount'), prop: 'invoiced_amount', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('platformSettle.doing_invoice_amount'), prop: 'doing_invoice_amount', align: 'center', operator: 'RANGE', sortable: false },
            { label: t('platformSettle.create_time'), prop: 'create_time', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            { label: t('platformSettle.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],
    },
    {
        defaultItems: { total_amount: 0, settle_status: '未回款', settled_amount: 0, invoice_status: '未开票', invoiced_amount: 0, doing_invoice_amount: 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: 'platformSettle',
})
</script>

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