<!-- 我的订单-供求成交 -->
<template>
    <app-view class="wrtradedetail">
        <app-pull-refresh class="order-list__wrapper" v-model:pageIndex="pageIndex" :page-count="pageCount"
            v-model:error="error" @refresh="onRefresh">
            <ul class="section">
                <li class="section-item" v-for="(item, index) in dataList" :key="index">
                    <div class="section-item__titlebar">
                        <div class="left">
                            <span>{{ item.wrstandardname }}</span>
                            <span>{{ getBuyOrSellName(item.buyorsell) }}</span>
                        </div>
                        <div class="right">
                            <span>{{ formatDate(item.tradetime) }}</span>
                        </div>
                    </div>
                    <div class="section-item__content">
                        <table cellspacing="0" cellpadding="0">
                            <tr>
                                <th>挂牌数量</th>
                                <td>{{ item.tradeqty }}</td>
                                <th>成交价格</th>
                                <td>{{ item.tradeprice }}</td>
                                <th>金额</th>
                                <td>{{ item.tradeqty }}</td>
                            </tr>
                            <tr>
                                <th>仓库</th>
                                <td colspan="5">{{ handleNoneValue(item.warehousename) }}</td>
                            </tr>
                        </table>
                    </div>
                    <div class="section-item__btnbar">
                        <Button size="small" @click="onClick(item)" round>详情</Button>
                    </div>
                </li>
            </ul>
        </app-pull-refresh>
    </app-view>
</template>

<script lang="ts" setup>
import { shallowRef } from 'vue'
import { Button } from 'vant'
import { formatDate, handleNoneValue } from '@/filters'
import { getBuyOrSellName } from '@/constants/order'
import { useQueryWrTradeDetail } from '@/business/order'
import AppPullRefresh from '@mobile/components/base/pull-refresh/index.vue'
import { useNavigation } from '@/hooks/navigation'

const { router } = useNavigation()
const { pageIndex, pageCount, getWrTradeDetail } = useQueryWrTradeDetail()
const dataList = shallowRef<Model.WrTradeDetailRsp[]>([])
const error = shallowRef(false)

const onClick = (item: Model.WrTradeDetailRsp) => {
    router.push({ name: 'wrtrade-detail', params: { item: JSON.stringify(item) } })
}

const onRefresh = (finish: () => void) => {
    /// 查询未完成
    getWrTradeDetail().then((res) => {
        if (pageIndex.value === 1) {
            dataList.value = []
        }
        dataList.value.push(...res)
    }).catch(() => {
        error.value = true
    }).finally(() => {
        finish()
    })
}
</script>