<template>
    <z-paging
        auto-show-back-to-top
        :auto="i == index"
        ref="paging"
        v-model="dataList"
        :data-key="i"
        @query="queryList"
        :fixed="false"
        height="100%"
    >
        <block v-for="(item2, index) in dataList" :key="index">
            <wait
                :name="item2.goodsName"
                :image="item2.goodsImage"
                :unit_name="item2.unitName"
                :price="item2.goodsPrice"
                :goodsId="item2.id"
                :finishTime="item2.finishTime"
            ></wait>
        </block>
    </z-paging>
</template>

<script lang="ts" setup>
import { ref, watch, nextTick, shallowRef, unref } from 'vue'
import Wait from './wait.vue'
import { apiWaitEvaluateGoodsLists } from '@/api/goods'
import { onShow } from '@dcloudio/uni-app'

const props = withDefaults(
    defineProps<{
        type: number
        count: number
        i: number
        index: number
    }>(),
    {
        type: 0,
        count: 0
    }
)

const paging = shallowRef<any>(null)
const dataList = ref<any>([])
const isFirst = ref<boolean>(true)

watch(
    () => props.index,
    async () => {
        await nextTick()
        if (props.i == props.index && unref(isFirst)) {
            isFirst.value = false
            paging.value?.reload()
        }
    },
    { immediate: true }
)

const queryList = async (pageNo = 1, pageSize = 10) => {
    try {
        const { lists } = await apiWaitEvaluateGoodsLists({
            pageNo,
            pageSize
        })

        paging.value.complete(lists)
    } catch (e) {
        console.log('报错=>', e)
        //TODO handle the exception
        paging.value.complete(false)
    }
}

onShow(() => {
    // paging.value?.reload()
})
</script>

<style scoped></style>
