mygiftpack.js 4.61 KB
var e = getApp(),
  a = e.globalData.setting,
  os = a,
  t = e.request,
  d = e.globalData;
Page({
  data: {
    iurl: a.imghost, //图片前缀网址
    getDate: new Date().getTime(),
    getStorageID: '',
    getUserID: '',
    wareCard: [],
    pages: 0,
    pageSize: 10,
    isEmpty: true,
    loadingType: 0, //定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore
    contentText: {
      contentdown: '加载更多',
      contentrefresh: '加载中...',
      contentnomore: '已加载全部'
    },
    is_resad:0,//数据是否全部加载完成
  },

  onLoad: function(options) {
    // this.getStorageID = options.stoid;
    // this.getUserID = options.userid;
    var th = this;
    th.setData({
      getStorageID: a.stoid,
      getUserID: d.user_id,
      pages: 1,
      pageSize: 10,
      loadingType: 0
    })
    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 _this = this; //上拉加载
    var that = this.data;
    if (that.loadingType != 0) {
      return false;
    }
    // that.loadingType = 1;
    _this.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": that.getStorageID, //商家ID
        "userId": that.getUserID, //用户ID
        "page": that.pages,
        "pageSize": that.pageSize
      },
      success: function success(res) {
        if (res.data.code == 0) {
          console.log(res.data.data);
          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 {
 
        }
      }
    });

  },
  TimeToDate: function(num) { //时间戳数据处理 是按秒来转换
    var date = new Date(num * 1000);
    //时间戳为10位需*1000,时间戳为13位的话不需乘1000
    var y = date.getFullYear();
    var MM = date.getMonth() + 1;
    MM = MM < 10 ? '0' + MM : MM; //月补0
    var d = date.getDate();
    d = d < 10 ? '0' + d : d; //天补0
    var h = date.getHours();
    h = h < 10 ? '0' + h : h; //小时补0
    var m = date.getMinutes();
    m = m < 10 ? '0' + m : m; //分钟补0
    var s = date.getSeconds();
    s = s < 10 ? '0' + s : s; //秒补0
    return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
  },
  DateToTime: function DateToTime(TimeNum) { //时间转换成时间戳
    var Time = new Date(TimeNum);
    return Time.getTime() / 1000;
  },
  //销毁界面跳转
  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;
    wx.navigateTo({
      url: url,
    })
  }

});