<!-- 挂牌大厅-出售大厅 -->
<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 #price="{ row }">
                {{ row.zscurrencytypedisplayunit + formatDecimal(row.price) }}
            </template>
            <!-- 克拉单价 -->
            <template #fixedprice="{ row }">
                {{ row.zscurrencytypedisplayunit + formatDecimal(row.fixedprice) }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation :menus="handleTableButtons(row)" :options="{ selectedRow: row }"
                    @closed="getSellOrderList" />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="getSellOrderList" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { formatDecimal } from '@/filters'
import { useLoginStore, useFavoriteStore } from '@/stores'
import { useSellOrder } from '@/business/trade/list'
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 { hasFavorite } = useFavoriteStore()
const { loading, dataList, columns, total, pageIndex, pageSize, selectList, inputList, buttonList, getSellOrderList } = useSellOrder()

// 未收藏的卖委托有收藏按钮
const handleTableButtons = (row: Ermcp.SellOrderRsp) => {
    if (hasFavorite(row.goodsno) || row.userid === getUserId()) {
        return ['details']
    }
    return ['details', 'favorite']
}

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