goodsList.js 3.98 KB
var t = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("../../../utils/LoadMore.js")), e = getApp(), a = new t.default(), oo = e.globalData.setting;

Page({
    data: {
        url: e.globalData.setting.imghost,
        resourceUrl: e.globalData.setting.resourceUrl,
        iurl: e.globalData.setting.imghost,
        currentPage: 1,
        requestData: null,
        allData: null,
        openFilterModal: !1,
        baseUrl: "/api/weshop/goods/page?1=1",
        requestUrl: "",
        tabname:"goods_id",   //排序的字段
        adname:"desc",        //升降的字段
		is_new:0,
		is_hot:0,
    },
    onLoad: function(t) {
      a.init(this, "", "requestData");
      var url = this.data.baseUrl;
	  this.data.is_new=t.is_new;
	  this.data.is_hot=t.is_hot;

      if (0 != t.cat_id && t.cat_id != undefined) {
            url += "&cat_id=" + t.cat_id;
            if (t.pid == undefined || t.pid == null){
                url +=  "&parent_id=0";
            }else{
                if(t.pid!="three"){
                    url +=  "&parent_id="+t.pid;
                }
            }
        }

      if (0 != t.brand_id && t.brand_id != undefined) { url += "&brand_id=" + t.brand_id; }
      if (0 != t.nation_id && t.nation_id != undefined) { url += "&nation_id=" + t.nation_id; }
      if (0 != t.group_id && t.group_id != undefined) { url += "&group_id=" + t.group_id; }
      if (0 != t.max_price && t.max_price != undefined) { url += "&min_pirce=" + t.min_pirce + "&max_price=" + t.max_price; }
     
	  if (0 != t.is_new && t.is_new != undefined) { url += "&is_new=" + t.is_new; }
	  if (0 != t.is_hot && t.is_hot != undefined) { url += "&is_hot=" + t.is_hot; }
 
      this.requestGoodsList(url);
    },
    changeTab: function(t) {
       var ord = t.currentTarget.dataset.href;
       var ad = t.currentTarget.dataset.ad;
       var url = this.data.requestUrl;

      if (this.data.tabname!=ord){
         this.setData({ tabname: ord, adname: "desc" });
      }else{
         ad = ad == "desc" ? "asc" :"desc";
        this.setData({adname: ad });
      }  
      this.resetData(), this.requestGoodsList(url);
    },
    requestGoodsList: function(t) {
        var e = this;
        this.data.requestUrl = t,     
        t += "&orderField=" + e.data.tabname;
        t += "&orderType=" + e.data.adname; 
        t +="&page=" + e.data.currentPage, 
        a.request(t, 
          function(t) {
            e.setData({is_go:1});
            e.data.currentPage++, null == e.data.allData && (e.data.allData = Object.assign({}, t.data.result)), 
            wx.stopPullDownRefresh();
         },
          null, { is_mainshow: 1, isonsale: 1, store_id: oo.stoid}
         );
    },
    onReachBottom: function() {
        a.canloadMore() && this.requestGoodsList(this.data.requestUrl);
    },
    onPullDownRefresh: function() {
        this.resetData(), this.requestGoodsList(this.data.requestUrl);
    },
    openFilterModal: function() {
        this.setData({
            openFilterModal: !0
        });
    },
    closeFilterModal: function() {
        this.setData({
            openFilterModal: !1
        });
    },
    filterGoods: function(t) {
        this.resetData(), this.requestGoodsList(t.currentTarget.dataset.href), this.closeFilterModal();
    },
    resetData: function() {
        a.resetConfig(), this.data.requestData = null, this.data.currentPage = 1;
    },

    //---回复最初的设置---
    restoreData: function() {
        this.setData({
            requestData: null,
        });
        this.data.currentPage = 2;
    },
    
    //---图片失败,默认图片---
    bind_bnerr2: function (e) {
    var _errImg = e.target.dataset.errorimg;
    var _errurl = e.target.dataset.url;
    var ii = _errurl.indexOf(oo.imghost);
    if (ii != -1) {
      var _errObj = {};
      _errObj[_errImg] = this.data.iurl+"/miniapp/images/default_g_img.gif";
      this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; 
    }
  }


});