resource-category.vue 4.28 KB
<template>
    <resource class="resource-category">
        <a-link class="cate-label" :href="brandLink" :yas="value" :yas-f="index">品牌<i class="icon icon-arrow-up trans-right"></i></a-link>
        <div v-for="(item, index) in sort" v-if="item.sub" :key="index">
            <p class="cate-label" @click="toggle(index)">{{item.category_name
                }}<i class="icon" :class="sortClass[index]"></i></p>
            <div class="cate-items" v-if="show[index]">
                <a-link class="cate-item"
                        :href="`/product/list?sort=${getAllSortId(index)}&sort_name=全部${item.category_name}&gender=${genderCvt}`"
                        :yas="value"
                        :yas-f="index">
                    {{`全部${item.category_name}`}}</a-link>
                <a-link
                    :href="`/product/list?sort=${sub.relation_parameter.sort}&sort_name=${sub.category_name}&gender=${genderCvt}`"
                    class="cate-item" 
                    v-for="sub in item.sub" 
                    :key="sub.category_id"
                    :yas="value"
                    :yas-f="index">{{sub.category_name}}
                </a-link>
            </div>
        </div>
    </resource>
</template>

<script>
import Resource from './resource';

export default {
    name: 'ResourceCategory',
    props: {
        value: Object,
        index: Number
    },
    data() {
        return {
            show: [],
            sortClass: []
        };
    },
    computed: {
        brandLink() {
            return `/brand?channel=${this.gender}`;
        },
        genderCvt() {
            return { men: '1,3', women: '2,3' }[this.gender];
        },
        gender() {
            return this.value.data.gender;
        },
        sort() {
            return this.value.data.sort;
        }
    },
    methods: {
        toggle(idx) {
            this.$set(this.show, idx, !this.show[idx]);
            this.$set(this.sortClass, idx, {
                'icon-arrow-up': this.show[idx],
                'icon-arrow-down': !this.show[idx]
            });
        },
        getAllSortId(idx) {
            return this.value.data.sort[idx].sub.map(sort=>sort.relation_parameter.sort).join(',') + ',';
        }
    },
    created() {
        const len = this.sort.length;

        this.show = [];
        for (let i = 0; i < len; i++) {
            this.show.push(false);
            this.sortClass.push({
                'icon-arrow-up': false,
                'icon-arrow-down': true,
            });
        }
    },
    components: {Resource}
};
</script>

<style lang="scss">
.resource-category {
    padding-left: 20px;
    padding-right: 0 !important;
    padding-top: 0 !important;

    .cate-label {
        display: block;
        position: relative;
        height: 88px;
        line-height: 88px;
        color: #030303;
        font-size: 28px;
        font-weight: bold;
        font-family: "HiraginoSansGB-W6";

        .icon {
            position: absolute;
            top: 0;
            right: 24px;
            font-size: 26px;
            line-height: 88px;
            font-weight: bold;
        }

        .icon.trans-right {
            transform: rotate(90deg);
        }

        &:after {
            content: " ";
            position: absolute;
            left: 0;
            bottom: 0;
            right: 0;
            height: 1px;
            border-top: 1px solid #e0e0e0;
            color: #d9d9d9;
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
        }
    }

    .cate-item {
        position: relative;
        color: #030303;
        display: block;
        font-size: 28px;
        padding-left: 30px;
        height: 88px;
        line-height: 88px;
        font-family: "HiraginoSansGB-W3", "PingFang SC", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei";

        &:after {
            content: " ";
            position: absolute;
            left: 0;
            bottom: 0;
            right: 0;
            height: 1px;
            border-top: 1px solid #e0e0e0;
            color: #d9d9d9;
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
            -webkit-transform: scaleY(0.5);
            transform: scaleY(0.5);
        }
    }
}
</style>