<template>
    <app-view class="wrorderdetail">
        <app-pull-refresh v-model:pageIndex="pageIndex" v-model:error="error" :page-count="pageCount"
            @refresh="onRefresh">
            <app-list :columns="columns" :data-list="dataList" @click="onClick">
                <!-- 方向 -->
                <template #buyorsell="{ value }">
                    {{ getBuyOrSellName(value) }}
                </template>
                <!-- 状态 -->
                <template #wrtradeorderstatus="{ value }">
                    {{ getTHJOrderStatusName(value) }}
                </template>
            </app-list>
            <!-- <Button>更多</Button> -->
        </app-pull-refresh>
    </app-view>
</template>

<script lang="ts" setup>

import { shallowRef } from 'vue'
// import { Button } from 'vant'
import { getTHJOrderStatusName, getBuyOrSellName } from '@/constants/order'
import { useQueryWrOrderDetail } from '@/business/order'
import AppPullRefresh from '@mobile/components/base/pull-refresh/index.vue'
import AppList from '@mobile/components/base/list/index.vue'
import { useNavigation } from '@/hooks/navigation'

const { router } = useNavigation()
const { pageIndex, pageCount, getWrOrderDetail } = useQueryWrOrderDetail()
const dataList = shallowRef<Model.WrOrderDetailRsp[]>([])
const error = shallowRef(false)

const columns: Model.TableColumn[] = [
    { prop: 'wrstandardname', label: '商品' },
    { prop: 'buyorsell', label: '方向' },
    { prop: 'fixedprice', label: '挂牌价格' },
    { prop: 'orderqty', label: '挂牌数量' },
    { prop: 'tradeqty', label: '成交数量' },
    { prop: 'wrtradeorderstatus', label: '状态' },
]

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

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