mygiftpack.js 5.15 KB
var i = require("../../../utils/util.js")
var e = getApp(),
  a = e.globalData.setting,
  os = a,
  t = e.request,
  d = e.globalData;
Page({
  data: {
    iurl: a.imghost, //图片前缀网址
    getDate: "",
    getStorageID: '',
    getUserID: '',
    wareCard: [],
    // pages: 0,
    // pageSize: 10,
    isEmpty: false,
    loadingType: 0, //定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore
    contentText: {
      contentdown: '加载更多',
      contentrefresh: '加载中...',
      contentnomore: '已加载全部'
    },
    ismore:0,//数据是否全部加载完成
    is_read:0,//是否查询过我的礼包接口
    curpage: 1, //当前分页数
    pageSize: 10, //页大小
    total: 0, //总数量
  },

  onLoad: function(options) {
    // this.getStorageID = options.stoid;
    // this.getUserID = options.userid;
    var th = this;
    th.setData({
      getStorageID: a.stoid,
      getUserID: d.user_id,
      loadingType: 0,
      getDate: i.formatTime(new Date().getTime())
    })
    th.getList();
  },
  onShow: function() {
    // this.pages = 1;
    // this.pageSize = 10;
    // this.loadingType = 0;
    // this.getList();
    // var th = this;
    // th.setData({
    //   pages: 1,
    //   pageSize: 10,
    //   loadingType: 0
    // })
    // th.getList();
  },
  // methods: {  
  //   BuyGift: function BuyGift() {
  //     /*销毁跳转*/
  //     uni.reLaunch({
  //       url: 'pages/giftpack/buygiftpack/giftpackbuy?stoid=' + this.getStorageID + '&userid=' + this.getUserID
  //     });

  //   },
  //   GetGiftPackList: function(getId, ojb) {
  //     //不销毁调整
  //     uni.navigateTo({
  //       url: 'pages/giftpack/giftpacklist/giftpacklist?isBuy=0&stoid=' + this.getStorageID + '&userid=' + this.getUserID + '&id=' +
  //         getId
  //     });

  //   },
  getList: function() {
    var th = this;
    // if (th.data.loadingType) {
    //   return false;
    // }
    // // that.loadingType = 1;
    // th.setData({
    //   loadingType: 1
    // })
    getApp().request.get('/api/weshop/marketing/my/giftbag/page', {
      data: {
        // "storeId": this.getStorageID, //商家ID
        // "userId": this.getUserID, //用户ID
        // "page": this.pages,
        // "pageSize": this.pageSize
        storeId: th.data.getStorageID, //商家ID
        userId: th.data.getUserID, //用户ID
        page: th.data.curpage,
        pageSize: th.data.pageSize
      },
      success: function success(res) {
        wx.hideLoading();
        if (res.data.code == 0) {
          th.data.curpage++;
          var arr1 = th.data.wareCard;
          var arr2 = res.data.data.pageData;
          var arr3 = [...arr1, ...arr2];
          var ismore = 0;
          if (arr3.length == res.data.data.total) ismore = 1
          th.setData({
            wareCard: arr3,
            total: res.data.data.total,
            ismore: ismore,
            is_read:1
          }), wx.stopPullDownRefresh(); //停止下拉刷新
        } else {
          th.setData({
            is_read: 1
          })
        }
       // if (res.data.code == 0) {
        //   if (res.data.data.total > 0) {
        //     // _this.isEmpty = false;
        //     _this.setData({
        //       isEmpty: false
        //     })
        //   } else {
        //     // _this.isEmpty = true;
        //     _this.setData({
        //       isEmpty: true
        //     })
        //   }
        //   if (res.data.data.pageData.length == 0) {
        //     // _this.loadingType = 2;
        //     _this.setData({
        //       loadingType: 2
        //     })
        //   } else {
        //     var wareCard = that.wareCard;
        //     var is_resad = 0;
        //     // if (_this.wareCard.length < res.data.data.pageData.length) {
        //     if (wareCard.length < res.data.data.total) {
        //       for (var i = 0; i < res.data.data.pageData.length; i++) {
        //         wareCard.push(res.data.data.pageData[i]);
        //       }
        //     }else{
        //       is_resad=1
        //     }
        //     _this.setData({
        //       wareCard: wareCard,
        //       is_resad: is_resad
        //     })

        //     // _this.loadingType = 0;
        //     _this.setData({
        //       loadingType: 0
        //     })
        //   }
        // } else {

        // }
      }
      
    });

  },
  //销毁界面跳转
  redirectTo: function (e) {
    var th = this;
    var url = e.currentTarget.dataset.url;
    //销毁跳转
    wx.redirectTo({
      url: url
    });
  },
  //不销毁界面跳转
  navigateTo: function (e) {
    var th = this;
    var url = e.currentTarget.dataset.url;
    getApp().goto(url);
  },
  //下拉事件
  onReachBottom: function () {
    var th = this;
    if (th.data.total <= th.data.pageSize) return;
    if (th.data.ismore) return;
    wx.showLoading({
      title: '加载中...',
    })
    th.getList();
  },
  //图片失败,默认图片
  bind_bnerr2: function (e) {
    var _errImg = e.target.dataset.errorimg;
    var _errObj = {};
    _errObj[_errImg] = "/public/images/empty.jpg";
    this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; 

  },

});