// packageI/newGroup/pastLog/pastLog.js
const app = getApp();
const nowDate = new Date().getTime();
import util from "../../../utils/util";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: [],
    start_time: "",
    end_time: "",
    show1: false,
    show: false,
    currentDate: nowDate,
    formatter(type, val) {
      if (type === "year") {
        return `${val}年`;
      } else if (type === "month") {
        return `${val}月`;
      } else if (type === "day") {
        return `${val}日`;
      }
      return val;
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  btnCancel() {
    console.log('111111111');
    this.setData({
      show: false,
      show1: false
    });
  },
  showTap() {
    this.setData({
      show: true
    });
  },
  showTap1() {
    this.setData({
      show1: true
    });
  },
  btnFinished(e) {
    let time = util.formatTimeTwo((e.detail / 1000), 'Y-M-D');
    this.setData({
      start_time: time,
      show: false
    });
  },
  btnFinished1(e) {
    let time = util.formatTimeTwo((e.detail / 1000), 'Y-M-D');
    this.setData({
      end_time: time,
      show1: false
    });
  },
  serach() {
    this.setData({
      page: 1,
      current_page: 1,
      last_page: 1
    });
    this.getData();
  },
  getData() {
    let urlStr = app.getNetAddresss(
      "plugin.zhp-group-lottery.frontend.contribution.get-old-today-contribution"
    );
    app._postNetWork({
      url: urlStr,
      data: {
        page: this.data.page,
        start_time: this.data.start_time,
        end_time: this.data.end_time
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            info: res.data.data,
            gxz_name:res.data.gxz_name,
            current_page: res.data.current_page,
            last_page: res.data.last_page
          });
          wx.setNavigationBarTitle({
            title: `往日${res.data.gxz_name}数量`,
          });
        } else {
          wx.showToast({
            title: res.msg,
            duration: 1000,
            icon: "none",
          });
        }
      },
    });
  },
  getMore() {
    let that = this;
    let urlStr = app.getNetAddresss(
      "plugin.zhp-group-lottery.frontend.contribution.get-old-today-contribution"
    );
    app._postNetWork({
      url: urlStr,
      data: {
        page: this.data.page,
        start_time: this.data.start_time,
        end_time: this.data.end_time
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            info: that.data.info.concat(res.data.data),
            current_page: res.data.current_page,
            last_page: res.data.last_page
          });
        } else {
          wx.showToast({
            title: res.msg,
            duration: 1000,
            icon: "none",
          });
        }
      },
    });
  },
});