mygiftpack.js 3.43 KB
var t = require("../../../utils/common.js"); var os = getApp().globalData.setting;
Page({
  data: function data() {
    return {
      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: '已加载全部'
      }
    };
  },

  onLoad: function onLoad(options) {
    this.getStorageID = options.stoid;
    this.getUserID = options.userid;
  },
  onShow: function onShow() {
    this.pages = 1;
    this.pageSize = 10;
    this.loadingType = 0;
    this.getList();
  },
  methods: {  
    BuyGift: function BuyGift() {
      /*销毁跳转*/
      uni.reLaunch({
        url: 'pages/giftpack/buygiftpack/giftpackbuy?stoid=' + this.getStorageID + '&userid=' + this.getUserID
      });

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

    },
    getList: function getList() {
      var _this = this; //上拉加载
      var that = this;
      if (that.loadingType != 0) {
        return false;
      }
      that.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
        },
        success: function success(res) {
          if (res.data.code == 0) {
            console.log(res.data.data);
            if (res.data.data.total > 0) {
              _this.isEmpty = false;
            } else {
              _this.isEmpty = true;
            }
            if (res.data.data.pageData.length == 0) {
              _this.loadingType = 2;
            } else {
              console.log(_this.wareCard.length);
              console.log(res.data.data.pageData.length);
              if (_this.wareCard.length < res.data.data.pageData.length) {
                for (var i = 0; i < res.data.data.pageData.length; i++) {
                  _this.wareCard.push(res.data.data.pageData[i]);
                }
              }

              _this.loadingType = 0;
              console.log(_this.wareCard);
            }
          } else {
            console.log(res.data.msg);
          }
        }
      });

    },
    TimeToDate: function TimeToDate(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;
    }
  }
});