<!-- 我的订单-供求委托 -->
<template>
    <app-view class="wrorderdetail">
        <app-pull-refresh class="order-list__wrapper" v-model:pageIndex="pageIndex" v-model:error="error"
            :page-count="pageCount" @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>
                        </div>
                        <div class="right">
                            <span>{{ getWRTradeOrderStatusName(item.wrtradeorderstatus) }}</span>
                        </div>
                    </div>
                    <div class="section-item__content">
                        <table cellspacing="0" cellpadding="0">
                            <tr>
                                <th>挂牌数量</th>
                                <td>{{ item.orderqty }}</td>
                                <th>挂牌价格</th>
                                <td>{{ item.fixedprice }}</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 { handleNoneValue } from '@/filters'
import { getWRTradeOrderStatusName } from '@/constants/order'
import { useQueryWrOrderDetail } from '@/business/order'
import AppPullRefresh from '@mobile/components/base/pull-refresh/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 onClick = (item: Model.WrOrderDetailRsp) => {
    router.push({ name: 'wrorder-detail', params: { item: JSON.stringify(item) } })
}

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