var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp()
Page({
  data: {
    // text:"这是一个页面"
    activityList: [],
    page: 1,
    size: 10,
    count: 0,
    scrollTop: 0,
    type: 0,//活动类型 1 2团购
    showPage: false
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.setData({
      type: null!=options.type?parseInt(options.type):0
    });
    
    wx.setNavigationBarTitle({
      title: '活动'
    })
  },
  onReady: function () {
    // 页面渲染完成

  },
  onShow: function () {
    // 页面显示
    this.getActivityList();
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  nextPage: function (event) {
    console.log();
    var that = this;
    if (this.data.page + 1 > that.data.count / that.data.size) {
      return true;
    }

    that.setData({
      "page": parseInt(that.data.page) + 1
    });

    this.getActivityList();

  },
  getActivityList: function () {

    let that = this;
    that.setData({
      scrollTop: 0,
      showPage: false,
      topicList: []
    });
    // 页面渲染完成
    wx.showToast({
      title: '加载中...',
      icon: 'loading',
      duration: 2000
    });

    util.request(api.ActivityList, { page: that.data.page, size: that.data.size,type:that.data.type }).then(function (res) {
      if (res.errno === 0) {

        that.setData({
          scrollTop: 0,
          activityList: res.data.data,
          showPage: true,
          count: res.data.count
        });
      }
      wx.hideToast();
    });
  },
  prevPage: function (event) {
    if (this.data.page <= 1) {
      return false;
    }

    var that = this;
    that.setData({
      "page": parseInt(that.data.page) - 1
    });
    this.getActivityList();
  },
  gotoGroup(event) {
    wx.redirectTo({
      url: '/pages/group/group?goods_id=' + event.currentTarget.dataset.goodsId
    })
  },
})