<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" />
        </app-pull-refresh>
    </app-view>
</template>

<script lang="ts" setup>

import { shallowRef } from 'vue'
import { useNavigation } from '@/hooks/navigation'
import { useQueryWrOutInApply } 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, getWrOutInApply } = useQueryWrOutInApply()
const dataList = shallowRef<Model.WrOutInApplyRsp[]>([])
const error = shallowRef(false)

const columns: Model.TableColumn[] = [
    { prop: 'wrstandardname', label: '商品' },
    { prop: 'qty', label: '数量' },
    { prop: 'applytype', label: '类型' },
    { prop: 'applytime', label: '申请时间' },
    { prop: 'warehousename', label: '仓库' },
    { prop: 'applystatus', label: '状态' },
]

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

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