<template>
    <view class="order-detail">
        <!-- 标签页 -->
        <view class="tabs-wrapper">
            <u-tabs :list="tabList" :current="currentTab" @change="handleTabChange" :is-scroll="false"
                active-color="#38C148" bar-width="60"></u-tabs>
        </view>

        <!-- 订单列表 -->
        <page-scroll :page-size="12" @updateList="handleUpdateList" ref="pageRef" slotEmpty
            url="/token/userPartner/geOrderList" :params="params" :immediate="false">
            <view v-if="orderList.length > 0" class="pad-20">
                <partner-order-item v-for="order in orderList" :key="order.orderNo" :order="order"></partner-order-item>
            </view>
        </page-scroll>
    </view>
</template>

<script>
import PartnerOrderItem from '../../components/partner-order-item.vue'
import pageScroll from '@/components/pageScroll/index.vue'

export default {
    components: {
        PartnerOrderItem,
        pageScroll,
    },
    data() {
        return {
            tabList: [{
                name: '全部',
                status: "NULL"
            },
            {
                name: '未结算',
                status: "1"
            },
            {
                name: '未到账',
                status: "2"
            },
            {
                name: '已到账',
                status: "3"
            },
            {
                name: '已失效',
                status: "4"
            }
            ],
            currentTab: 0,
            orderList: [],
            params: {},
            // 模拟数据
            mockOrders: []
        }
    },
    onLoad(options) {
        // 如果有传入状态，切换到对应tab
        if (options.status) {
            this.currentTab = this.tabList.findIndex(item => item.status === options.status)
            this.params.status = options.status
        }
        this.loadOrders(true, this.params)
    },
    methods: {
        loadOrders(bool = false, params = {}) {
            this.$refs.pageRef?.loadData(bool, params);
        },

        handleTabChange(index) {
            this.currentTab = index
            this.params.status = this.tabList[index].status
            this.loadOrders(true, this.params)
        },

        handleUpdateList(list) {
            this.orderList = list
        }
    }
}
</script>

<style lang="scss" scoped>
.order-detail {
    min-height: 100vh;
    background-color: #F5F5F5;

    .tabs-wrapper {
        position: sticky;
        top: 0;
        z-index: 99;
        background: #FFFFFF;
    }

    .pad-20 {
        padding: 20rpx;
    }
}
</style>
