optimization2.vue 26 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 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
<template>
    <div class="optimization-box">

        <!-- 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" :style="'padding-top: ' + $parent.top.value + 'px'" ref="backBox" v-if="isCNLive.value && $route.query.showBack == true" @back="back"
            :backs="backs">
        </back-box>

        <!-- pl -->
        <div class="pl" :class="{'is-cnlive': isCNLive.value && $route.query.showBack == true, 'is-open-app': $parent.isOpenApp.value}"></div>

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

            <!-- 折扣专区 -->
            <div class="section shop-list" v-if="discountLists && discountLists.length">

                <!-- 标题 -->
                <text-bg-title-com @more="toDiscountList"
                    :titles="{
                        bg: 'static/img/text_bg_title_bg.png',
                        more: true
                    }">

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

                <!-- 商品列表 -->
                <div class="list-box">

                    <!-- 商品展示样式 2 -->
                    <goods-item-2 class="item" v-for="(item, index) in discountLists" :key="index" @jump="toDiscountList(item)"
                        :item="item"
                        pid="4">

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

            <!-- 锚点区域 -->
            <div class="section anchor-list" v-if="navs && navs.length">

                <!-- 锚点区域(单个图标) -->
                <icons-com v-for="(item, index) in navs" :key="index" @jump="anchor(item)"
                    :item="item">
                </icons-com>
            </div>

            <!-- 品质优选 -->
            <div class="shop-list-box" ref="optimizationBox" v-if="quality && quality.length">

                <div class="section shop-list" v-for="(items, index) in quality" :key="index" @click="toOptimizationList(items)">

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

                    <!-- 商品列表 -->
                    <div class="list-box">

                        <!-- 商品展示样式 2 -->
                        <goods-item-2 class="item" v-for="(item, i) in items.list" :key="i"
                            :item="item"
                            pid="1">
                        </goods-item-2>
                    </div>
                </div>
            </div>

            <!-- 热销排行 -->
            <div class="section hot-box" ref="hotBox">
                
                <!-- 3D轮播 -->
                <swiper-3d-com @onMainSlideClick="toHotSaleList"
                    :items="sales"
                    :options="salesOptions">
                </swiper-3d-com>
            </div>

            <!-- 积分商城 -->
            <!-- <div class="section shop-list" ref="integralMallBox"> -->

                <!-- 标题 -->
                <!-- <text-bg-title-com
                    :titles="{
                        bg: 'static/img/text_bg_title_bg_2.png'
                    }">
                </text-bg-title-com> -->

                <!-- 商品列表 -->
                <!-- <div class="list-box"> -->

                    <!-- 商品展示样式 2 -->
                    <!-- <goods-item-2 class="item" v-for="(item, index) in pointsLists" :key="index" @jump="pointsMore"
                        :item="item"
                        pid="5">
                    </goods-item-2>
                </div> -->

                <!-- 积分展示 -->
                <!-- <more-com class="points-box" @more="pointsMore"
                    :mores="points">
                </more-com>
            </div> -->

            <!-- 猜你喜欢 -->
            <div class="section goods-list" ref="guessLikeBox">

                <!-- 标题 -->
                <text-title-box @more='changeGoods'
                    :titles="{
                        title: '猜你喜欢',
                        more: true,
                        moreText: '换一组',
                        icon: 'static/img/icon_refresh.png'
                    }">
                </text-title-box>

                <!-- 商品样式 7 列表 -->
                <column-list-box class="column-list-box" v-if="likeLists && likeLists.list && likeLists.list.length && likeLists.list[likeNum] && likeLists.list[likeNum].length" @jump="toDetail" @primary="primary"
                    :lists="likeLists.list[likeNum]"
                    com="7">
                </column-list-box>
            </div>

            <!-- 推荐(瀑布流) -->
            <div class="section goods-list">

                <!-- 标题 -->
                <text-title-box
                    :titles="{
                        title: '推荐'
                    }">
                </text-title-box>

                <!-- 上拉加载 -->
                <van-list class="column-list-container" v-model="shopGoodsLists.loading" :finished="shopGoodsLists.finished" finished-text="没有更多了" @load="loadMore">

                    <!-- 商品样式 7 列表 -->
                    <column-list-box class="column-list-box" v-if="shopGoodsLists && shopGoodsLists.list && shopGoodsLists.list.length" @jump="toDetail" @primary="primary"
                        :lists="shopGoodsLists.list"
                        com="7">
                    </column-list-box>
                </van-list>
            </div>
        </div>

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

<script>

    // 引入组件
    import Vue from "vue";
    import { Toast, Indicator } from "mint-ui";
    import { List } from "vant";
    import callAppBox from "@/components/callAppBox/callAppBox";
    import backBox from "@/components/backBox/backBox";
    import textBgTitleCom from "@/components/textBgTitleCom/textBgTitleCom";
    import countDownCom from "@/components/countDownCom/countDownCom";
    import goodsItem2 from "@/components/goodsItem_2/goodsItem_2";
    import iconsCom from "@/components/iconsCom/iconsCom";
    import swiper3dCom from "@/components/swiper3dCom/swiper3dCom";
    import moreCom from "@/components/moreCom/moreCom";
    import textTitleBox from "@/components/textTitleBox/textTitleBox";
    import columnListBox from "@/components/columnListBox/columnListBox";
    import gotoTop from "@/components/gotoTop/gotoTop";

    Vue.use(List);

    export default {
        name: 'optimization',
        data () {
            return {
                title: "",              // 标题
                backs: null,            // 后退按钮组
                navs: null,             // 导航
                discountType: null,     // 折扣专区状态,0:未开始;1:进行中;2:已结束
                discountTimeout: 0,     // 倒计时超时时间计数
                discountTime: null,     // 倒计时时间
                discountLists: null,    // 折扣专区数据
                quality: null,          // 品质优选
                salesOptions: null,     // 热销排行选项
                sales: null,            // 热销排行数据
                points: null,           // 用户积分
                pointsLists: null,      // 积分商城数据
                likeLists: null,        // 猜你喜欢列表
                likeNum: 0,             // 猜你喜欢二维数组当前显示的下标
                shopGoodsLists: {       // 推荐商品瀑布流
                    loading: false,
                    loadingNow: false,
                    finished: false,
                    page: 1,
                    list: []
                }
            }
        },
        computed: {

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

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

                    return ((Math.floor(x * 1000) / 1000) * 10).toString() + '折';
                }
            }
        },
        components: {
            callAppBox,
            backBox,
            textBgTitleCom,
            countDownCom,
            goodsItem2,
            iconsCom,
            swiper3dCom,
            moreCom,
            textTitleBox,
            columnListBox,
            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.index();

            // 商品列表
            // this.shopGoodsList();

            // 设置锚点定位数据
            this.$set(this, 'navs', [
                {
                    ref: 'optimizationBox',
                    simg: 'static/img/icon_nav_optimization.png',
                    title: '品质优选'
                },
                {
                    ref: 'hotBox',
                    simg: 'static/img/icon_nav_hot_sale.png',
                    title: '热销排行'
                },
                // {
                //     ref: 'integralMallBox',
                //     simg: 'static/img/icon_nav_points_mall.png',
                //     title: '积分商城'
                // },
                {
                    ref: 'guessLikeBox',
                    simg: 'static/img/icon_guess_like.png',
                    title: '猜你喜欢'
                }
            ]);

            // 热销排行背景图
            this.$set(this, 'salesOptions', {
                bg: 'static/img/hot_img_bg.png'
            });

            // 用户积分数据设置
            this.$set(this, 'points', {
                key: '我的积分',
                value: '0',
                moreText: '查看更多',
                icon: 'static/img/icon_more_arrow_right.png'
            });
        },
        methods: {

            /**
             * 加载更多
             */
            loadMore() {

                // 判断是否可加载
                if (this.shopGoodsLists.loadingNow === false && this.shopGoodsLists.finished === false) {
                    
                    // 商品列表
                    this.shopGoodsList();
                }
            },

            /**
             * 优选页面接口
             */
            index() {

                // 校验登录
                if (this.$parent.checkLogin()) {

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

                    // 请求接口
                    this.http("/Api/" + this.getApiVersion().good + "/index", {
                        uid: this.getStore("uid") || 0
                    }, this.indexCallback, {
                        method: "POST"
                    });
                }
            },

            /**
             * 优选页面接口回调
             * @param {Object} res [服务器返回数据]
             * @param {Object} ext [扩展参数]
             */
            indexCallback(res, ext) {

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

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

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

                    /* 获取优选库“优选”数据 开始 */

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

                    // 设置折扣专区数据
                    if (datas.discount_time > 0 && datas.discount && datas.discount.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.discount);

                    // 判断品质优选是否有数据
                    if (datas.quality && datas.quality.length) {

                        // 设置品质优选数据
                        this.$set(this, 'quality', [
                            {
                                header_img: 'static/img/box_banner.jpg',
                                list: datas.quality
                            }
                        ]);
                    }

                    // 判断是否有热销商品
                    if (datas.sale && datas.sale.length) {

                        // 热销排行数据
                        this.$set(this, 'sales', datas.sale);
                    }

                    // 设置用户积分
                    this.$set(this.points, 'value', datas.grade);

                    // 判断是否有积分商城
                    if (datas.integral_goods && datas.integral_goods.length) {

                        // 热销排行数据
                        this.$set(this, 'pointsLists', datas.integral_goods);
                    }

                    // 判断是否有猜你喜欢
                    if (datas.recommend_goods && datas.recommend_goods.length) {

                        // 猜你喜欢产品列表
                        this.$set(this, 'likeLists', {
                            list: datas.recommend_goods
                        });
                    }

                    /* 获取优选库“优选”数据 结束 */

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

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

                    // 获取优选失败
                    Toast("获取数据失败");
                }
            },

            /**
             * 商品列表
             */
            shopGoodsList() {

                // 校验登录
                if (this.$parent.checkLogin()) {

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

                    // 设置开始加载
                    this.$set(this.shopGoodsLists, 'loading', true);
                    this.$set(this.shopGoodsLists, 'loadingNow', true);

                    // 请求接口
                    this.http("/Api/" + this.getApiVersion().index + "/shopGoodsList", {
                        page: this.shopGoodsLists.page
                    }, this.shopGoodsListCallback, {
                        method: "POST"
                    });
                }
            },

            /**
             * 商品列表回调
             * @param {Object} res [服务器返回数据]
             * @param {Object} ext [扩展参数]
             */
            shopGoodsListCallback(res, ext) {

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

                // 设置加载结束
                this.$set(this.shopGoodsLists, 'loading', false);
                this.$set(this.shopGoodsLists, 'loadingNow', false);

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

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

                    /* 获取商品列表数据 开始 */

                    // 判断是否有商品
                    if (datas && datas.length) {

                        // 设置列表数据
                        this.$set(this.shopGoodsLists, 'list', [...this.shopGoodsLists.list, ...datas]);

                        // 设置页码
                        this.$set(this.shopGoodsLists, 'page', ++this.shopGoodsLists.page);
                    } else {

                        // 设置全部商品加载完成
                        this.$set(this.shopGoodsLists, 'finished', true);
                    }

                    /* 获取商品列表数据 结束 */

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

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

                    // 获取优选失败
                    Toast("获取数据失败");
                }
            },

            /**
             * 跳转折扣专区列表
             * @param {Object} item [通用跳转对象]
             */
            toDiscountList(item) {

                // 跳转封装
                if (typeof this.$parent.gotoDetail === 'function') {

                    // 设置跳转参数
                    let params = {
                        type: '5',
                        to: window.location.origin + window.location.pathname + '#/discountList',
                        shop_type: ''
                    };

                    // 页面跳转
                    this.$parent.gotoDetail(params);
                }
            },

            /**
             * 锚点定位
             * @param {Object} item [数据对象]
             */
            anchor(item) {

                // 判断锚点是否存在
                if (item.ref && typeof this.$refs === 'object' && typeof this.$refs[item.ref] === 'object') {

                    // 根据头部设置锚点位置
                    let safeDistance = 0;

                    // 判断是否有callApp组件
                    if (typeof this.$refs.callApp === 'object') {
                        safeDistance += this.$refs.callApp.$el.clientHeight;
                    }

                    // 判断是否有backBox组件
                    if (typeof this.$refs.backBox === 'object') {
                        safeDistance += this.$refs.backBox.$el.clientHeight;
                    }

                    document.documentElement.scrollTop = document.body.scrollTop = this.$refs[item.ref].offsetTop - safeDistance - (20 * ((document.documentElement.clientWidth || document.body.clientWidth) / 750));
                }
            },

            /**
             * 跳转品质优选列表
             * @param {Object} item [通用跳转对象]
             */
            toOptimizationList(item) {

                // 跳转封装
                if (typeof this.$parent.gotoDetail === 'function') {

                    // 设置跳转参数
                    let params = {
                        type: '5',
                        to: window.location.origin + window.location.pathname + '#/optimizationList',
                        shop_type: ''
                    };

                    // 页面跳转
                    this.$parent.gotoDetail(params);
                }
            },

            /**
             * 跳转热销排行列表
             * @param {Object} item [通用跳转对象]
             */
            toHotSaleList(item) {

                // 跳转封装
                if (typeof this.$parent.gotoDetail === 'function') {

                    // 设置跳转参数
                    let params = {
                        type: '5',
                        to: window.location.origin + window.location.pathname + '#/hotSaleList',
                        shop_type: ''
                    };

                    // 页面跳转
                    this.$parent.gotoDetail(params);
                }
            },

            /**
             * 查看积分详情
             * @param {Object} item [数据对象]
             */
            pointsDetail(item) {

                // 跳转封装
                if (typeof this.$parent.gotoDetail === 'function') {

                    // 设置跳转参数
                    let params = {
                        type: '5',
                        to: window.location.origin + window.location.pathname + '#/goodDetails?goodsId=' + item.id,
                        shop_type: ''
                    };

                    // 页面跳转
                    this.$parent.gotoDetail(params);
                }
            },

            /**
             * 查看更多积分
             * @param {Object} item [数据对象]
             */
            pointsMore(item) {

                // 跳转封装
                if (typeof this.$parent.gotoDetail === 'function') {

                    // 设置跳转参数
                    let params = {
                        type: '5',
                        to: window.location.origin + window.location.pathname + '#/pointsMall',
                        shop_type: ''
                    };

                    // 页面跳转
                    this.$parent.gotoDetail(params);
                }
            },

            /**
             * 换一租
             * @param {Object} item [数据对象]
             */
            changeGoods(item) {

                // 设置数组下标
                this.$set(this, 'likeNum', ++this.likeNum);

                // 判断如果超出数组下标,设置为0,循环数组
                if (this.likeNum >= this.likeLists.list.length) {

                    // 初始化数组下标
                    this.$set(this, 'likeNum', 0);
                }
            },

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

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

                    // 构建通用跳转数据
                    let params = {
                        type: '2',
                        to: item.id,
                        shop_type: item.shop_type
                    };

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

            /**
             * 列表加号按钮事件
             * @param {Object} item [数据对象]
             */
            primary(item) {

                // 跳转详情页面
                this.toDetail(item);
            },

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

                // 判断分享
                if (typeof this.$parent.toShare === 'function') {
                    this.$parent.toShare(0, 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: 0,
                        id: this.$route.query.id || 1,
                        url: ""
                    });
                }
    
                // 分享详情页
                if (typeof this.$parent.getShareData === "function") {
                    this.$parent.getShareData({
                        type: 0,
                        id: this.$route.query.id || 1,
                        url: ""
                    });
                }
            }

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

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

                    // 优选页面接口
                    this.index();
                }
            });
        }
    }
</script>

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