<template>
    <div class="item flexflex" @click="goapArtmentDetails">
        <!-- <div class="collect-box flexcenter" @click.stop="handleCollect(item)"> -->
            <!-- <img class="collect-icon" style="width: 30px; height: 30px;" src="@/assets/img/apartmentDetail/collecting-shadows.svg" /> -->
            <!-- <img class="collect-icon" src="@/assets/img/apartmentDetail/collecting-yellow-shadows.svg" /> -->
        <!-- </div> -->
        <img class="img" v-lazy="item['image']" />
        <div class="title">{{ item["title"] }}</div>
        <div class="hint">{{ item["propaganda"] }}</div>
        <div class="tab-box flexflex" v-if="item['tags']">
            <div class="tab-item flexcenter" v-for="(it, index) in item['tags'].split(',')" :key="index">{{ it }}</div>
        </div>
        <div class="location flexacenter" v-if="item['address']">
            <img class="location-icon" src="@/assets/img/publicImage/location-icon.png" />
            <div class="ellipsis">{{ item["address"] }}</div>
            <span class="area-distance" v-if="pitchValue['school'] && item['distance']">{{ Math.round(item["distance"] * 10) / 10 }}km</span>
        </div>

        <div class="type-list" v-if="item['roomlist']">
            <div class="type-item flexacenter" v-for="(it, index) in item['roomlist']" :key="index">
                <div class="type-name flex1 ellipsis">{{ it["name"] }}</div>
                <div class="type-data flexacenter">
                    <div class="unit">HK$</div>
                    <div class="price">{{ it["price"] }}</div>
                    /月
                </div>
            </div>
        </div>
        <div class="type-quantity flexacenter">
            共
            <div class="type-quantity-number">{{ item["roomnum"] }}</div>
            个房型
            <img class="black-arrow" src="@/assets/img/publicImage/black-arrow.svg" />
        </div>
    </div>
</template>

<script setup>
import { ref } from "vue"
import { useRoute, useRouter } from "vue-router"
import { redirectToExternalWebsite } from "@/utils/util.js"
const router = useRouter()

const props = defineProps({
    item: Object,
    pitchValue: Object,
})

const emit = defineEmits(["handlecollect"])

const goapArtmentDetails = () => redirectToExternalWebsite(`/apartmentDetail?uniqid=${props["item"].uniqid}`)

// 点击收藏后传过父组件
const handlecollect = item => {
    console.log("item", item)
    emit("handlecollect", item)
}
</script>

<style lang="less" scoped>
.item {
    width: 386px;
    background-color: rgba(255, 255, 255, 1);
    border-radius: 20px;
    -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.156862745098039);
    -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.156862745098039);
    box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.156862745098039);
    flex-direction: column;
    padding: 10px 10px 0;
    margin-bottom: 20px;
    position: relative;
    height: fit-content;
    cursor: pointer;

    &:hover {
        -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.256862745098039);
        -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.256862745098039);
        box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.256862745098039);
    }

    .collect-box {
        width: 50px;
        height: 50px;
        position: absolute;
        top: 0;
        right: 0;
        // background: #447eb3;
        cursor: pointer;
        .collect-icon {
            width: 40px;
            height: 40px;
        }
    }

    .img {
        width: 366px;
        height: 244px;
        border-radius: 16px;
        margin-bottom: 19px;
        object-fit: cover;
    }

    .title {
        font-weight: 650;
        font-size: 20px;
        color: #000000;
        margin-bottom: 10px;
        padding-left: 6px;
        word-break: break-all;
    }

    .hint {
        color: #aaaaaa;
        font-size: 14px;
        margin: 0 6px 20px;
        word-break: break-all;
    }

    .tab-box {
        flex-wrap: wrap;
        margin-bottom: 14px;
        padding-left: 6px;

        .tab-item {
            // height: 28px;
            line-height: 28px;
            background-color: rgba(224, 240, 255, 1);
            border-radius: 5px;
            font-family: "PingFangSC-Regular", "PingFang SC", sans-serif;
            font-weight: 400;
            font-size: 13px;
            color: #447eb3;
            padding: 0 11px;
            margin-right: 10px;
            margin-bottom: 10px;
            word-break: break-word;
        }
    }

    .location {
        .location-icon {
            width: 18px;
            height: 18px;
            margin-right: 2px;
        }

        font-size: 15px;
        color: #555555;
        margin-bottom: 16px;
        padding-left: 6px;
    }

    .type-list {
        width: 354px;
        // height: 108px;
        background: rgba(246, 246, 246, 1);
        border-radius: 12px;
        padding: 0 10px;
        margin: 0 6px;

        .type-item {
            height: 54px;

            &:not(:last-of-type) {
                border-bottom: 1px solid #ebebeb;
            }

            .type-name {
                color: #000000;
                font-size: 15px;
                padding-right: 15px;
            }

            .type-data {
                font-size: 14px;

                .unit {
                    font-family: "Arial-Black", "Arial Black", sans-serif;
                    font-weight: 900;
                    color: #000000;
                }

                .price {
                    font-family: "Arial-Black", "Arial Black", sans-serif;
                    font-weight: 900;
                    font-size: 20px;
                    color: #f95d5d;
                    margin: 0 5px;
                }

                font-size: 14px;
                color: #555555;
            }
        }
    }

    .type-quantity {
        font-size: 14px;
        color: #555555;
        margin: 24px auto;

        .type-quantity-number {
            font-weight: 650;
            font-size: 14px;
            color: #000000;
            // height: 18px;
            line-height: 18px;
            background-color: rgba(253, 223, 109, 1);
            border-radius: 9px;
            padding: 0 8px;
            margin: 0 8px;
        }

        .black-arrow {
            width: 7px;
            height: 12px;
            margin-left: 8px;
        }
    }
}

.area-distance {
    margin-left: 16px;
    color: #50e3c2;
    position: relative;
    &::after {
        content: "|";
        position: absolute;
        left: -8px;
        color: #d7d7d7;
    }
}
</style>
