<!--我的收藏-->
<template>
    <div id="myCollection">
        <Nav :title="$t('myCollection.title')"></Nav>
        <div class="content">
            <div class="rankBox">
                <template v-if="rankList.length">
                    <div class="cell" v-for="item,index in rankList" :key="index">
                        <div class="left" @click="getCommodity(item)">
                            <!-- <div class="tagBox">
                                <span>{{index+1}}</span>
                            </div> -->
                            <img :src="requestUrl+item.faceImg" alt="" srcset="">
                        </div>
                        <div class="right">
                            <div @click="getCommodity(item)">
                                <span>{{item.commodityName}}</span>
                            </div>
                            <div @click="getCommodity(item)">
                                <!-- <span>{{item.commodityName}}</span> -->
                            </div>
                            <div>
                                <div class="center">
                                    <span>{{$t('myCollection.category')}}:{{item.commodityTypeName}}</span>
                                </div>
                                <div class="right">
                                    <van-icon @click="deletes(item.id)" name="delete-o" color="#999999" size="18" />
                                </div>
                            </div>
                        </div>
                    </div>
                </template>
                <template v-else>
                    <van-empty :description="$t('myCollection.none')"></van-empty>
                </template>
            </div>
        </div>
        <van-overlay :show="loading" @click="loading = false">
            <div class="wrapper" @click.stop>
                <div class="block">
                    <van-loading color="#1989fa" size="50" />
                </div>
            </div>
        </van-overlay>
    </div>
</template>

<script>
import Nav from "@/components/pages/nav";
import { collectionOrFootprintList,delCollectionOrFootprint } from "@/api/comp/personal.js";
export default {
    data() {
        return {
            loading: true,
            rankList: [],
            loading: true,
            requestUrl: process.env.VUE_APP_BASE_API,
        };
    },
    mounted() {
        setTimeout(() => {
            this.loading = false;
        }, 1000);
    },
    created() {
        this.getData();
        // let that = this;
        // setTimeout(() => {
        //     for (let i = 0; i < 10; i++) {
        //         that.rankList.push({
        //             img: require("@/../public/static/images/chanpin1.png"),
        //             title: "商品标题商品标题商品标题商品标题商品标题",
        //             text: "显示概要说明显示概要说明显示概要说明显示显示概要说明…",
        //             type: "XXXXXX",
        //             id:i+1
        //         });
        //     }
        //     that.loading = false;
        // }, 1000);
    },
    methods: {
        getData(){
            this.loading = true;
            collectionOrFootprintList({type:2}).then(res=>{
                if(res.code==200){
                    this.rankList=res.data;
                    this.loading = false;
                }
            })
        },
        getCommodity(data) {
            console.log(data, "获得的商品数据");
            let datas=Object.assign({},data);
            datas.id=datas.commodityId;
            this.$store.commit("home/SET_PRODUCT", datas);
            this.$router.push("/productDetails");
        },
        deletes(id) {
            this.$dialog.confirm({
                title: this.$t('myCollection.tips'),
                message: this.$t('myCollection.confirmTips'),
            })
                .then(() => {
                    delCollectionOrFootprint(id).then(res=>{
                        if(res.code==200){
                            this.$toast({ type: "success", message: this.$t('myCollection.successmassage') });
                            this.getData();
                        }
                    })
                })
                .catch(() => {
                    this.$notify({ type: 'warning', message: this.$t('myCollection.massage') });
                });
        },
    },
    components: {
        Nav,
    },
};
</script>

<style lang="scss" scoped>
#myCollection {
    .content {
        padding: 0.12rem /* 12/100 */;
        background: #f9f9f9;
        box-sizing: border-box;
        min-height: calc(100vh - .44rem /* 128/100 */);
        .rankBox {
            padding: 0.05rem /* 5/100 */ 0 /* 15/100 */;
            .cell {
                width: 100%;
                height: 1.39rem /* 139/100 */;
                display: flex;
                padding: 0.12rem /* 12/100 */;
                margin-bottom: 0.15rem /* 15/100 */;
                box-sizing: border-box;
                border-radius: 0.05rem /* 5/100 */;
                color: #333333;
                background-color: #fff;
                box-shadow: 0px 0px 5px #e9e9e9;
                .left {
                    width: 38%;
                    border-radius: 5px;
                    overflow: hidden;
                    position: relative;
                    img {
                        width: 100%;
                        height: 100%;
                    }
                    .tagBox {
                        width: 32px;
                        height: 32px;
                        background: url("../../../../../public/static/images/tagBg.png");
                        position: absolute;
                        left: 0;
                        top: 0;
                        z-index: 1;
                        font-size: 0.14rem /* 16/100 */;
                        text-align: left;
                        span {
                            margin-top: 0.05rem /* 5/100 */;
                            margin-left: 0.05rem /* 5/100 */;
                            display: inline-block;
                            color: #fff;
                        }
                    }
                }
                .right {
                    padding-top: 0.03rem /* 3/100 */;
                    width: 72%;
                    font-size: 0.15rem /* 15/100 */;
                    text-align: left;
                    > div:nth-child(1) {
                        width: 100%;
                        height: 40%;
                        display: flex;
                        align-items: center;
                        padding: 0 0 0 0.12rem;
                        font-weight: bold;
                        box-sizing: border-box;
                        display: -webkit-box;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        -webkit-line-clamp: 2;
                        -webkit-box-orient: vertical;
                    }
                    > div:nth-child(2) {
                        width: 100%;
                        height: 35%;
                        text-align: left;
                        padding: 0 0 0 0.12rem;
                        box-sizing: border-box;
                        display: -webkit-box;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        -webkit-line-clamp: 2;
                        -webkit-box-orient: vertical;
                    }
                    > div:nth-child(3) {
                        width: 100%;
                        height: 25%;
                        text-align: left;
                        padding: 0 0 0 0.12rem;
                        color: #999999;
                        box-sizing: border-box;
                        overflow: hidden;
                        display: flex;
                        > div:nth-child(1) {
                            width: 80%;
                            display: flex;
                            justify-content: flex-start;
                            align-items: flex-end;
                            font-size:0.12rem;
                        }
                        > div:nth-child(2) {
                            width: 20%;
                            text-align: right;
                            display: flex;
                            justify-content: flex-end;
                            align-items: flex-end;
                        }
                    }
                }
            }
        }
    }
}
</style>