<!-- 集采交易-我参与的集采 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" />
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="tableColumns" :loading="loading">
            <!-- 采购保证金(%) -->
            <template #marginvalue="{ value }">
                {{ parsePercent(value) }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation type="dropdown" :menus="['centralize_partake_details']" :options="{ selectedRow: row }"
                    @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 { shallowRef } from 'vue'
import { ElMessage } from 'element-plus'
import { parsePercent } from '@/filters'
import { useDataFilter } from '@/hooks/datatable'
import { useRequest } from '@/hooks/request'
import { queryGZMyTradingPreSell } from '@/services/api/presale'
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'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'

const { filterOptons, getQueryParams } = useDataFilter<Ermcp.GZMyTradingPreSellReq>()
const { loading, dataList, total, pageIndex, pageSize, run } = useRequest(queryGZMyTradingPreSell, {
    params: {
        pagesize: 20,
        marketid: 62201,
        status: 1,
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = shallowRef<Ermcp.TableColumn[]>([
    { prop: 'customername', label: '卖方' },
    { prop: 'wrstandardname', label: '商品' },
    { prop: 'orderqty', label: '采购数量(克拉)' },
    { prop: 'tradeprice', label: '采购价格(元/克拉)', width: 140 },
    { prop: 'tradeamount', label: '货款' },
    { prop: 'marginvalue', label: '保证金比例(%)' },
    { prop: 'freezemargin', label: '已付保证金' },
    { prop: 'ordertime', label: '认购时间' },
    { prop: 'operate', label: '操作', fixed: 'right' },
])

filterOptons.selectList = [
    {
        label: '状态',
        key: 'status',
        locked: true,
        selectedValue: 1,
        options: [
            { label: '集采中', value: 1 },
            { label: '执行中', value: 2 },
            { label: '已完成', value: 3 }
        ],
    },
]

filterOptons.inputList = [
    { label: '卖方', keys: ['customername'] },
    { label: '商品', keys: ['wrstandardname'] },
]

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

const onSearch = (clear = false) => {
    getQueryParams((qs) => {
        pageIndex.value = 1
        run(qs)
    }, clear)
}

const onRefresh = () => {
    getQueryParams((qs) => run(qs))
}
</script>