brand-list.vue 3.41 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.domain | brandUrl}}">
                        <div class="brand-logo">
                            <img v-bind:src="brand.logo | resize 136 136" alt="{{brand.name}}">
                        </div>
                        <span class="brand-name">{{brand.name}}</span>
                    </a>
                </div>
            </div>
        </div>
    </div>
    <index-list class="index-list" :index-list="indexList"></index-list>
</template>
<style>
    .brand-list-box {
        width: 100%;
        padding: 20px 0;
        background: #f6f6f6;
        border-top: 1px solid #eee;

        .per-brand-box {
            background: #fff;
            padding: 0 30px;
            border-top: 1px solid #eee;
            border-bottom: 1px solid #eee;
            
            &:not(:first-of-type) {
                margin-top: 20px;
            }

            .index {
                height: 60px;
                line-height: 60px;

                a {
                    font-size: 32px;
                }
            }
        }

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

        .brand-box {
            width: 172px;
            height: 162px;
            float: left;
            overflow: hidden;
            text-align: center;
            margin-bottom: 20px;

            .brand-logo {
                margin: 0 auto;
                width: 136px;
                height: 136px;
                overflow: hidden;

                img {
                    width: 100%;
                }
            }

            .brand-name {
                width: 136px;
                font-size: 18px;
                color: #d0d0d0;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                display: inline-block;
            }
        }
    }

    .index-list {
        top: 90px !important;
    }
</style>
<script>
    const $ = require('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: '/brand/list.json',
                    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>