<!-- 保税仓业务-进仓管理 -->
<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="['bonded_inbound_apply']" @closed="onRefresh" />
            </template>
            <!-- 单据状态 -->
            <template #orderstatus="{ value }">
                {{ getGZBSCOrderStatusName(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 { GZBSCOrderType, getGZBSCOrderStatusName } from '@/constants/bonded'
import { useGzbscinOutOrder } 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, getGzbscinOutOrder } = useGzbscinOutOrder()
const { tableColumns } = useComposeTable<Ermcp.GzbscinOutOrderRsp>({ rowKey: 'orderid', columnKey: 'bonded_inbound' })
const { filterOptons, getQueryParams } = useDataFilter<Ermcp.GzbscinOutOrderReq>()

// 状态”2.待上传 “多操作：“上传”
const handleOperateButtons = (row: Ermcp.GzbscinOutOrderRsp) => {
    const buttons = ['bonded_inbound_details', 'bonded_inbound_download']
    if (row.orderstatus === 2) {
        buttons.push('bonded_inbound_upload')
    }
    return buttons
}

const onSearch = (clear = false) => {
    getQueryParams((qs) => {
        qs.ordertype = GZBSCOrderType.In
        pageIndex.value = 1
        getGzbscinOutOrder(qs)
    }, clear)
}

const onRefresh = () => {
    getQueryParams((qs) => {
        qs.ordertype = GZBSCOrderType.In
        getGzbscinOutOrder(qs).catch((err) => ElMessage.error(err))
    })
}

filterOptons.selectList = [
    {
        label: '单据状态',
        key: 'listtype',
        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>