<template>
    <div class="service-list">
        <div class="chart-title">
            <div class="name">
                <img src="@/assets/images/common/chart-icon.png" alt="" />
                <span>农服管理</span>
            </div>
        </div>
        <div class="service-content">
            <div class="service-item"
                v-for="(item, index) in serviceList"
                @click="handleServiceClick(item, index)"
                :class="{ active: activeService === index }"
                :key="index">
                <div class="service-header">
                    <div class="service-image">
                        <img :src="item.image || 'https://birdseye-img.sysuimars.com/dinggou-mini/defalut-icon.png'" alt="" />
                    </div>
                    <div class="service-info">
                        <div class="service-title-row">
                            <div class="service-title">{{ item.name }}</div>
                            <div class="service-tags">
                                <span class="tag" v-for="(tag, tagIndex) in item.tags" :key="tagIndex">{{ tag }}</span>
                            </div>
                        </div>
                        <div class="service-location">
                            <div class="location-item">
                                <span class="location-label">主体位置:</span>
                                <span class="location-value">{{ item.mainLocation }}</span>
                            </div>
                            <div class="location-item">
                                <span class="location-label">农场位置:</span>
                                <span class="location-value">{{ item.farmLocation }}</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="service-stats">
                    <div class="stat-box">
                        <div class="stat-value"><span class="stat-value-num">{{ item.serviceArea }}</span><span class="stat-unit">亩</span></div>
                        <div class="stat-label">服务亩数</div>
                    </div>
                    <div class="stat-box">
                        <div class="stat-value"><span class="stat-value-num">{{ item.deviceCount }}</span><span class="stat-unit">个</span></div>
                        <div class="stat-label">设备数量</div>
                    </div>
                    <div class="stat-box">
                        <div class="stat-value"><span class="stat-value-num">{{ item.teamMembers }}</span><span class="stat-unit">人</span></div>
                        <div class="stat-label">团队成员</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref } from "vue";

// 默认图片
const defaultImage = "https://via.placeholder.com/120x120";

// 服务列表数据
const serviceList = ref([
    {
        name: "农资名称名称农资名称名称农资名称名称",
        tags: ["荔枝", "井岗红糯"],
        mainLocation: "广东省广州市荔湾区开发大道",
        farmLocation: "广东省广州市荔湾区",
        serviceArea: "1585",
        deviceCount: "1585",
        teamMembers: "500",
    },
    {
        name: "农资名称名称",
        tags: ["荔枝", "井岗红糯"],
        mainLocation: "广东省广州市***",
        farmLocation: "广东省广州市***",
        serviceArea: "1585",
        deviceCount: "1585",
        teamMembers: "500",
    },
    {
        name: "农资名称名称",
        tags: ["荔枝", "井岗红糯"],
        mainLocation: "广东省广州市***",
        farmLocation: "广东省广州市***",
        serviceArea: "1585",
        deviceCount: "1585",
        teamMembers: "500",
    },
]);

const activeService = ref(null);
const handleServiceClick = (item, index) => {
    activeService.value = index;
};
</script>

<style lang="scss" scoped>
.service-list {
    width: 100%;
    height: 100%;
    background: #232323;
    border-radius: 4px;
    box-sizing: border-box;
    border: 1px solid #444444;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    .chart-title {
        width: 100%;
        height: 38px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: rgba(255, 255, 255, 0.05);
        padding-right: 12px;
        box-sizing: border-box;
        flex: none;
        .name {
            display: flex;
            align-items: center;
            padding: 0 12px;
            span {
                font-size: 18px;
                margin-left: 6px;
                font-family: "SOURCEHANTIFINE";
                margin-right: 8px;
            }
        }
    }

    .service-content {
        flex: 1;
        overflow-y: auto;
        padding: 10px;
        box-sizing: border-box;

        .service-item {
            border: 0.3px solid rgba(239, 239, 239, 0.2);
            border-radius: 5px;
            margin-bottom: 12px;
            padding: 10px;
            box-sizing: border-box;
            cursor: pointer;
            &.active {
                background: rgba(23, 15, 0, 0.55);
                border-color: #FFD489;
            }

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

            .service-header {
                display: flex;
                margin-bottom: 12px;

                .service-image {
                    width: 64px;
                    height: 64px;
                    flex-shrink: 0;
                    border-radius: 6px;
                    margin-right: 12px;

                    img {
                        width: 100%;
                        height: 100%;
                        border-radius: 6px;
                        object-fit: cover;
                    }
                }

                .service-info {
                    flex: 1;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;

                    .service-title-row {
                        display: flex;
                        align-items: center;
                        margin-bottom: 4px;

                        .service-title {
                            font-size: 16px;
                            font-weight: 500;
                            color: #fff;
                            flex: 1;
                            padding-right: 8px;
                            word-wrap: break-word;
                            word-break: break-all;
                            line-height: 1.4;
                        }

                        .service-tags {
                            display: flex;
                            gap: 4px;

                            .tag {
                                padding: 1px 6px;
                                border: 0.2px solid #FFD489;
                                border-radius: 2px;
                                font-size: 12px;
                                color: #FFD489;
                            }
                        }
                    }

                    .service-location {
                        display: flex;
                        flex-direction: column;
                        color: #9F9F9F;

                        .location-item {
                            font-size: 12px;

                            .location-label {
                                margin-right: 8px;
                            }
                        }
                    }
                }
            }

            .service-stats {
                display: flex;
                gap: 12px;

                .stat-box {
                    flex: 1;
                    background: rgba(255, 255, 255, 0.05);
                    border: 0.3px solid rgba(255, 212, 137, 0.1);
                    border-radius: 2px;
                    padding: 8px 4px;
                    text-align: center;
                    box-sizing: border-box;

                    .stat-value {
                        color: #fff;
                        margin-bottom: 2px;
                        .stat-value-num {
                            font-size: 20px;
                            font-family: "PangMenZhengDao";
                            color: #fff;
                        }
                        .stat-unit {
                            font-size: 12px;
                            padding-left: 2px;
                        }
                    }

                    .stat-label {
                        font-size: 12px;
                        color: rgba(255, 255, 255, 0.7);
                    }
                }
            }
        }
    }
}
</style>
