<!-- 挂牌大厅-我的询价 -->
<template>
    <app-view>
        <template #header>
            <app-filter v-bind="{ selectList,  buttonList }" :loading="loading" />
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="columns" :loading="loading">
            <!-- 申请状态 -->
            <template #applystatus="{ value }">
                {{ getApplyStatusName(value) }}
            </template>
            <!-- 克拉单价 -->
            <template #priceper="{ row }">
                {{ row.zscurrencytypedisplayunit + formatDecimal(row.priceper) }}
            </template>
            <!-- 我的出价 -->
            <template #applyprice="{ row }">
                {{ row.zscurrencytypedisplayunit + formatDecimal(row.applyprice) }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation :menus="handleTableButtons(row)" :options="{ selectedRow: row }"
                    @closed="getBargainOrderList" />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="getBargainOrderList" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { formatDecimal } from '@/filters'
import { useBargain } from '@/business/bargain'
import { getApplyStatusName, ApplyStatus } from '@/constants/order'
import AppTable from '@pc/components/base/table/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'
import AppFilter from '@pc/components/base/table-filter/index.vue'

const { loading, dataList, total, pageIndex, pageSize, columns, selectList, buttonList, getBargainOrderList } = useBargain()

// “待确认”状态 有撤销按钮
const handleTableButtons = (row: Ermcp.MyBargainApplyRsp | Ermcp.MyDelistingApplyRsp) => {
    if (row.applystatus === ApplyStatus.Pending) {
        return ['details', 'cancel']
    }
    return ['details']
}

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