brand-top-bar.vue 2.33 KB
<template>
    <div class="top-box clearfix">
        <span class="icon back" @click="goBack()">&#xe606;</span>
        <div class="right">
            <span class="icon" v-bind:class="{'favorite': shareData.isFav}" @click="collectShop()">&#xe609;</span>
            <span class="icon share" @click="goShare()">&#xe60e;</span>
            <span class="icon filter" @click="showFilter()">&#xe60b;</span>
        </div>
    </div>
</template>

<style>
    .top-box {
        width: 100%;
        height: 60px;
        padding: 0 20px;
        position: fixed;
        top: 60px;
        left: 0;
        z-index: 99;
        color: #fff;
        font-size: 48px;

        .back {
            width: 60px;
            height: 60px;
            float: left;
        }

        .right {
            height: 60px;
            float: right;
            margin: 0;
            padding: 0;

            span {
                width: 60px;
                height: 60px;
                margin: 0 5px;
            }

            .favorite {
                color: #000;
            }
        }
    }
</style>

<script>
    const yoho = require('yoho');
    const $ = require('yoho-jquery');
    const tip = require('common/tip');

    module.exports = {
        props: {
            shareData: {
                type: Object
            }
        },
        methods: {
            goShare() {
                yoho.goShare(this.shareData, function() {}, function() {});
            },
            goBack() {
                yoho.goBack({}, function() {}, function() {});
            },

            /* 收藏或者取消收藏店铺 */
            collectShop() {

                /* TODO 获取数据策略待确定 */
                let data = {
                    shopId: this.shareData.shopId,
                    isFav: this.shareData.isFav
                };

                $.post({
                    url: '/collect-shop',
                    data: data
                }).done(result => {
                    if (result.code === 200) {
                        this.shareData.isFav = this.shareData.isFav !== true;
                    } else {
                        tip('网络错误');
                    }
                }).fail(() => {
                    tip('网络错误');
                });
            },
            showFilter() {

            }
        }
    };
</script>