<!-- 挂牌大厅-求购大厅 -->
<template>
    <app-view>
        <template #header>
            <app-filter v-bind="{ selectList, inputList, buttonList }" :loading="loading" />
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="columns" :loading="loading">
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation :menus="handleOperateButtons(row)" :options="{ selectedRow: row }"
                    @closed="getBuyOrderList" />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="getBuyOrderList" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { useBuyOrder } from '@/business/trade/list'
import { useLoginStore } from '@/stores'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'
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 { getUserId } = useLoginStore()
const { loading, dataList, columns, total, pageIndex, pageSize, selectList, inputList, buttonList, getBuyOrderList } = useBuyOrder()
const operateButtons = ['details', 'delisting']

const handleOperateButtons = (row: Ermcp.SellOrderRsp) => {
    if (row.userid === getUserId()) {
        // 自己上架的商品不能摘牌
        return operateButtons.filter((code) => !['delisting'].includes(code))
    }
    return operateButtons
}

getBuyOrderList().catch((err) => ElMessage.error(err))
</script>