list.vue 3.01 KB
<template>
    <div class="goods-box" v-infinite-scroll="fetch()" infinite-scroll-disable="disableFetch">
        <ul class="cardlist card-large clearfix">
            <li class="card" v-for="item in data">
                <div class="card-pic">
                    <a href="/product/{{item.productId}}">
                        <img v-lazy="item.goodsList[0].imagesUrl | resize 372 499" alt="{{item.productName}}">
                    </a>
                </div>
                <div class="card-bd">
                    <h2 class="card-label">
                        <a href="/product/{{item.productId}}" class="line-clamp-2">{{item.productName}}</a>
                    </h2>
                    <span class="good-price" :class="{'old-price': item.marketPrice}" v-if="item.marketPrice">¥ {{item.marketPrice}}</span>
                    <span class="good-price" :class="{'sale-price': item.marketPrice}">¥ {{item.salesPrice}}</span>
                </div>
            </li>
        </ul>
        <p class="cardlist--loading text-center" v-show="inLoading">正在加载...</p>
        <p class="cardlist--end text-center" v-show="atEnd ">--End--</p>
    </div>
</template>
<script>
    const Vue = require('yoho-vue');
    const lazyload = require('yoho-vue-lazyload');
    const infinitScroll = require('yoho-vue-infinite-scroll');

    Vue.use(lazyload);
    Vue.use(infinitScroll);

    let bus = require('common/vue-bus');

    module.exports = {
        props: {
            /* 开启滚动加载 */
            disableFetch: Boolean,

            // 数据
            data: Array
        },
        computed: {
            // 空列表: data.length === 0
            whenEmpty() {
                return !this.data.length;
            }
        },
        methods: {
            fetch: function() {
                bus.$emit('list.paging');
            }
        }
    };

</script>
<style>
    @import "../../../scss/common/color";

    .cardlist {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    .card-large {
        .card {
            float: left;
            width: 372px;
            margin-right: 6px;
            &:nth-child(2n) {
                margin-right: 0;
            }
        }
        .card-pic {
            width: 100%;
            height: 499px;
            a,
            img {
                display: block;
                width: 100%;
                height: 100%;
            }
        }
        .card-bd {
            min-height: 180px;
            margin-left: 30px;
            margin-right: 30px;
            padding-top: 25px;
            text-align: center;
            font-size: 24px;
        }
        .card-label {
            margin: 0 0 10px;
            font-size: 24px;
            font-weight: normal;
        }
    }

    .good-price {
        color: #b0b0b0;
        margin-right: 10px;
        &:last-of-type {
            margin-right: 0;
        }
        &.old-price {
            text-decoration: line-through;
        }
        &.sale-price {
            color: $red;
        }
    }

</style>