<template>
    <z-paging
        auto-show-back-to-top
        :auto="i == index"
        ref="paging"
        v-model="dataList"
        :data-key="i"
        :fixed="false"
        height="100%"
        :auto-clean-list-when-reload="true"
        :auto-scroll-to-top-when-reload="false"
        :empty-view-img="NoDrawEmpty"
        empty-view-text="暂无记录~"
        @query="queryList"
    >
        <view class="px-[30rpx]">
            <block v-for="(item, index) in dataList" :key="index">
                <DrawCard :value="item" :status="item.status"></DrawCard>
            </block>
        </view>
    </z-paging>
</template>

<script lang="ts" setup>
import { ref, watch, nextTick, shallowRef } from 'vue'
import { drawingRecord } from '@/api/drawing'
import DrawCard from './components/index.vue'
import NoDrawEmpty from '@/packages/static/images/drawing/empty.png'

const emit = defineEmits(['click'])
const props = withDefaults(
    defineProps<{
        i?: number
        index?: number
        status?: number
        setTaskRecordFunc: any
    }>(),
    {
        i: 0,
        index: 0,
        status: 3,
        setTaskRecordFunc: () => {}
    }
)

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

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

const queryList = async (page_no: number, page_size: number) => {
    try {
        const { lists } = await drawingRecord({
            status: props.status,
            page_no,
            page_size
        })
        if (props.i == props.index) {
            props.setTaskRecordFunc({
                reload: paging.value,
                lists: lists
            })
        }
        paging.value.complete(lists)
    } catch (e) {
        console.log('报错=>', e)
        //TODO handle the exception
        paging.value.complete(false)
    }
}
</script>

<style scoped></style>
