<!-- 保税仓业务-计费管理 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" />
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="tableColumns" :loading="loading">
            <!-- 支付状态 -->
            <template #paystatus="{ value }">
                {{ getGZBSCPayStatusName(value) }}
            </template>
            <!-- 支付方式 -->
            <template #paymode="{ value }">
                {{ getGZBSCPayModeName(value) }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation type="dropdown" :menus="handleOperateButtons(row)" :options="{ selectedRow: row }"
                    @closed="onRefresh" />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="onRefresh" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { useDataFilter } from '@/hooks/datatable'
import { useComposeTable } from '@pc/components/base/table'
import { getGZBSCPayStatusList, getGZBSCPayStatusName, getGZBSCPayModeName } from '@/constants/bonded'
import { useGzbscusermonthpay } from '@/business/bonded'
import AppTable from '@pc/components/base/table/index.vue'
import AppFilter from '@pc/components/base/table-filter/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'

const { loading, dataList, total, pageIndex, pageSize, getGzbscusermonthpay } = useGzbscusermonthpay()
const { tableColumns } = useComposeTable<Ermcp.GzbscusermonthpayRsp>({ rowKey: 'trademonth', columnKey: 'bonded_expense' })
const { filterOptons, getQueryParams } = useDataFilter<Ermcp.GzbscusermonthpayReq>()

// 状态”2:待支付 “多操作：“支付”
const handleOperateButtons = (row: Ermcp.GzbscusermonthpayRsp) => {
    const buttons = ['bonded_expense_details']
    if (row.paystatus === 2) {
        buttons.push('bonded_expense_payment')
    }
    return buttons
}

const onSearch = (clear = false) => {
    getQueryParams((qs) => {
        pageIndex.value = 1
        getGzbscusermonthpay(qs)
    }, clear)
}

const onRefresh = () => {
    getQueryParams((qs) => {
        getGzbscusermonthpay(qs).catch((err) => ElMessage.error(err))
    })
}

filterOptons.selectList = [
    {
        label: '支付状态',
        key: 'paystatus',
        options: getGZBSCPayStatusList(),
    },
]

filterOptons.buttonList = [
    { lable: '重置', onClick: () => onSearch(true) },
    { lable: '查询', className: 'el-button--primary', onClick: () => onSearch() }
]

onRefresh()
</script>