myGiftBox.vue 7.25 KB
<template>
    <div class="my_gift_box">
        <!--tab切换-->
        <div class="top_box" :style="'padding-top: ' + ($parent.top.value) + 'px'">
            <img src="static/img/icon_back.png" />
            <div class="tabs">
                <van-tabs @change="onTap" v-model="active">
                    <van-tab title="收礼"></van-tab>
                    <van-tab title="送礼"></van-tab>
                </van-tabs>
            </div>
            <div class="desc">规则说明</div>
        </div>
        <!--内容-->
        <div
            infinite-scroll-immediate-check="true"
            v-infinite-scroll="getorderGiftList"
            infinite-scroll-disabled="loading"
            :infinite-scroll-distance="50"
        >
            <!-- 送礼列表 -->
            <receiving-gifts-item
                v-show="active != 1 && active == 0"
                @giftInReturn="giftInReturn"
                :receivingGiftsInfo="receivingGiftsInfo"
            ></receiving-gifts-item>
            <!-- 收礼列表 -->
            <giftGivingItem
                v-show="active != 0 && active == 1"
                :giftGivingItem="giftGivingItem"
            >
            </giftGivingItem>
        </div>
    </div>
</template>

<script>
// 引入组件
import { Toast, Indicator } from "mint-ui";
import receivingGiftsItem from "@/components/receivingGiftsItem/receivingGiftsItem"; // 收礼列表
import giftGivingItem from "@/components/giftGivingItem/giftGivingItem"; // 送礼列表
export default {
    name: "myGiftBox",
    data() {
        return {
            active: 0,
            receivingGiftsInfo: null, // 收礼列表页数据
            receivingGifts: {
                loading: false, // 加载
                pages: 0 // 分页
            },
            giftGivingItem: null, // 送礼列表页数据
            giftGiving: {
                loading: false, // 加载
                pages: 0 // 分页
            }
        };
    },
    components: {
        receivingGiftsItem,
        giftGivingItem
    },
    created() {
        // 收礼订单列表
        this.getorderGiftList();
        // 送礼订单列表
        this.getorderGiveGiftList();
    },
    methods: {
        onTap(active) {
            this.active = active;
        },
        /**
         * 获取收礼礼物列表
         */
        getorderGiftList() {
            this.receivingGifts.loading = true;
            this.receivingGifts.pages++;
            // 加载中提示
            Indicator.open("加载中...");

            // 获取收礼礼物列表接口
            this.http(
                "/Api/" + this.getApiVersion().index + "/orderGiftList",
                {
                    uid: this.$route.query.uid, // 用户id
                    page: this.receivingGifts.pages, // 分页 默认为1 一页20条
                    type: 1, // 1 收礼列表 2 送礼列表(送礼已废弃)
                    status: 0 // 0或者不传 全部 1 未填地址 2 未发货 3 已完成 4 已发货
                },
                this.getorderGiftListCallback,
                {
                    method: "post"
                }
            );
        },

        /**
         * 获取收礼礼物列表回调
         * @param {object} res [服务器返回数据]
         * @param {object} ext [扩展参数]
         */
        getorderGiftListCallback(res, ext) {
            // 加载完成
            Indicator.close();

            // 返回处理
            if (res.code == 200) {
                // 解构数据
                let { data: datas } = res;
                // 设置shopFnsDynamic达人动态数据

                if (datas.list && datas.list.length) {
                    // 隐藏加载圈
                    this.receivingGifts.loading = false;
                    if (this.pages > 1) {
                        this.$set(this, "receivingGiftsInfo", [
                            ...this.receivingGiftsInfo,
                            ...datas.list
                        ]);
                    } else {
                        this.$set(this, "receivingGiftsInfo", datas.list);
                    }
                }
                /* 获取达人动态数据 结束 */
            } else if (res.code == 400) {
                // 获取达人动态失败
                Toast(res.message);
            } else {
                // 获取优选库精选活动失败
                Toast("获取收礼订单列表失败");
            }
        },
        // 跳转回赠礼物
        giftInReturn(item) {
            // 判断并调用通用跳转
            if (typeof this.$parent.gotoDetail === "function") {
                // 临时,设置跳转商品详情参数
                Object.assign(item, {
                    type: "14",
                    to: "",
                    shop_type: ""
                });

                this.$parent.gotoDetail(item);
            }
        },
        /**
         * 获取送礼礼物列表
         */
        getorderGiveGiftList() {
            this.giftGiving.loading = true;
            this.giftGiving.pages++;
            // 加载中提示
            Indicator.open("加载中...");

            // 获取送礼礼物列表接口
            this.http(
                "/Api/" + this.getApiVersion().index + "/orderGiveGiftList",
                {
                    uid: this.$route.query.uid, // 用户id
                    page: this.giftGiving.pages, // 分页 默认为1 一页20条
                    type: 1, // 1 收礼列表 2 送礼列表(送礼已废弃)
                    status: 0 // 0或者不传 全部 1 未填地址 2 未发货 3 已完成 4 已发货
                },
                this.getorderGiveGiftListCallback,
                {
                    method: "post"
                }
            );
        },

        /**
         * 获取送礼礼物列表回调
         * @param {object} res [服务器返回数据]
         * @param {object} ext [扩展参数]
         */
        getorderGiveGiftListCallback(res, ext) {
            // 加载完成
            Indicator.close();

            // 返回处理
            if (res.code == 200) {
                // 解构数据
                let { data: datas } = res;
                // 设置giftGivingItem数据

                if (datas.list && datas.list.length) {
                    // 隐藏加载圈
                    this.giftGiving.loading = false;
                    if (this.pages > 1) {
                        this.$set(this, "giftGivingItem", [
                            ...this.giftGivingItem,
                            ...datas.list
                        ]);
                    } else {
                        this.$set(this, "giftGivingItem", datas.list);
                    }
                    console.log(this.giftGivingItem);
                }
                /* 获取送礼订单列表 结束 */
            } else if (res.code == 400) {
                // 获取送礼订单列表失败
                Toast(res.message);
            } else {
                // 获取送礼订单列表失败
                Toast("获取送礼订单列表失败");
            }
        }
    }
};
</script>

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