<template>
    <app-view class="histransfer-order">
        <template #header>
            <app-navbar title="转让委托-已成交" />
        </template>
        <app-pull-refresh 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.transferid }}</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 colspan="3">{{ item.createtime }}</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 { 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 dataList = shallowRef<Model.THJPurchaseTransferOrderRsp[]>([])
const error = shallowRef(false)

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

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