list.js 4.99 KB
var e = getApp(), i = e.request, os = e.globalData.setting, ut = require("../../../../utils/util.js");
var regeneratorRuntime = require('../../../../utils/runtime.js');

Page({
    data: {
        url: os.imghost,
        goodlist:[],
        page: 1,
        timer: null,
        ismore: 1,  //是否可以加载更多
        isshow: 0,
        ad_data: null,
        max_sw_height: 200,
    },

    //------初始化加载----------
    onLoad: function (t) {
        var first_leader = t.first_leader;
        var th = this;
        getApp().getConfig();
        this.data.act_id=t.act_id;

        if (first_leader) {
            getApp().globalData.first_leader = first_leader;
            //调用接口判断是不是会员
            getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + first_leader, {}).then(res => {
                if (res.data.code == 0) {
                    getApp().globalData.guide_id = res.data.data.id;
                }
            })
        }

        getApp().request.promiseGet("/api/weshop/ad/page?pid=1202&store_id=" + os.stoid, {
            data: {
                enabled: 1
            }
        }).then(res => {
            if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length > 0) {
                var a = res.data.data.pageData;
                var narr = [];
                for (var i in a) {
                    var tt = {
                        'ad_code': os.imghost + a[i].ad_code,
                        'media_link': '',
                        'ad_weapplink': a[i].ad_weapplink
                    };
                    narr.push(tt);
                }
                th.setData({ad_data: narr});
            }
        })

        var userInfo=getApp().globalData.userInfo;
        if(userInfo && goodlist.length==0){
            //调用列表
            this.get_list();
        }else{
            getApp().goto("/pages/togoin/togoin");
        }
    },
    onShow: function (t) {
        var userInfo=getApp().globalData.userInfo;
        if(userInfo && this.data.goodlist.length==0){
            //调用列表
            this.get_list();
        }else{
            if(getApp().globalData.pre_back==1){
                getApp().globalData.pre_back=0;
                getApp().goto("/pages/index/index/index");
            }
        }
    },
    //---小于10的格式化函数----
    timeFormat(param) {
        return param < 10 ? '0' + param : param;
    },

    onReachBottom: function () {
        this.get_list();
    },

    //图片失败,默认图片
    bind_bnerr2: function (e) {
        var _errImg = e.target.dataset.errorimg;
        var val = e.target.dataset.val;
        if (val != undefined && val != null && val != 'null') {
            var _errObj = {};
            _errObj[_errImg] = "/public/images/default_goods_image_240.gif";
            this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
        }
    },


    imageLoad: function (e) {
        var imgwidth = e.detail.width;
        var imgheight = e.detail.height;
        //宽高比
        var ratio = imgwidth / imgheight;
        //计算的高度值
        var viewHeight = 750 / ratio;
        var hei = this.data.max_sw_height;
        if (hei < viewHeight) {
            this.setData({max_sw_height: viewHeight});
        }
    },


    //获取数据
    get_list(){
        var self = this;
        if (this.data.loading) return false;
        if (this.data.no_more) return false;
        this.data.loading = 1;

        var req = {
            is_end: 0,
            store_id: os.stoid,
            page: this.data.page,
            pageSize: 10,
            timetype: 1
        }
        if(getApp().globalData.userInfo){
            req.user_id=getApp().globalData.userInfo.user_id;
        }
        if(this.data.act_id){
            req.prom_type=8;
            req.prom_id=this.data.act_id;
        }
        //调用接口获取数据
        getApp().request.get("/api/weshop/marketing/marketingPresellList/page", {
            data: req,
            success: function (res) {
                console.log(res);
                self.data.loading = 0;
                if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length > 0) {
                    var list = self.data.goodlist ? self.data.goodlist : [];
                    var arr = res.data.data.pageData;
                    //数组合起来
                    for (var i in arr) {
                        list.push(arr[i]);
                    }
                    self.data.page++;
                    self.setData({goodlist: list});
                    if (arr.length < 10) {
                        self.setData({no_more: 1})
                    }
                } else {
                    self.setData({no_more: 1})
                }
                self.setData({is_get: 1})

            }
        })
    },
    go_index:function () {
        getApp().goto("/pages/index/index/index");
    }


});