optimization.vue 9.48 KB
<template>
    <div class="optimization-box">

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

        <!-- 已关注达人列表(4条) -->
        <div v-if="index < 4" v-for="(item, index) in dresserList" :key="index">
            <dresserList
                :dresserList="item">
            </dresserList>
        </div>

        <!-- 商品部分 -->
        <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>

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

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

            <!-- 商品样式 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>
    </div>
</template>

<script>

    // 引入组件
    import { Toast, Indicator } from "mint-ui";
    import dresserList from "@/components/dresserList/dresserList";
    import horizList from "@/components/horizList/horizList";
    import horizListFlex from "@/components/horizListFlex/horizListFlex";
    import textTitleBox from "@/components/textTitleBox/textTitleBox";

    export default {
        data () {
            return {
                title: "",
                dresserList: null,      // 达人列表
                hotGoods: null,         // 热销商品
                hotGoodsMore: null,     // 热销商品更多
                newGoods: null,         // 最新上架
                newGoodsMore: null,     // 最新上架更多
                newBuyGoods: null,      // 最新购买
                recommendGoods: null    // 猜你喜欢
            }
        },
        components: {
            dresserList,
            horizList,
            horizListFlex,
            textTitleBox
        },
        created() {

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

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

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

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

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

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

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

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

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

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

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

                    // 获取“达人列表数据”
                    if (datas.list && datas.list.length) {

                        // 设置“达人列表数据”数据
                        this.$set(this, "dresserList", datas.list);
                    }

                    // 获取“热销商品”
                    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", 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("获取优选失败");
                }
            },

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

                // 跳转达人列表页面
                this.$router.push({
                    path:"/fansShopMessageList",
                    query:{
                        uid: (this.$route.query.uid || this.getStore("uid"))
                    }
                })
            },

            /**
             * 跳转
             * @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);
                }
            }
        },
        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>