brand-list.vue 2.66 KB
<template>
    <div class="brand-list-box">
        <div v-for="item in brandList" class="per-brand-box">
            <div class="index"><a href="#{{item.index}}" name="{{item.index}}">{{item.index}}</a></div>
            <div class="brand-big-box clearfix">
                <div class="brand-box" v-for="brand in item.brands">
                    <a href="{{brand.link}}">
                        <div class="brand-logo">
                            <img v-lazy="brand.logo | resize 150 150" alt="{{brand.name}}">
                        </div>
                        <span class="brand-name">{{brand.name}}</span>
                    </a>
                </div>
            </div>
        </div>
    </div>
    <index-list v-bind:index-list="indexList"></index-list>
</template>
<style>
    .brand-list-box {
        width: 100%;

        .per-brand-box {
            .index {
                padding: 20px;
            }
        }

        .brand-big-box {
            width: 100%;
        }

        .brand-box {
            width: 24%;
            height: 180px;
            float: left;
            overflow: hidden;
            text-align: center;
            margin: 0 0.5%;

            .brand-logo {
                height: 150px;
                overflow: hidden;

                img {
                    width: 100%;
                }
            }

            .brand-name {
                white-space: nowrap;
                color: #d0d0d0;
            }
        }
    }
</style>
<script>
    const $ = require('yoho-jquery');
    const bus = require('common/vue-bus');
    const tip = require('common/tip');
    const indexList = require('component/tool/index-list.vue');

    module.exports = {
        props: ['channel'],
        data() {
            return {
                brandList: [],
                indexList: []
            };
        },
        watch: {
            channel() {
                this.getBrandList();
            }
        },
        methods: {
            getBrandList() {
                let data = {
                    channel: this.channel
                };

                $.ajax({
                    url: '/get-brand-list',
                    data: data
                }).then(result => {
                    this.brandList = result.brandList;
                    this.indexList = result.indexList;
                }).fail(() => {
                    tip('网络错误');
                });
            }
        },
        components: {
            indexList
        },
        created() {
            this.getBrandList();
            bus.$on('channel.change', (page, channel) => {
                this.channel = channel;
            });
        }
    };
</script>