<template>
    <app-view class="order-list-purchase">
        <app-pull-refresh v-model:error="error" v-model:pageIndex="pageIndex" :page-count="pageCount"
            @refresh="onRefresh">
            <app-list :columns="columns" :data-list="dataList" @click="onClick" />
            <!-- <Button>更多</Button> -->
        </app-pull-refresh>
    </app-view>
</template>

<script lang="ts" setup>

import { shallowRef } from 'vue'
import { useNavigation } from '@/hooks/navigation'
import { useTHJPurchaseTradeDetail } from '@/business/order'
import AppPullRefresh from '@mobile/components/base/pull-refresh/index.vue'
import AppList from '@mobile/components/base/list/index.vue'

const { router } = useNavigation()
const { pageIndex, pageCount, getTHJPurchaseTradeDetail } = useTHJPurchaseTradeDetail()
const dataList = shallowRef<Model.THJPurchaseTradeDetailRsp[]>([])
const error = shallowRef(false)

const columns: Model.TableColumn[] = [
    { prop: 'wrstandardname', label: '商品' },
    { prop: 'tradeqty', label: '数量' },
    { prop: 'tradeprice', label: '预售价' },
    { prop: 'lastprice', label: '实际价' },
    { prop: 'payeddeposit', label: '定金' },
    { prop: 'remainamount', label: '尾款' },
    { prop: 'thjorderstatusdisplay', label: '状态' },
]

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

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