brand-cate.vue 7.57 KB
<template>
    <tab v-bind:page="'cate'"></tab>
    <div class="cate-page" id='cate-page'>
        <div class="cate-container clearfix">
            <div class="content" style="height: 522px;">
                <ul class="primary-level">
                    <li v-for="(index, ca) in cateNavLeftData" v-bind:class="{focus: index === leftcurrent}" class="p-level-item" v-on:click='cateNavLeftFun(index, ca.relationParameter.sort, ca.categoryName)'>
                        {{ca.categoryName}}
                    </li>
                </ul>
                <div class="sub-level-container">
                    <ul class="sub-level">
                        <li><a href="/list?sort={{rightAll.sortId}}&sort_name={{rightAll.categoryName}}&gender={{gender}}">全部{{rightAll.categoryName}}</a></li>
                    </ul>
                    <ul class="sub-level">
                        <li v-for="sub in cateNavRightData">
                            <a href="/list?sort={{sub.relationParameter.sort}}&sort_name={{sub.categoryName}}&gender={{gender}}">{{sub.categoryName}}</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div><!--/end cate-container-->
    </div>
</template>
<style>
.cate-page {
    font-size: 36px;
    font-family: helvetica, Arial, "黑体";

    .cate-container {
        margin-top: 80px;
    }

    ul,
    li {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .search-input {
        position: relative;
        background-color: #f8f8f8;
        padding: 13px 20px;

        p {
            box-sizing: border-box;
            width: 100%;
            height: 60px;
            line-height: 60px;
            border: none;
            padding-left: 66px;
            border-radius: 60px;
            font-size: 26px;
            background: #fff;
            color: #999;
        }
    }

    .search-icon {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 43px;
        line-height: 86px;
        color: #999;
    }

    .cate-nav {
        height: 120px;
        border-bottom: 1px solid #e6e6e6;
        font-size: 24px;

        li {
            display: block;
            box-sizing: border-box;
            float: left;
            height: 100%;
            padding: 20px 0;
            width: 25%;
            text-align: center;
            color: #999;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;

            &:last-child {
                border-right: none;
            }

            &.focus {
                color: #000;

                span {
                    border-bottom: 4px solid #000;
                    font-weight: bold;
                }
            }

            &.bytouch {
                background: #eee;
            }
        }

        span {
            line-height: 80px;
            padding-bottom: 10px;
        }

        li:last-child span {
            border-right: 0;
        }
    }

    .content {
        &.hide {
            display: none;
        }
    }

    .primary-level {
        float: left;
        box-sizing: border-box;
        width: 45%;

        > li {
            height: 120px;
            line-height: 120px;
            padding: 0 32px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            border-bottom: 1px solid #e6e6e6;
            user-select: none;

            &.focus {
                background-color: #fff;

                &:after {
                    content: "";
                    width: 0;
                    height: 0;
                    border-top: 20px solid transparent;
                    border-bottom: 20px solid transparent;
                    border-right: 20px solid #efefef;
                    position: absolute;
                    margin-top: 32px;
                    right: 55%;
                }
            }

            &.highlight {
                background-color: #eee;
            }
        }
    }

    .sub-level-container {
        float: left;
        box-sizing: border-box;
        background: #f6f6f6;
        width: 55%;
        height: 100%;
    }

    .sub-level {
        width: 100%;
        background-color: #f6f6f6;
        position: relative;

        &.hide {
            display: none;
        }

        > li {
            box-sizing: border-box;
            height: 110px;
            line-height: 110px;
            border-bottom: 1px solid #e6e6e6;
            padding-left: 20px;
            user-select: none;

            &.highlight {
                background: #eee;
            }

            &:hover {
                background-color: #efefef;
            }
        }

        a {
            display: block;
            height: 100%;
            width: 100%;
            color: #000;
        }
    }
}
</style>
<script>
    const $ = require('jquery');
    const tip = require('common/tip');
    const tab = require('channel/tab.vue');
    const contentCode = require('content-code');
    const qs = require('yoho-qs');
    const bus = require('common/vue-bus');

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

    module.exports = {
        props: [],
        data() {
            return {
                brandCate: [],
                cateNavLeftData: [],
                cateNavRightData: [],
                topcurrent: 0,
                widthli: 33.33,
                leftcurrent: 0,
                page: 'cate',
                gender: '1,2,3',
                rightAll: {},
                contentCode: contentCode.brand[qs.channel || 'men']
            };
        },
        methods: {
            getCateList() {
                let data = {
                    channel: ''
                };

                $.ajax({
                    url: '/cate/list.json',
                    data: data
                }).then(result => {
                    if (result.code === 200 && result.data) {
                        this.$set('brandCate', result.data);
                        this.$set('cateNavLeftData', result.data['MEN男士']);
                        this.$set('cateNavRightData', result.data['MEN男士'] ? result.data['MEN男士'][0].sub : []);

                        this.$set('rightAll', result.data['MEN男士'] ? {
                            sortId: result.data['MEN男士'][0].relationParameter.sort,
                            categoryName: result.data['MEN男士'][0].categoryName
                        } : {});
                    }
                }).fail(() => {
                    tip('网络错误');
                });
            },
            cateNavLeftFun(index, categoryId, categoryName) {
                this.leftcurrent = index;
                this.cateNavRightData = this.cateNavLeftData[index].sub;
                this.rightAll = {
                    sortId: categoryId,
                    categoryName: categoryName
                };
            }
        },
        components: {
            tab
        },
        created() {
            const self = this;

            this.getCateList();

            bus.$on('channel.change', function(page, channel) {
                self.gender = channelTrans[channel].code;
                self.cateNavLeftData = self.brandCate[channelTrans[channel].key];
                self.cateNavRightData = self.cateNavLeftData ? self.cateNavLeftData[0].sub : [];
            });
        }
    };
</script>