discountList.vue 13.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
<template>
    <div class="discount-list-page" :style="{'backgroundColor': discountColor}">

        <!-- H5唤起App组件 -->
        <call-app-box class="call-app-box" ref="callApp" v-if="!isCNLive.value && $parent.isOpenApp.value"
            :callApps="$parent.callApps">
        </call-app-box>

        <!-- 后退导航 -->
        <back-box class="back-box" :class="{'hide': $route.query.hideBack == true}" :style="'padding-top: ' + $parent.top.value + 'px'" v-if="isCNLive.value" @back="back"
            :backs="backs">
        </back-box>

        <!-- pl -->
        <div class="pl" :class="{'is-cnlive': isCNLive.value, 'is-open-app': $parent.isOpenApp.value, 'hide': $route.query.hideBack == true}" :style="'padding-top: ' + $parent.top.value + 'px'"></div>

        <!-- 主区域 -->
        <div class="main-box">

            <!-- 头图 -->
            <div class="header-box" v-if="discountImg">
                <img :src="discountImg + SIGN.BIG" class="header-img" />
            </div>

            <!-- 倒计时 -->
            <div class="count-down-box">
                <div class="state" v-if="discountType == '0'">
                    <div class="text">距离活动开始仅剩</div>
                </div>
                <div class="state" v-if="discountType == '1'">
                    <div class="text">距离活动结束仅剩</div>
                </div>
                <div class="state" v-if="discountType === '2'">
                    <img src="/static/img/icon_tips_book.png" class="icon-tips-img" />
                    <div class="text">本次活动已结束,敬请期待下次折扣活动~</div>
                </div>

                <!-- 倒计时组件 -->
                <count-down-com slot="extend" v-if="discountTime && discountTime > 0 && (discountType == '0' || discountType == '1')"
                    :time="parseInt(discountTime) * 1000"
                    sty="5">
                </count-down-com>
            </div>

            <!-- 商品列表 -->
            <div class="section goods-list" v-if="discountLists && discountLists.length">

                <!-- 商品列表 -->
                <goods-item-8 v-for="(item, index) in discountLists" :key="index" @jump="toDetail" @primary="primary"
                    :item="item"
                    sty="1">

                    <!-- 折扣角标 -->
                    <div class="discount-flag" slot="flag" v-if="parseFloat(item.price) < parseFloat(item.prices)">
                        {{getDiscount(item.price, item.prices)}}折
                    </div>
                </goods-item-8>
            </div>
            
            <div class="bottom-pl"></div>

            <!-- 活动规则提示 -->
            <!-- <div class="tips-box">
                <div class="tips">
                    <img src="static/img/icon_tips.png" class="tips-img" />
                    <div class="text">本次活动每个商品每个用户限购一件</div>
                </div>
            </div> -->
        </div>

        <!-- 回到顶部按钮 -->
        <goto-top
            :top="parseInt(150)">
        </goto-top>
    </div>
</template>

<script>

    // 引入组件
    import { Toast, Indicator } from "mint-ui";
    import callAppBox from "@/components/callAppBox/callAppBox";
    import backBox from "@/components/backBox/backBox";
    import countDownCom from "@/components/countDownCom/countDownCom";
    import goodsItem8 from "@/components/goodsItem_8/goodsItem_8";
    import gotoTop from "@/components/gotoTop/gotoTop";

    export default {
        name: 'discountListPage',
        data () {
            return {
                title: "",              // 标题
                backs: null,            // 后退按钮组
                discountColor: null,    // 背景颜色
                discountImg: null,      // 头图
                discountType: null,     // 折扣专区状态,0:未开始;1:进行中;2:已结束
                discountTimeout: 0,     // 倒计时超时时间计数
                discountTime: null,     // 倒计时时间
                discountLists: null     // 折扣专区数据
            }
        },
        computed: {

            /**
             * 计算折扣
             */
            getDiscount() {
                return (price, prices) => {

                    // 售价/原价
                    let x = (price * 100) / (prices * 100);

                    return (Math.floor(x * 1000) / 1000) * 10;
                }
            }
        },
        components: {
            callAppBox,
            backBox,
            countDownCom,
            goodsItem8,
            gotoTop
        },
        created() {

            // 设置标题
            this.$set(this, "title", "折扣专区");

            // 判断是否在App内
            if (this.isCNLive.value) {

                // 添加后退按钮组“后退”和“分享”按钮
                this.$set(this, 'backs', {
                    title: this.title,
                    funcs: {
                        back: {
                            icon: "static/img/icon_back.png"
                        },
                        funcArray: [
                            {
                                icon: "static/img/icon_share.png",
                                func: this.toShare
                            }
                        ]
                    }
                });
            }

            // 折扣专区列表
            this.discountGoods();
        },
        methods: {

            /**
             * 折扣专区列表
             */
            discountGoods() {

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

                // 获取证书请求接口
                this.http("/Api/" + this.getApiVersion().good + "/discountGoods", {
                    uid: this.getStore("uid") || 0
                }, this.discountGoodsCallback, {
                    method: "POST"
                });
            },

            /**
             * 折扣专区列表回调
             * @param {Object} res [服务器返回数据]
             * @param {Object} ext [扩展参数]
             */
            discountGoodsCallback(res, ext) {

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

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

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

                    /* 获取折扣专区列表数据 开始 */

                    // 设置折扣商品状态
                    this.$set(this, 'discountType', datas.discount_type);

                    // 设置背景色
                    this.$set(this, 'discountColor', datas.discount_color);
                    
                    // 头图
                    this.$set(this, 'discountImg', datas.discount_img);

                    // 设置折扣专区数据
                    if (datas.discount_time > 0 && datas.list && datas.list.length) {

                        // 设置倒计时时间
                        this.$set(this, 'discountTime', parseInt(datas.discount_time) + 10);

                        // 设置倒计时超时轮训
                        let timeoutInterval = setInterval(() => {

                            // 倒计时超时时间计数
                            this.discountTimeout++;

                            // 判断是否超时
                            if (this.discountTimeout >= this.discountTime) {

                                // 停止倒计时
                                clearInterval(timeoutInterval);

                                // 刷新页面
                                window.location.reload();
                            }
                        }, 1000);
                    }

                    // 设置折扣专区列表数据
                    this.$set(this, 'discountLists', datas.list);
                    
                    /* 获取折扣专区列表数据 结束 */

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

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

                    // 获取优选失败
                    Toast("获取列表失败");
                }
            },

            /**
             * 跳转商品详情
             * @param {Object} item [数据对象]
             */
            toDetail(item) {

                // 判断App内
                if (this.isCNLive.value) {

                    // 判断是活动未开始状态,弹窗提示活动未开始
                    if (this.discountType == '0') {
                        
                        // 通用弹窗提示
                        this.showModal();
                        return false;
                    }

                    // 已抢光,不跳转
                    if (item.num == '2' || (item.num == '1' && item.stock == '0')) {
                        return false;
                    }

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

                        // 跳转参数
                        let params = {
                            type: '2',
                            to: item.id,
                            shop_type: item.shop_type
                        };

                        // 通用跳转
                        this.$parent.gotoDetail(params);
                    }
                } else {

                    // App外,唤起App
                    this.openApp();
                }
            },

            /**
             * 项目按钮事件
             * @param {Object} item [数据对象]
             */
            primary(item) {

                // 跳转商品详情
                this.toDetail(item);
            },

            showModal() {

                // 判断通用弹窗是否存在
                if (typeof this.$parent.showModal === 'function') {

                    // 设置通用弹窗参数
                    let options = {
                        title: "提示",
                        message: "当前活动未开始,请耐心等待",
                        confirmButtonText: "我知道了",
                        closeOnClickModal: true
                    };

                    // 调用函数,显示通用弹窗
                    this.$parent.showModal(options);
                }
            },

            /**
             * 唤起App封装
             */
            openApp() {

                this.$nextTick(() => {

                    // 唤起App
                    if (typeof this.$parent.callAppModal === 'function' && typeof this.$refs.callApp === 'object') {

                        // 设置唤起参数
                        let options = {
                            success: this.$refs.callApp.callApp
                        }

                        // 唤起App
                        this.$parent.callAppModal(options);
                    }
                });
            },

            /**
             * 分享
             */
            toShare() {

                // 判断分享
                if (typeof this.$parent.toShare === 'function') {
                    this.$parent.toShare(49, this.$route.query.id || 1);
                }
            },

            /**
             * 后退
             */
            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() {
            
            // 如果是App外,设置唤起App和微信内分享参数
            if (!this.isCNLive.value) {

                // 唤起详情页
                if (typeof this.$parent.getOpenApp === "function") {
                    this.$parent.getOpenApp({
                        type: 49,
                        id: this.$route.query.id || 1,
                        url: ""
                    });
                }
    
                // 分享详情页
                if (typeof this.$parent.getShareData === "function") {
                    this.$parent.getShareData({
                        type: 49,
                        id: this.$route.query.id || 1,
                        url: ""
                    });
                }
            }

            // 页面切换可见状态监听
            document.addEventListener('visibilitychange', () => {

                // 页面显示出来了
                if (document.hidden === false && this.$route.name == 'discountList') {

                    // 折扣专区列表
                    this.discountGoods();
                }
            });
        }
    }
</script>

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