<template>
    <view class="review-order-card">
        <!-- 订单信息 -->
        <view class="order-info">
            <view class="info-row">
                <text class="label">订单号：</text>
                <text class="value">{{ item.orderId }}</text>
            </view>
            <view class="info-row">
                <text class="label">仓库：</text>
                <text class="value">{{ item.godownName }}</text>
            </view>
            <view class="info-row">
                <text class="label">不良数量：</text>
                <text class="value">{{ item.reviewNum || 0 }}</text>
            </view>
            <view class="info-row">
                <text class="label">是否入库：</text>
                <text class="value">{{ stockStatusText }}</text>
                <text v-if="item.positionCode" class="position-code">{{ item.positionCode }}</text>
            </view>
            <view class="info-row">
                <text class="label">申请复审时间：</text>
                <text class="value">{{ item.applyTime }}</text>
            </view>
            <view class="info-row">
                <text class="label">已用时长：</text>
                <TimeClock :initialSeconds="item.waitingTime" />
            </view>
        </view>
    </view>
</template>

<script setup>
import { computed } from "vue";
import TimeClock from "./time-clock.vue";

const props = defineProps({
    item: {
        type: Object,
        default: () => { },
    },
});

// 库存状态文本
const stockStatusText = computed(() => {
    if (props.item.stockStatus === 1) {
        return "已入库";
    } else if (props.item.stockStatus === 0) {
        return "未入库";
    }
    return "-";
});

// 库存状态颜色
const stockStatusColor = computed(() => {
    if (props.item.stockStatus === 1) {
        return "#FF4D4F"; // 红色 - 已入库
    } else if (props.item.stockStatus === 0) {
        return "#333333"; // 黑色 - 未入库
    }
    return "#999999";
});

// 格式化等待时长（毫秒转为时:分:秒）
const formatWaitingTime = (milliseconds) => {
    if (!milliseconds) return "00:00:00";

    const totalSeconds = Math.floor(milliseconds / 1000);
    const hours = Math.floor(totalSeconds / 3600);
    const minutes = Math.floor((totalSeconds % 3600) / 60);
    const seconds = totalSeconds % 60;

    const pad = (num) => String(num).padStart(2, '0');

    return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
};
</script>

<style lang="scss" scoped>
.review-order-card {
    background: #ffffff;
    border-radius: 8rpx;
    padding: 24rpx;
    margin-bottom: 20rpx;
    box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);

    .order-info {
        .info-row {
            display: flex;
            align-items: center;
            margin-bottom: 16rpx;
            font-size: 28rpx;
            line-height: 40rpx;

            &:last-child {
                margin-bottom: 0;
            }

            .label {
                color: #333333;
                font-weight: 400;
            }

            .value {
                color: #333333;
                flex: 1;

                &.time-duration {
                    color: #FF4D4F;
                    font-weight: 500;
                }
            }

            .position-code {
                color: #E87A20FF;
                margin-left: 16rpx;
                font-weight: 500;
            }
        }
    }
}
</style>
