<!-- 挂牌大厅-我的摘牌 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" :loading="loading">
                <template #after>
                    <el-date-picker type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                        value-format="YYYYMMDD" v-model="filterDate" />
                </template>
            </app-filter>
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="tableColumns" :loading="loading">
            <!-- 价格 -->
            <template #price="{ row }">
                {{ row.zscurrencytypedisplayunit + formatDecimal(row.price) }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation type="dropdown" :options="{ selectedRow: row, buyorsell: buyOrSell }"
                    @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 { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import { formatDecimal } from '@/filters'
import { useDataFilter } from '@/hooks/datatable'
import { useDelistingOrder } from '@/business/trade/list'
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 AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'
import AppFilter from '@pc/components/base/table-filter/index.vue'

const { params } = useRoute()

const buyorsell = (() => {
    const result = Number(params.buyorsell)
    return isNaN(result) ? undefined : result
})()

const { loading, dataList, total, pageIndex, pageSize, buyOrSell, filterDate, categoryList, buyOrSellList, getDelistingOrderList } = useDelistingOrder(buyorsell)
const { tableColumns } = useComposeTable<Ermcp.MyDeListingRsp>({ rowKey: 'wrtradedetailid', columnKey: 'listing_delisting' })
const { filterOptons, getQueryParams } = useDataFilter<Ermcp.MyDeListingReq>()

const onSearch = (clear = false) => {
    if (clear) {
        filterDate.value = []
    }
    getQueryParams((qs) => {
        pageIndex.value = 1
        getDelistingOrderList(qs)
    }, clear)
}

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

filterOptons.selectList = [
    {
        label: '商品分类',
        key: 'zscategorys',
        options: categoryList,
    },
    {
        label: '方向',
        key: 'buyorsell',
        selectedValue: buyOrSell.value,
        locked: true,
        options: buyOrSellList,
    },
]

filterOptons.inputList = [
    { label: '对手方', keys: ['matchusername'] },
    { label: '商品', keys: ['zsallproperties'] },
]

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

onRefresh()
</script>