<template>
    <div class="agricultural-detail">
        <custom-header name="农事详情"></custom-header>

        <div class="detail-content">
            <!-- 采样信息卡片 -->
            <div class="card-wrap">
                <div class="card-box sampling-card">
                    <div class="sampling-title">采样时间: {{ imgInfo.samplingTime }}</div>
                    <div class="sampling-desc">本次飞巡采样了1区、2区和5区，拍摄了 120棵树</div>
                </div>
            </div>

            <!-- 农情照片卡片 -->
            <div class="card-wrap">
                <div class="card-box photo-card">
                    <div class="card-title">农情照片</div>
                    <div class="ratio-tip">出现新梢的果树占比为5%</div>
                    <div class="photo-grid">
                        <div
                            v-for="photo in imgInfo.imageList"
                            :key="photo.id"
                            class="photo-item"
                            @click="handlePhotoClick(photo.url)"
                        >
                            <img :src="photo.url" alt="农情照片" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { useRoute } from "vue-router";
import { ref, onMounted } from "vue";
import customHeader from "@/components/customHeader.vue";
import { showImagePreview } from 'vant';

const route = useRoute();

const handlePhotoClick = (photo) => {
    showImagePreview({
        images: [photo],
        startPosition: 0,
        closeable: true,
        showIndex: true,
    });
};

onMounted(() => {
    getFarmImagePage();
});

const imgInfo = ref({});
const getFarmImagePage = () => {
    VE_API.monitor.getFarmImagePage({
        farmId: route.query.farmId,
        regionId: route.query.regionId,
        uploadDate: route.query.date,
    }).then((res) => {
        if (res.code === 0) {
            imgInfo.value = res.data;
        }
    });
};
</script>

<style lang="scss" scoped>
.agricultural-detail {
    min-height: 100vh;
    width: 100%;
    background: #f2f3f5;

    .detail-content {
        padding: 12px;
        padding-bottom: 24px;
        box-sizing: border-box;

        .card-wrap {
            margin-bottom: 12px;

            .card-box {
                background: #fff;
                border-radius: 8px;
                padding: 12px 16px;
                box-sizing: border-box;
            }

            .sampling-card {
                .sampling-title {
                    font-size: 16px;
                    font-weight: 500;
                    color: #333;
                    margin-bottom: 6px;
                }

                .sampling-desc {
                    font-size: 14px;
                    color: rgba(0, 0, 0, 0.5);
                }
            }

            .photo-card {
                .card-title {
                    font-size: 16px;
                    font-weight: bold;
                    color: #333;
                    margin-bottom: 12px;
                }

                .ratio-tip {
                    font-size: 14px;
                    color: #2199f8;
                    padding: 10px 12px;
                    background: rgba(33, 153, 248, 0.08);
                    border-radius: 8px;
                }

                .photo-grid {
                    margin-top: 12px;
                    display: grid;
                    grid-template-columns: repeat(4, 1fr);
                    grid-gap: 6px;

                    .photo-item {
                        position: relative;
                        width: 100%;
                        padding-bottom: 100%;
                        border-radius: 8px;
                        overflow: hidden;
                        background: #e5f5e5;

                        img {
                            position: absolute;
                            inset: 0;
                            width: 100%;
                            height: 100%;
                            object-fit: cover;
                            display: block;
                        }
                    }
                }
            }
        }
    }
}

.image-popup {
    width: 327px;
    border-radius: 8px;

    .popup-content {
        width: 100%;
    }
}
</style>