<template>
    <view class="common-page" style="padding: 0" @click="playGlobalSound">
        <PageScroll requestStr="/app/orderreview/reviewOrderList" @updateList="updateList" ref="scrollRef"
            :otherParams="otherParams" :immediate="true">
            <view class="list-con" v-if="dataList.length">
                <ReviewOrderItem v-for="cell in dataList" :key="cell.orderId" :item="cell" class="mt-20" @click="handleReviewOrder(cell)">
                </ReviewOrderItem>
            </view>

            <!-- 底部统计 -->
            <view class="fixed-bottom total-count" v-if="total > 0">
                共计{{ total }}条
            </view>
        </PageScroll>
    </view>
</template>

<script setup>
import { ref } from "vue";
import { onShow } from "@dcloudio/uni-app";
import PageScroll from "@/components/pageScroll/index.vue";
import ReviewOrderItem from "./components/reviewOrderItem.vue";

//点击全局音效
function playGlobalSound() {
    uni.$u.playClickSound();
}

const otherParams = ref({});
const scrollRef = ref(null);
const refreshList = () => {
    scrollRef.value?.resetUpScroll();
};

let dataList = ref([]);
let total = ref(0);

const updateList = (data, page) => {
    dataList.value = data;
    // 假设API返回的数据结构中包含total字段
    // 如果API响应结构不同，需要根据实际情况调整
    if (page && page.total !== undefined) {
        total.value = page.total;
    } else {
        total.value = data.length;
    }
};

const handleReviewOrder = (item) => {
    uni.navigateTo({
        url: `/pages/index/detail/review-detail?id=${item.orderId}`
    });
};

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

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

.total-count {
    background-color: #4caf50;
    color: #ffffff;
    text-align: center;
    padding: 24rpx;
    font-size: 32rpx;
    font-weight: 500;
    margin-top: 20rpx;
    display: flex;
    justify-content: center;
}
</style>
