mall.vue 6.17 KB
<template>
    <div class="mall-box">
        
        <!--轮播-->
        <swiper v-if="banner"
            :swipers="banner">
        </swiper>
        
        <!--导航-->
        <swiperItem v-if="navs"
            :navs="navs">
        </swiperItem>
        
        <!-- 遍历ads,输出列表数据 -->
        <div class="ads-box">
            <div class="ads" v-for="(item, index) in ads" :key="index">
                
                <!--优惠专区-->
                <discountZone v-if="item.style == '1'" @more="toDetail" @toDetail="toDetail"
                    :discountZoneInfo="item">
                </discountZone>
                
                <!--天天特惠-->
                <preferential v-if="item.style == '2'" @more="toDetail" @toDetail="toDetail"
                    :preferentialInfo="item">
                </preferential>
                
                <!--视听专区-->
                <videoArea v-if="item.style == '13'" @more="toDetail" @toDetail="toDetail"
                    :videoAreaInfo="item">
                </videoArea>

                <!-- style_7组件 -->
                <style-7 v-if="item.style == '7'" @more="toDetail" @bannerJump="toDetail" @jump=jump @addCart=addCart
                    :styles="item">
                </style-7>
            </div>
        </div>
    </div>
</template>

<script>
    // 引入组件
    import { Toast, Indicator } from "mint-ui";
    import swiper from "@/components/swiper/swiper";
    import swiperItem from "@/components/swiperItem/swiperItem";
    import discountZone from "@/components/discountZone/discountZone";
    import preferential from "@/components/preferential/preferential";
    import videoArea from "@/components/videoArea/videoArea";
    import style7 from "@/components/style_7/style_7";
    
    export default {
        name: 'mall',
        data() {
            return {
                title: "",      // 标题
                banner:null,    // banner
                navs: null,     // 导航
                ads: null       // 列表
            }
        },
        components:{
            swiper,
            swiperItem,
            discountZone,
            preferential,
            videoArea,
            style7
        },
        created() {

            // 设置标题
            this.$set(this, "title", "优选库商城");

            // 获取优选库精选活动
            this.activityAd();
        },
        methods: {

            /**
             * 获取优选库精选活动
             */
            activityAd() {
                // 加载中提示
                Indicator.open("加载中...");

                // 获取证书请求接口
                this.http("/Api/" + this.getApiVersion().index + "/activityAd", {
                        id: this.$route.query.id
                    }, this.activityAdCallback, {
                        method: "post"
                    }
                );
            },

            /**
             * 获取优选库精选活动回调
             * @param {object} res [服务器返回数据]
             * @param {object} ext [扩展参数]
             */
            activityAdCallback(res, ext) {

                // 加载完成
                Indicator.close();
                
                // 返回处理
                if (res.code == 200) {

                    // 解构数据
                    let { data: datas } = res;

                    /* 获取优选库精选活动数据 开始 */
                    
                    // 设置banner数据
                    if (datas.banner && datas.banner.length) {
                        this.$set(this, "banner", datas.banner);
                    }

                    // 设置navs数据
                    if (datas.navs && datas.navs.length) {
                        this.$set(this, "navs", datas.navs);
                    }

                    // 设置ads数据
                    if (datas.ads && datas.ads.length) {
                        this.$set(this, "ads", datas.ads);
                    }
                } else if (res.code == 400) {

                    // 获取优选库精选活动失败
                    Toast(res.message);
                } else {

                    // 获取优选库精选活动失败
                    Toast("获取优选库精选活动失败");
                }
            },

            /**
             * 调用通用跳转
             * @param {object} item [通用跳转对象]
             */
            toDetail(item) {

                // 判断是否有通用跳转函数
                if (typeof this.$parent.gotoDetail === "function") {

                    // 调用通用跳转
                    this.$parent.gotoDetail(item);
                }
            },

            /**
             * style7跳转
             * @param {object} item [数据对象]
             */
            jump(item) {

                // 判断并调用通用跳转
                if (typeof this.$parent.gotoDetail === "function") {

                    // 构造跳转详情页参数
                    let options = {
                        type: "2",
                        to: item.id,
                        shop_type: item.shop_type
                    }

                    this.$parent.gotoDetail(options);
                }
            },

            /**
             * 加入购物车
             * @param {object} item [数据对象]
             */
            addCart(item) {
                

                console.log("addCartA", item);


            }
        },
        head: {
            title () {
                return {
                    inner: this.title
                }
            }
        },
        watch: {

            // 设置页面标题
            title(newVal) {
                if (this.$store.state.browser.toLowerCase() == "qq" && this.$store.state.deviceType.toLowerCase() == "iphone") {
                    this.$iFrame.insertIFrame(newVal);
                } else {
                    this.$emit("updateHead");
                }
            }
        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/less" lang="less" scoped>
    @import "mall";
</style>