var oo = require("../setting.js");
var ut = require('util.js');

function a(a, t, e) {
    return t in a ? Object.defineProperty(a, t, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = e, a;
}

function t(a, t) {
    if (!(a instanceof t)) throw new TypeError("Cannot call a class as a function");
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var e = function() {
    function a(a, t) {
        for (var e = 0; e < t.length; e++) {
            var o = t[e];
            o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0),
            Object.defineProperty(a, o.key, o);
        }
    }
    return function(t, e, o) {
        return e && a(t.prototype, e), o && a(t, o), t;
    };
}(), o = getApp(), n = o.request, i = function() {
    function i() {
        t(this, i), this.data = {
            page: null,
            listName: "",
            resultName: "",
            resultListName: "",
            scrollTimeStamp: 0,
            goodsLoadFinishFlag: !1,
            goodsLoading: !1
        };
    }
    return e(i, [ {
        key: "init",
        value: function(a, t, e, o) {
            this.data.scrollTimeStamp = 0, this.data.page = a, this.data.listName = t, this.data.resultName = e,
            this.data.resultListName = void 0 == o ? t : o, this.data.goodsLoadFinishFlag = !1,
            this.data.goodsLoading = !1;
        }
    }, {
        key: "request",
        value: function(t, e, i,dd) {
            if(dd==undefined) dd=null;
            var s = this,rurl=t;
            return !s.data.goodsLoading && (s.data.goodsLoading = !0, n.get(t, {
                data:dd,
                success: function(t) {
                    var n = !0;

                    var i, r = s.data.listName, l = s.data.resultName, d = s.data.resultListName;
                    i = "" != r ? t.data.data[r] : (t.data.data && t.data.data.pageData?t.data.data.pageData:null);  //data.pageData是接口固定会出现的，封装好了
                    var u = !1, g = null, c = s.data.page;

                    //如果已经的第二页的时候，就是把数据加入数组
                    if (c !=undefined && c.data[l]) {
                        u = !0;
                        var f = null;
                        f = "" != d ? c.data[l][d] : c.data[l], [].push.apply(f, i), g = c.data[l];
                    } else  g = (t.data.data && t.data.data.pageData?t.data.data.pageData:null);


                    //格式化
                    var glist="";
                    if(g && g.length) {
                        for (var ii = 0; ii < g.length; ii++) {
                            //if(g[i].prom_type == 1 || g[i].prom_type == 2 || g[i].prom_type == 6) {
                            if (g[ii].prom_type && g[ii].prom_type == 1) {
                                glist += g[ii].goods_id + ",";
                            }
                            if (g[ii].original_img != undefined) {
                                if (g[ii].original_img.indexOf(oo.imghost) == -1)
                                    g[ii].original_img = oo.imghost + g[ii].original_img;
                            }

                            if (g[ii].add_time != undefined && rurl.indexOf("goodscollect") < 0) {
                                var tx = g[ii].add_time + "";
                                if (tx.indexOf('-') == -1) {
                                    g[ii].add_time = ut.formatTime(g[ii].add_time, 'yyyy-MM-dd hh:mm:ss');
                                }
                            }
                            if (rurl.indexOf('comment/page') != -1) {
                                console.log('comment/page');
                                console.log(g[ii].img);
                                var tx1 = g[ii].img;

                                if (tx1 != "" && tx1 != null && ut.isString(tx1)) {
                                    var arr = ut.unserialize(tx1);
                                    g[ii].img = arr;
                                } else if (!ut.isArray(tx1)) {
                                    g[ii].img = "";
                                }
                            }
                        }
                    }


                  //没有活动，就不用调用接口
                  if (glist==""){
                      c.setData(a({}, l, g));
                      if ("function" == typeof e && (n = e(t)), !1 === n) return !1;
                      i && 0 != i.length || (s.data.goodsLoadFinishFlag = !0, u && o.showWarning("加载完啦", null, 500, !1));
                      return false;
                  }

                  c.setData(a({}, l, g));
                  if ("function" == typeof e && (n = e(t)), !1 === n) return !1;
                  i && 0 != i.length || (s.data.goodsLoadFinishFlag = !0, u && o.showWarning("加载完啦", null, 500, !1));

                  return false;


                  glist = ut.sub_last(glist);
                  //---如果是调用商品列表，就要使用商品实际价格----
                  getApp().request.get("/api/weshop/activitylist/getGoodsPrice/"
                    + oo.stoid + "/" + glist, {
                      success: function (t) {
                        console.log('/goods/page');
                        console.log(t);

                        //g[i].shop_price = t.data.data.prom_price;
                        //g[i].inter = t.data.data.prom_integral;
                        if(t.data.code==0){

                        }

                        c.setData(a({}, l, g));
                        if ("function" == typeof e && (n = e(t)), !1 === n) return !1;
                        i && 0 != i.length || (s.data.goodsLoadFinishFlag = !0, u && o.showWarning("加载完啦", null, 500, !1));
                        return false;

                      }
                    });

                },
                fail: function(a) {
                    var t = !0;
                    return console.log(a), "function" == typeof i && (t = i(a)), t;
                },
                complete: function(a) {
                    s.data.goodsLoading = !1;
                }
            }), !0);
        }
    }, {
        key: "canloadMore",
        value: function() {
            console.log("loadMore...Finish:", this.data.goodsLoadFinishFlag);
            var a = this;
            if (a.data.goodsLoadFinishFlag) return o.showWarning("加载完啦", null, 500, !1), !1;
            var t = new Date().getTime();
            return console.log("loadMore...time:", t), t - a.data.scrollTimeStamp > 300 && (a.data.scrollTimeStamp = t,
            !0);
        }
    }, {
        key: "resetConfig",
        value: function() {
            this.data.goodsLoadFinishFlag = !1;
        }
    } ]), i;
}();

exports.default = i;
