<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 { Button } from 'vant'
import { useNavigation } from '@/hooks/navigation'
import { useQueryHoldLB } 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, getHoldLB } = useQueryHoldLB()
const dataList = shallowRef<Model.HoldLBRsp[]>([])
const error = shallowRef(false)

const columns: Model.TableColumn[] = [
    { prop: 'wrstandardname', label: '商品' },
    { prop: 'qty', label: '库存' },
    { prop: 'freezerqty', label: '冻结' },
    { prop: 'enableqty', label: '可用' },
    { prop: 'warehousename', label: '仓库' }
]

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

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