hqywList.vue 6.41 KB
<template>
	<div class="hqyw_list">

		<!--返回按钮-->
		<div class="header">
			<div class="header_ztl" :style="'padding-top: ' + ($parent.top.value) + 'px'"></div>
			<div class="header_top">
				<div class="header_back" @click="back">
					<img src="static/img/hqywBack2.png">
				</div>
				<div class="header_close" @click="back">
					<img src="static/img/hqywListClose.png">
				</div>
				<div class="header_title">
					{{title}}
				</div>
				<div class="header_back"></div>
				<div class="header_close" ></div>
			</div>	
		</div>

		<div class="headerBackground">
			<div class="header_ztl" :style="'padding-top: ' + ($parent.top.value) + 'px'"></div>
			<div class="header_top"></div>
		</div>

		<div class="list" v-for="(item, index) in goods" :key="index" @click="toDetail(item)">
			<div class="goods_pic">
				<img class="goods_pic_img" v-lazy="item.simg">
			</div>
			<div class="goods_right">
				<div class="goods_title">{{item.title}}</div>
				<div class="goods_price">
					<p>¥{{integer(item.price)}}</p>
					<span v-if="Number(item.prices) > Number(item.price)">¥{{integer(item.prices)}}</span>
				</div>
			</div>
		</div>

		<div class="list_end">
			—— THE END —— 
		</div>

		<div v-show="showButton" class="go_top_button" @click="goTop">
			<img class="gotop_img" src="static/img/gotopbutton.png" >
		</div>

	</div>
</template>

<script>

	// 引入组件
	import { Toast, Indicator } from "mint-ui";
	
	export default {
		name: 'hqywList',
		data() {
			return{
				title: "",
				goods: [],				// 商品列表
				showButton: false,		//是否显示gotopbutton
				timer: null				// 滚动条监听setTimeout对象
			}
		},
		computed: {

            /**
             * 删除无效小数
             * @param {string} num [文本类型数字]
             */
            integer() {
                return (num) => {
                    return num.replace(/\.00/g,"");
                }
            }
		},
		created() {
			
			// 店铺活动详情
			this.shopMarketInfo();
		},
		methods: {
		
			/**
             * 店铺活动详情
             */
            shopMarketInfo() {

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

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

            /**
             * 店铺活动详情回调
             * @param {object} res [服务器返回数据]
             * @param {object} ext [扩展参数]
             */
            shopMarketInfoCallback(res, ext) {

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

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

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

                    /* 获取店铺活动详情数据 开始 */

					// 设置标题
                    this.$set(this, "title", datas.title);

					// 设置商品列表
                    this.$set(this, "goods", datas.goods);

                    /* 获取店铺活动详情数据 结束 */

                } 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);
                }
            },

			/**
			 * 监听滚动条,判断是否显示回到顶部Button
			 * @param {object} e [滚动条对象]
			 * @param {boolean} isTimeout [是否为setTimeout方法调用]
			 */
			showGoTopButton(e, isTimeout = false) {

				// 获取滚动条位置,浏览器兼容处理
                let scrollTop = (document.documentElement.scrollTop || document.body.scrollTop) || 0;

                // 滚动控制高度
                let maxHeight = 300;

                if (scrollTop >= maxHeight) {
                    this.$set(this, "showButton", true);
                } else {
                    this.$set(this, "showButton", false);
                }
                
                if (!isTimeout) {
                    
                    if (this.timer) {
                        clearTimeout(this.timer);
                    }
                    
                    // 倒计时校正滚动条位置
                    this.timer = setTimeout((options) => {

                        // 递归
                        this.showGoTopButton(options.e, true);
                    }, 1000, {e});
                }
			},

			/**
			 * 回到顶部
			 */
			goTop() {
				document.documentElement.scrollTop = document.body.scrollTop = 0;
			},

			/**
             * 后退
             */
            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");
                }
            }
        },
		mounted() {
			
			// 监听滚动条
			window.addEventListener("scroll", this.showGoTopButton, true);
		},
		beforeDestroy() {

			// 取消滚动条监听
			window.removeEventListener("scroll", this.showGoTopButton, false);
		}
	}
</script>

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