<!-- 交易服务-出境检测 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" />
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="tableColumns" :loading="loading">
            <template #header>
                <app-auth-operation :menus="['customs_exit_add']" @closed="onRefresh" />
            </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 { GZCJStatus } from '@/constants/customs'
import { useCJJCOrderList } from '@/business/customs/exit'
import { useComposeTable } from '@pc/components/base/table'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'
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'

const { loading, dataList, total, pageIndex, pageSize, getGZCJJCOrderList } = useCJJCOrderList()
const { tableColumns } = useComposeTable<Ermcp.GZCJJCOrderRsp>({ rowKey: 'orderidstr', columnKey: 'customs_cjjc' })
const { filterOptons, getQueryParams } = useDataFilter<Ermcp.GZCJJCOrderReq>()

const handleOperateButtons = (row: Ermcp.GZCJJCOrderRsp) => {
    switch (row.gzcjstatus) {
        case GZCJStatus.Uncommitted: {
            return ['customs_exit_details', 'customs_exit_edit', 'customs_exit_cancel']
        }
        case GZCJStatus.Audit: {
            return ['customs_exit_details', 'customs_exit_cancel']
        }
        case GZCJStatus.Shipping: {
            return ['customs_exit_details', 'customs_exit_download', 'customs_exit_delivery']
        }
        case GZCJStatus.CheckConfirm: {
            return ['customs_exit_details', 'customs_exit_download', 'customs_exit_check']
        }
        case GZCJStatus.AdvancePaymentConfirm: {
            return ['customs_exit_details', 'customs_exit_download', 'customs_exit_advance_payment']
        }
        case GZCJStatus.PaymentConfirm: {
            return ['customs_exit_details', 'customs_exit_download', 'customs_exit_payment']
        }
        default: {
            return ['customs_exit_details', 'customs_exit_download']
        }
    }
}

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

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

filterOptons.selectList = [
    {
        label: '单据状态',
        key: 'executestatus',
        options: [
            { label: '待处理', value: 1 },
            { label: '进行中', value: 2 },
            { label: '已结束', value: 3 },
        ],
    },
]

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

onRefresh()
</script>