const util = require('../../../utils/util.js');
const api = require('../../../utils/api.js');

const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    apiTotal: '',
    tab: 1,
    list: []
  },

  checkTab: function(e) {
    const that = this;
    let type = e.currentTarget.dataset.type;
    that.setData({
      tab: type
    })
    that.getUnInInfo();
  },

  getUnInInfo: function(e) {
    const that = this;
    let date = new Date();
    let stoday = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    let day1 = new Date();
    day1.setTime(day1.getTime() - 24 * 60 * 60 * 1000);
    let s1 = day1.getFullYear() + "-" + (day1.getMonth() + 1) + "-" + day1.getDate();
    let day3 = new Date();
    day3.setTime(day3.getTime() - 3 * 24 * 60 * 60 * 1000);
    let s3 = day3.getFullYear() + "-" + (day3.getMonth() + 1) + "-" + day3.getDate();
    let day5 = new Date();
    day5.setTime(day5.getTime() - 5 * 24 * 60 * 60 * 1000);
    let s5 = day5.getFullYear() + "-" + (day5.getMonth() + 1) + "-" + day5.getDate();
    console.log(s1, s3, s5)
    util.httpRequest(api.getunInByCount, {
      start: that.data.tab == 1 ? s1 : that.data.tab == 3 ? s3 : s5,
      end: stoday,
      page: 1,
      rows: 20,
      unInCount: that.data.tab
    }, 'post').then(res => {
      that.setData({
        list: res.data.data.data
      })
    })
  },

  makePhoneCall: function(e) {
    let phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const that = this;
    that.setData({
      apiTotal: api.total.substring(0, api.total.length - 4)
    })
    that.getUnInInfo();
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

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

  },

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

  },

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

  },

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

  }
})