<!-- WMS结算单 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" />
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="tableColumns" :loading="loading">
            <!-- 操作 -->
            <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 { shallowRef } from 'vue'
import { ElMessage } from 'element-plus'
import { useDataFilter } from '@/hooks/datatable'
import { useRequest } from '@/hooks/request'
import { queryGzbscreckonorder } from '@/services/api/bonded'
import AppTable from '@pc/components/base/table/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import AppFilter from '@pc/components/base/table-filter/index.vue'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'

const { filterOptons, getQueryParams } = useDataFilter<Ermcp.GzbscreckonorderReq>()
const { loading, dataList, total, pageIndex, pageSize, run } = useRequest(queryGzbscreckonorder, {
    params: {
        paystatus: 2,
        pagesize: 20,
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = shallowRef<Ermcp.TableColumn[]>([
    { prop: 'reckonmonth', label: '结算月份' },
    { prop: 'totalfee', label: '总费用', decimal: 2 },
    { prop: 'servicefee', label: '分拣室服务费', decimal: 2 },
    { prop: 'storagefee', label: '仓储费', decimal: 2 },
    { prop: 'premium', label: '保险费', decimal: 2 },
    { prop: 'powerfee', label: '分拣室电费', decimal: 2 },
    { prop: 'customsfee', label: '报关费', decimal: 2 },
    { prop: 'applicanttime', label: '申请时间' },
    { prop: 'paytime', label: '支付时间' },
    { prop: 'operate', label: '操作', fixed: 'right' },
])

filterOptons.selectList = [
    {
        label: '支付状态',
        key: 'paystatus',
        selectedValue: 2,
        options: [
            { label: '待支付', value: 2 },
            { label: '已支付', value: 3 },
        ],
    },
]

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

// “2：待支付”的有操作”支付“
const handleOperateButtons = (row: Ermcp.GzbscreckonorderRsp) => {
    if (row.paystatus === 2) {
        return ['wms_list_payment']
    }
    return []
}

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

const onRefresh = () => {
    getQueryParams((qs) => run(qs))
}
</script>