<template>
    <view class="common-page" style="padding: 0;">
        <PageScroll
            requestStr="/app/workorder/pending"
            @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: 'mall',
    status: 'pending'
})

const updateList = (data, page) => {
    const mock = [
        { waybillCode: 'YT54454654564', taskTypeName: '部分发货', createTime: '2026-05-11 15:00:00' },
        { waybillCode: 'YT54454654564', taskTypeName: '部分发货', createTime: '2026-05-11 15:00:00' },
        { waybillCode: 'YT54454654564', taskTypeName: '部分发货', createTime: '2026-05-11 15:00:00' },
        { waybillCode: 'YT54454654564', taskTypeName: '部分发货', createTime: '2026-05-11 15:00:00' },
        { waybillCode: 'YT54454654564', taskTypeName: '部分发货', createTime: '2026-05-11 15:00:00' },
    ]
    dataList.value = Array.isArray(data) && data.length ? data : mock
}

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

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

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

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