optimization.vue 23.6 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
<template>
    <div class="optimization-box">

        <!-- 下拉刷新 -->
        <!-- <van-pull-refresh v-model="isLoading" pulling-text="下拉刷新..." loosing-text="释放刷新" loading-text="加载中..." success-text="刷新成功" @refresh="onRefresh"> -->

            <!-- 已关注达人 -->
            <div v-if="dresserList&&dresserList.length">

                <!-- 标题 -->
                <text-title-box @more="h5More"
                    :titles="{
                        title: '已关注达人动态',
                        more: true
                    }">
                </text-title-box>

                <!-- 已关注达人列表(4条) -->
                <div>
                    <!-- 达人列表组件 -->
                    <dresserList @toDetail="toDetail"
                        :dresserList="dresserList">
                    </dresserList>
                </div>
            </div>

            <!-- 暂时不修改 开始 -->

            <!-- 已关注达人 -->
            <!-- <div class="follow-daren-box" v-if="dresserList && dresserList.length"> -->

                <!-- tabs横向滚动 -->
                <!-- <horiz-list v-if="dresserList && dresserList.length" @jump="followDarenJump"
                    :lists="dresserList"
                    com="daren-tab"> -->

                    <!-- 标题 -->
                    <!-- <text-title-box slot="title-box" @more="more"
                        :titles="{
                            title: '已关注达人',
                            more: false
                        }">
                    </text-title-box>
                </horiz-list>
            </div> -->

            <!-- 最新动态 -->
            <!-- <daren-list-box class="daren-list" @userJump="userJump" @jump="jump" @goodsJump="goodsJump" @goodsPrimary="goodsPrimary"
                :lists="{}"> -->

                <!--最新达人动态-->
                <!-- <text-title-box slot="title-box"
                    :titles="{
                        title: '最新动态',
                        more: darenListsMore
                    }">
                </text-title-box>
            </daren-list-box> -->

            <!-- 暂时不修改 结束 -->

            <!-- 商品部分 -->
            <div class="goods-list-box">

                <!-- 商品样式 2 横排flex -->
                <horiz-list-flex class="components-box" v-if="hotGoods && hotGoods.length" @jump="jump"
                    :lists="hotGoods"
                    com="2"
                    pid="2"
                    :flags="{
                        icon: [
                            'static/img/icon_n1.png',
                            'static/img/icon_n2.png',
                            'static/img/icon_n3.png'
                        ]
                    }">

                    <!-- 标题 -->
                    <text-title-box slot="title-box" @more="more"
                        :titles="{
                            title: '热销商品',
                            more: hotGoodsMore
                        }">
                    </text-title-box>
                </horiz-list-flex>

                <!-- 商品样式 2 滑动 -->
                <horiz-list class="components-box" v-if="newBuyGoods && newBuyGoods.length" @jump="jump"
                    :lists="newBuyGoods"
                    com="2"
                    pid="1">

                    <!-- 标题 -->
                    <text-title-box slot="title-box"
                        :titles="{
                            title: '最近购买'
                        }">
                    </text-title-box>
                </horiz-list>

                <!-- 商品样式 3 滑动 -->
                <horiz-list class="components-box" v-if="recommendGoods && recommendGoods.length" @jump="jump" @primary="primary"
                    :lists="recommendGoods"
                    com="3">

                    <!-- 标题 -->
                    <text-title-box slot="title-box"
                        :titles="{
                            title: '猜你喜欢'
                        }">
                    </text-title-box>
                </horiz-list>

                <!-- 最新上架组 -->
                <div class="components-box" v-if="(newGoodsTabs && newGoodsTabs.list && newGoodsTabs.list.length) || (newGoods && newGoods.list && newGoods.list.length)">

                    <!-- tabs横向滚动 -->
                    <horiz-list ref="tabsHoriz" v-if="newGoodsTabs && newGoodsTabs.list && newGoodsTabs.list.length" @changeTab="changeTab"
                        :lists="newGoodsTabs.list"
                        com="tab"
                        :pid="true">

                        <!-- 标题 -->
                        <text-title-box slot="title-box" @more="more"
                            :titles="{
                                title: '最新上架',
                                //more: newGoodsMore
                                more: false
                            }">
                        </text-title-box>
                    </horiz-list>


                    <!-- 上拉加载 infinite-scroll-immediate-check="true"可避免上拉多次调用接口问题 -->
                    <div class="column-list-container" :infinite-scroll-immediate-check="true" v-infinite-scroll="loadMore" :infinite-scroll-disabled="paging.loading" :infinite-scroll-distance="paging.distance">

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

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

<script>

    // 引入组件
    import { Toast, Indicator } from "mint-ui";
    import { Tab, Tabs } from 'vant';
    import dresserList from "@/components/dresserList/dresserList";
    import darenListBox from "@/components/darenListBox/darenListBox";
    import horizList from "@/components/horizList/horizList";
    import horizListFlex from "@/components/horizListFlex/horizListFlex";
    import textTitleBox from "@/components/textTitleBox/textTitleBox";
    import columnListBox from "@/components/columnListBox/columnListBox";
    import gotoTop from "@/components/gotoTop/gotoTop";

    export default {
        name: 'optimization',
        data () {
            return {
                title: "",
                isLoading: false,               // 下拉刷新控制
                paging: {                       // 分页、上拉加载
                    activeId: 0,
                    loading: true,
                    page: 0,
                    distance: 50
                },
                CALL_STATUS: {
					INIT: "init",				// 初始化页面
					REFRESH: "refresh",			// 刷新页面
					LOAD_MORE: "loadMore"		// 加载更多
				},
                dresserList: null,              // 达人列表
                darenLists: null,               // 达人动态列表
                darenListsMore: null,           // 达人动态列表更多
                hotGoods: null,                 // 热销商品
                hotGoodsMore: null,             // 热销商品更多
                newGoodsMore: null,             // 最新上架更多
                newBuyGoods: null,              // 最新购买
                recommendGoods: null,           // 猜你喜欢
                newGoodsTabs: null,             // 最新上架tabs对象
                newGoods: null                  // 最新上架
            }
        },
        components: {
            dresserList,
            darenListBox,
            horizList,
            horizListFlex,
            textTitleBox,
            columnListBox,
            gotoTop
        },
        created() {

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

            // 优选页面接口
            this.fansShopMessageList();
        },
        methods: {

            /**
             * 上拉加载
             */
            loadMore() {

                // 判断是否可执行上拉加载
                if (this.paging.activeId && this.paging.page) {

                    // 增加页码
                    this.$set(this.paging, "page", ++this.paging.page);

                    // 商品列表(追加)
                    this.shopGoodsList(this.paging.activeId, this.paging.page, this.CALL_STATUS.LOAD_MORE);
                }
            },

            // 下拉刷新
            // onRefresh() {

            //     // 下拉刷新中
            //     this.$set(this, "isLoading", true);

            //     // 优选页面接口
            //     this.fansShopMessageList();
            // },

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

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

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

                    // 获取证书请求接口
                    this.http("/Api/" + this.getApiVersion().dynamic + "/fansShopMessageList", {
                            uid: this.getStore("uid")
                        }, this.fansShopMessageListCallback, {
                            method: "post"
                        }
                    );
                }
            },

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

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

                // 下拉刷新结束
                this.$set(this, "isLoading", false);

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

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

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

                    // 获取最新上架分类列表
                    if (datas.hotGroup && datas.hotGroup.length) {
                        this.$set(this, "newGoodsTabs", {
                            list: datas.hotGroup
                        });

                        // 调用获取商品列表接口,获取第一个分类的列表
                        if (datas.hotGroup[0]) {

                            // 下一周期执行
                            this.$nextTick(() => {

                                // 切换分类
                                this.changeTab(datas.hotGroup[0]);
                            });
                        }
                    }

                    // 获取“达人列表数据”
                    if (datas.list && datas.list.length) {
                        // 设置“达人列表数据”数据
                        this.$set(this, "dresserList", datas.list.filter((item,index,arr) =>{return index <4}));
                    }

                    // 获取“热销商品”
                    if (datas.hotGoods && datas.hotGoods.length) {

                        // 设置“热销商品”数据
                        this.$set(this, "hotGoods", datas.hotGoods);

                        // 判断“热销商品”更多
                        if (datas.hotGoodsMore) {

                            // 设置“热销商品”更多
                            this.$set(this, "hotGoodsMore", datas.hotGoodsMore);
                        }
                    }

                    // // 获取“最新上架”
                    // if (datas.newGoods && datas.newGoods.length) {

                    //     // 设置“最新上架”数据
                    //     this.$set(this, "newGoods", {
                    //         list: datas.newGoods
                    //     });

                    //     // 判断“最新上架”更多
                    //     if (datas.newGoodsMore) {

                    //         // 设置“最新上架”更多
                    //         this.$set(this, "newGoodsMore", datas.newGoodsMore);
                    //     }
                    // }

                    // 获取“最近购买”
                    if (datas.newBuyGoods && datas.newBuyGoods.length) {

                        // 设置“最近购买”数据
                        this.$set(this, "newBuyGoods", datas.newBuyGoods);
                    }

                    // 获取“猜你喜欢”
                    if (datas.recommendGoods && datas.recommendGoods.length) {

                        // 设置“猜你喜欢”数据
                        this.$set(this, "recommendGoods", datas.recommendGoods);
                    }

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

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

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

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

            /**
             * 商品列表
             * @param {Int} groupId [平台分类id]
             * @param {Int} page [页码]
             * @param {String} CALL_STATUS [何处触发请求]
             */
            shopGoodsList(groupId, page, CALL_STATUS = this.CALL_STATUS.INIT) {

                // 校验必填参数
                if (groupId && page) {

                    // 加载中
                    this.$set(this.paging, "loading", true);

                    // 获取证书请求接口
                    this.http("/Api/" + this.getApiVersion().index + "/shopNewGoodsList", {
                            groupid: groupId,
                            page: page
                        }, this.shopGoodsListCallback, {
                            method: "POST",
                            CALL_STATUS
                        }
                    );
                }
            },

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

                // 下拉刷新结束
                this.$set(this, "isLoading", false);

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

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

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

                    // 判断是否有数据
                    if (datas) {        // datas肯定为数组,但是可能为空,会影响数据更新,所以不判断数组长度

                        // 根据操作,设置列表
                        switch (ext.CALL_STATUS) {
                            case this.CALL_STATUS.INIT:
                            
                                // 设置“最新上架”数据
                                this.$set(this, "newGoods", {
                                    list: datas
                                });
                                break;
                            case this.CALL_STATUS.REFRESH:
                                
                                // 设置“最新上架”数据
                                this.$set(this, "newGoods", {
                                    list: datas
                                });
                                break;
                            case this.CALL_STATUS.LOAD_MORE:
                                
                                // 设置“最新上架”数据(追加)
                                this.$set(this.newGoods, "list", [...this.newGoods.list, ...datas]);
                                break;
                        }



                        console.log('newGoods', this.newGoods);




                        
                        // 设置还有需要加载的内容
                        this.$set(this.paging, "loading", false);
                    } else {

                        // 没有需要加载的内容,停止上拉加载
                        this.$set(this.paging, "loading", true);
                    }

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

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

                    // 获取最新上架列表失败
                    Toast(res.message);
                } else {

                    // 获取最新上架列表失败
                    Toast("获取最新上架列表失败");
                }
            },

            /**
             * 跳转到关注人列表数据
             */
            h5More() {

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

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

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

            /**
             * 用户头像/昵称,点击跳转
             * @param {object} item [数据对象]
             * type等于2属于达人跳转传uid,type=1传id
             */
            userJump(item) {
                
                // 判断并调用通用跳转
                if (typeof this.$parent.gotoDetail === "function") {

                    // 临时,设置跳转达人个人主页用户数据
                    Object.assign(item, {
                        type: "5",
                        to: (this.mode == "prod") ?
                            "https://managemall.cnlive.com/html/preferred-library/1/#/pages/darenProfile/darenProfile?from=redirect" + "&id=" + (item.type==2?item.uid:item.id) + "&uid=" + this.getStore("uid") :
                            "https://wjjshop.cnlive.com/html/preferred-library/1/#/pages/darenProfile/darenProfile?from=redirect"+ "&id=" + (item.type==2?item.uid:item.id) + "&uid=" + this.getStore("uid"),
                        shop_type: ""
                    });

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

            /**
             * 点击跳转商品
             * @param {object} item [数据对象]
             */
            goodsJump(item) {

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

                    // 临时,设置跳转商品详情参数
                    Object.assign(item, {
                        type: "2",
                        to: item.id,
                        shop_type: "1"
                    });

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

            /**
             * 点击跳转商品购买
             * @param {object} item [数据对象]
             */
            goodsPrimary(item) {

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

                    // 临时,设置跳转商品详情参数
                    Object.assign(item, {
                        type: "2",
                        to: item.id,
                        shop_type: "1"
                    });

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

            /**
             * 跳转
             * @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 [数据对象]
			 */
			primary(item) {

                // 调用详情
                this.jump(item);
			},

            /**
             * 更多
             * @param {object} item [数据对象]
             */
            more(item) {

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

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

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

                    // 设置跳转达人个人主页用户数据
                    Object.assign(item, {
                        type: "5",
                        to: (this.mode == "prod") ?
                            "https://managemall.cnlive.com/html/preferred-library/1/#/pages/darenProfile/darenProfile?from=redirect" + "&id=" + (item.user_id) + (this.getStore("uid") ? "&uid=" + this.getStore("uid") : "") :
                            "https://wjjshop.cnlive.com/html/preferred-library/1/#/pages/darenProfile/darenProfile?from=redirect"+ "&id=" + (item.user_id) + (this.getStore("uid") ? "&uid=" + this.getStore("uid") : ""),
                        shop_type: ""
                    });

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

            /**
			 * 切换标签
			 * @param {object} item [对象]
			 */
            changeTab(item) {

                // 判断是否有滚动分类
                if (this.$refs.tabsHoriz) {

                    // 设置children数组
                    let children = this.$refs.tabsHoriz.$children;

                    // 循环处理
                    for (let i = 0; i < children.length; i++) {

                        // 设置当前活动分类id
                        if (children[i].$refs.tabs && typeof children[i].setActiveId === "function") {
                            children[i].setActiveId(item.id);
                        }
                    }
    
                }

                // 设置当前活动分类id
                this.$set(this.paging, "activeId", item.id);

                // 上拉加载控制参数初始化
                this.$set(this.paging, "loading", true);

                // 初始化页码
                this.$set(this.paging, "page", 1);

                // 获取数据
                this.shopGoodsList(item.id, this.paging.page, this.CALL_STATUS.INIT);
            }
        },
        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 "optimization";
</style>