<!-- 我的收藏 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" />
        </template>
        <app-table :data="dataList" v-model:columns="tableColumns" :loading="loading">
            <!-- 我的出价 -->
            <template #price="{ row }">
                {{ row.zscurrencytypedisplayunit + formatDecimal(row.price) }}
            </template>
            <!-- 克拉单价 -->
            <template #priceper="{ row }">
                {{ row.zscurrencytypedisplayunit + formatDecimal(row.priceper) }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation type="dropdown" :options="{ selectedRow: row }" @closed="getFavoriteList" />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { formatDecimal } from '@/filters'
import { useDataFilter } from '@/hooks/datatable'
import { useFavorite } from '@/business/favorite'
import { Category } from '@/constants/diamond'
import { useComposeTable } from '@pc/components/base/table'
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 { loading, dataList, filters, total, pageIndex, pageSize, getFavoriteList } = useFavorite()
const { tableColumns } = useComposeTable<Ermcp.MyFavoriteRsp>({ rowKey: 'wrtradeorderid', columnKey: 'favorite' })
const { filterOptons, getFilterParams } = useDataFilter<Ermcp.MyFavoriteRsp>()

const onSearch = (clear = false) => {
    getFilterParams((params) => {
        pageIndex.value = 1
        filters.value = params
    }, clear)
}

const onRefresh = () => {
    getFilterParams((params) => filters.value = params)
}

filterOptons.selectList = [
    {
        label: '商品分类',
        key: 'zscategory',
        options: [
            { label: '单颗裸钻', value: Category.Diamond },
            { label: '单颗彩钻', value: Category.Fancy }
        ],
    },
]

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

onRefresh()
</script>