<template>
    <view class="common-page" style="padding: 0;">
        <PageScroll
            requestStr="/app/workOrder/getMyHandleWorkOrder"
            @updateList="updateList"
            ref="scrollRef"
            :otherParams="otherParams"
            method="get"
        >
            <view class="list-con" v-if="dataList.length">
                <WorkorderItem
                    v-for="(cell, idx) in dataList"
                    :key="idx"
                    :item="cell"
                    :showDuration="false"
                    @click="goDetail(cell)"
                    class="mt-20"
                />
            </view>
        </PageScroll>
    </view>
</template>

<script setup>
import { ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import PageScroll from '@/components/pageScroll/index.vue'
import WorkorderItem from '../components/workorder-item.vue'

const dataList = ref([])
const scrollRef = ref(null)

const otherParams = ref({
    type: 1 // 工单类型：1-卖书
})

const updateList = (data, page) => {
    // 如果data是响应对象，提取rows
    const rows = data?.rows || data
    dataList.value = Array.isArray(rows) && rows.length ? rows : []
}

const refreshList = () => {
    scrollRef.value?.resetUpScroll()
}

const goDetail = (cell) => {
    const id = cell?.id || ''
    uni.navigateTo({
        url: `/pages/order/mall/detail?id=${id}`
    })
}

onShow(() => {
    refreshList()
})
</script>

<style lang="scss" scoped>
.list-con {
    padding: 10rpx 30rpx;
    gap: 30rpx;
}
</style>
