<!-- 挂牌大厅-求购大厅 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" :loading="loading" />
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="tableColumns" :loading="loading">
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation type="dropdown" :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 { useBuyOrder } from '@/business/trade/list'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'
import { useComposeTable } from '@pc/components/base/table'
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'

const { loading, dataList, total, pageIndex, pageSize, categoryList, getBuyOrderList } = useBuyOrder()
const { tableColumns } = useComposeTable<Ermcp.BuyOrderRsp>({ rowKey: 'wrtradeorderid', columnKey: 'listing_buyorder' })
const { filterOptons, getQueryParams } = useDataFilter<Ermcp.BuyOrderReq>()

filterOptons.selectList = [
    {
        label: '商品分类',
        key: 'zscategorys',
        options: categoryList,
    },
]

filterOptons.inputList = [
    { label: '买方', keys: ['buyusername'] },
    { label: '商品', keys: ['zsallproperties'] },
]

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

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

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

onRefresh()
</script>