brand-cate-box.vue 1.98 KB
<template>
    <div>
        <brand-cate :category="category" :jump="true" :gender="gender"></brand-cate>
    </div>
</template>
<script>
    import tip from 'common/tip';
    import brandCate from 'channel/brand-cate.vue';
    import tab from 'channel/tab.vue';
    import $ from 'jquery';
    import bus from 'common/vue-bus';
    import qs from 'yoho-qs';
    import cookie from 'yoho-cookie';

    const channelTrans = {
        men: {
            key: 'MEN男士',
            code: '1,3'
        },
        women: {
            key: 'WOMEN女士',
            code: '2,3'
        },
        lifestyle: {
            key: 'LIFESTYLE生活',
            code: '1,2,3'
        }
    };

    export default {
        data() {
            const detaultChannel = qs.channel || cookie.get('_Channel') || 'men';

            return {
                category: [],
                categoryResult: {},
                detaultChannel: detaultChannel,
                gender: channelTrans[detaultChannel].code,
            };
        },
        components: {
            tab,
            brandCate
        },
        methods: {
            getCateList() {
                $.ajax({
                    url: '/cate/list.json'
                }).then(result => {
                    if (result.code === 200 && result.data) {
                        this.categoryResult = result.data;
                        this.category = this.categoryResult[channelTrans[this.detaultChannel].key];
                    }
                }).fail(() => {
                    tip('网络错误');
                });
            }
        },
        created() {
            this.getCateList();

            bus.$on('channel.change', (page, channel) => {
                this.detaultChannel = channel || qs.channel || cookie.get('_Channel') || 'men';
                this.gender = channelTrans[this.detaultChannel].code;
                this.category = this.categoryResult[channelTrans[this.detaultChannel].key];
            });
        }
    };
</script>