hqyw.vue 9.54 KB
<template>
	<div class="hqyw-box">

		<!--返回按钮-->
		<div class="header" v-if="$parent.isBackBox.value">
			<div class="header_ztl"></div>
			<div class="header_top">
				<div class="header_back" @click="back">
					<img src="static/img/hqywBack1.png">
				</div>
				<div class="header_close" @click="back">
					<img src="static/img/hqywClose.png">
				</div>
				<div class="header_search">
					
				</div>
			</div>	
		</div>
        
		<div class="headerBackground" v-if="$parent.isBackBox.value">
			<div class="header_ztl"></div>
			<div class="header_top"></div>
		</div>
        
		<div class="hqyw">
			<div class="hqyw_swiper">
				
                <!-- 轮播 -->
                <swiper v-if="swipers" @onChange="swiperChange"
                    :swipers="swipers"
                    :options="{
                        showIndicators: false
                    }">
                </swiper>

                <!-- 轮播提示符按钮 -->
				<div class="swiper_pagination">
					<li v-for="(item, index) in swipers" :key="index" :class="{'swiper_page_active': swiperIndex == index}"></li>
				</div>
			</div>

			<div v-if="ads" @click="toAdsDetail(ads)">
				<div class="hqyw_qyzz">
					<img class="hqyw_qyzz_img" :src="ads.simg">
				</div>
			</div>

			<div v-for="(item, index) in shopMarkets" :key="index">
				<div class="card1" v-if="item.style == '1'">
					<div class="top_pic">
						<a @click="more(item)">
							<img class="top_pic_img" v-lazy="item.simg">
						</a>
					</div>
					<div class="list">
						<div class="scoll_div">
							<ul class="scoll_ul">
								<li class="scoll_li" v-for="(value, index) in item.goods" :key="index" @click="toDetail(value)">
									<div class="li_pic">
										<img class="li_pic_img" v-lazy="value.simg">
									</div>
									<div class="li_name">{{value.title}}</div>
									<div class="li_price">
										<p>¥{{integer(value.price)}}</p>
										<span v-if="Number(value.prices) > Number(value.price)">¥{{integer(value.prices)}}</span>
									</div>
								</li>
							</ul>
						</div>
					</div>
				</div>

				<div class="card2" v-if="item.style == '2'">
					<div class="card_title">
						<div class="title_left">{{item.title}}</div>
						<a @click="more(item)" class="title_right">
							<div>
								MORE
								<img class="title_right_img" src="static/img/gd.png">
							</div>
						</a>
					</div>
					<div class="goods_list">
						<div class="goods_single" v-for="(value, index) in item.goods" :key="index" @click="toDetail(value)">
							<div class="goods_pic">
								<img class="goods_pic_img" v-lazy="value.simg">
							</div>
							<div class="goods_name">{{value.title}}</div>
							<div class="goods_price">
								<p>¥{{integer(value.price)}}</p>
								<span v-if="Number(value.prices) > Number(value.price)">¥{{integer(value.prices)}}</span>
							</div>
						</div>
					</div>
				</div>

				<div class="card2" v-if="item.style == '3'">
					<div class="card_title">
						<div class="title_left">{{item.title}}</div>
						<a @click="more(item)" class="title_right">
							<div >
								MORE
								<img class="title_right_img" src="static/img/gd.png">
							</div>
						</a>
					</div>
					<div class="list" v-for="(value, index) in item.goods" :key="index" @click="toDetail(value)">
						<div class="goods_pic">
							<img class="goods_pic_img" v-lazy="value.simg">
						</div>
						<div class="goods_right">
							<div class="goods_title">{{value.title}}</div>
							<div class="goods_price">
								<p>¥{{integer(value.price)}}</p>
								<span v-if="Number(value.prices) > Number(value.price)">¥{{integer(value.prices)}}</span>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>

    // 引入组件
    import { Toast, Indicator } from "mint-ui";
    import swiper from "@/components/swiper/swiper";

    export default {
        name: 'hqyw',
        data() {
            return {
                title: "",
                list:[],
                swipers: null,              // banner数据
                swiperIndex: 0,             // 轮播索引
                ads: null,                  // 广告位
                shopMarkets: null,          // 商城数组



            }
        },
        components: {
            swiper
        },
        computed: {

            /**
             * 删除无效小数
             * @param {string} num [文本类型数字]
             */
            integer() {
                return (num) => {
                    return num.replace(/\.00/g,"");
                }
            }
        },
        created() {

            // 设置标题
            this.$set(this, "title", "环球优物");
            
            // 获取环球优物首页
            this.shopIndexHq();
        },
	    methods:{

            /**
             * 获取环球优物首页
             */
            shopIndexHq() {

                // 加载中提示
                Indicator.open("加载中...");

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

            /**
             * 获取环球优物首页回调
             * @param {object} res [服务器返回数据]
             * @param {object} ext [扩展参数]
             */
            shopIndexHqCallback(res, ext) {

                // 加载完成
                Indicator.close();

                // 返回处理
                if (res.code == 200) {

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

                    /* 获取环球优物首页数据 开始 */

                    this.$set(this, "list", datas);

                    // 设置轮播
                    this.$set(this, "swipers", datas.banner);

                    // 设置广告位
                    this.$set(this, "ads", datas.ads);
                    
                    // 设置商城列表
                    this.$set(this, "shopMarkets", datas.shopMarket);

                    /* 获取环球优物首页数据 结束 */

                } else if (res.code == 400) {

                    // 获取环球优物首页失败
                    Toast(res.message);
                } else {

                    // 获取环球优物首页失败
                    Toast("获取环球优物首页失败");
                }
            },

            /**
             * ads广告调用通用跳转,补充shop_type参数再调用通用跳转
             * @param {object} item [通用跳转对象]
             */
            toAdsDetail(item) {

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

                    // 判断是否有shop_type属性,如果没有,补上shop_type属性
                    if (item.shop_type === undefined) {
                        this.$set(item, "shop_type", "");
                    }

                    // 调用通用跳转
                    this.$parent.gotoDetail(item);
                }
            },
            
            /**
             * 调用通用跳转
             * @param {object} item [通用跳转对象]
             */
            toDetail(item) {

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

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

            /**
             * 更多
             * @param {object} item [跳转更多参数]
             */
            more(item) {

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

                    // 设置跳转参数
                    let options = {
                        type: "5",
                        to: (window.location.href.split("#")[0] + "#/hqywList?shop_id=" + item.id),
                        shop_type: ""
                    }

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

            /**
             * swiperChange事件
             * @param {object} index [滑动swiper索引]
             */
            swiperChange(index) {

                // 设置下方swiper提示器切换
                this.$set(this, "swiperIndex", index);
            },

            /**
             * 后退
             */
            back() {

                // 判断是否有后退函数
                if (typeof this.$parent.back === "function") {

                    // 调用后退
                    this.$parent.back();
                } else {

                    // 后退
                    window.history.go(-1);
                }
            }
        },
        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 "hqyw";
</style>