<!-- 我的订单-转让成交 -->
<template>
    <app-view class="order-list-purchase">
        <app-pull-refresh ref="pullRefreshRef" class="order-list__wrapper" v-model:loading="loading" v-model:error="error"
            v-model:pageIndex="pageIndex" :page-count="pageCount" @refresh="run">
            <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>{{ item.wrtradedetailid }}</span>
                        </div>
                    </div>
                    <div class="section-item__content">
                        <table cellspacing="0" cellpadding="0">
                            <tr>
                                <th>交收月份</th>
                                <td>{{ item.enddatemonth }}</td>
                                <th>交易日</th>
                                <td>{{ item.tradedate }}</td>
                            </tr>
                            <tr>
                                <th>转让价格</th>
                                <td>{{ handleNumberValue(item.transferprice) }}</td>
                                <th>数量</th>
                                <td>{{ item.transferqty.toString() + getGoodsUnitName(item.unitid) }}</td>
                            </tr>
                            <tr>
                                <th>转让金额</th>
                                <td>{{ handleNumberValue(item.transferamount) }}</td>
                                <th>预付款</th>
                                <td>{{ handleNumberValue(item.tradeprice) }}</td>
                            </tr>
                            <tr>
                                <th>成交时间</th>
                                <td>{{ item.transfertradetime }}</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, onActivated } from 'vue'
import { Button } from 'vant'
import { useNavigation } from '@/hooks/navigation'
import { getGoodsUnitName } from '@/constants/unit'
import { handleNumberValue } from '@/filters'
import { useRequest } from '@/hooks/request'
import { queryTHJPurchaseTransferOrder } from '@/services/api/order'
import AppPullRefresh from '@mobile/components/base/pull-refresh/index.vue'

const { router } = useNavigation()
const pullRefreshRef = shallowRef()
const dataList = shallowRef<Model.THJPurchaseTransferOrderRsp[]>([])
const error = shallowRef(false)

const { loading, pageIndex, pageCount, run } = useRequest(queryTHJPurchaseTransferOrder, {
    manual: true,
    params: {
        pagesize: 20,
        ordertype: 2,
    },
    onSuccess: (res) => {
        if (pageIndex.value === 1) {
            dataList.value = []
        }
        dataList.value.push(...res.data)
    },
    onError: () => {
        error.value = true
    }
})

const onClick = (item: Model.THJPurchaseTransferOrderRsp) => {
    router.push({ name: 'transfer-detail', query: { id: item.transferid } })
}

onActivated(() => {
    pullRefreshRef.value?.refresh()
})
</script>