const baseUrl = getApp();
const api = require('../../config/api.js');
const util = require('../../config/util.js');
const utiltime = require('../../utils/util.js');
Page({

  data: {
    date: '',
    pareid: 1,
    listdata: [],
    spot: [],
    indexclassid: 1,
    workdate: [],
    mycnt: 0
  },
  dateChange: function (e) {

    this.getindexclassindex(this.data.indexclassid, e.detail.dateString);

    this.setData({
      dateString: e.detail.dateString,
      workdate: e.detail.dateString
    })
  },
  /*
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var timeNow = utiltime.formatDate(new Date());
    this.getindexclassindexbyworkitem(options.id);
    this.getindexclassindex(options.id, timeNow);
    this.setData({
      indexclassid: options.id,
      date: timeNow,
      spot: timeNow
    });
  },

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

  },

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

    const that = this;
    let url = baseUrl.globalData.baseUrl + '/indexclass/indexclasslistres2';
    var param = {
      indexclasslist_id: indexclassid
    };
    //此处为使用封装的post请求
    util.get(url, param).then((res) => {
      that.setData({
        spot: res.data.workitem
      });

    }).catch((errMsg) => {
      console.log(errMsg);
    });
  },
  getindexclassindex: function (indexclassid, workdate) {
    const that = this;
    let url = baseUrl.globalData.baseUrl + '/indexclass/indexclasslistres';
    var param = {
      indexclasslist_id: indexclassid,
      workdate: workdate
    };
    //此处为使用封装的post请求
    util.get(url, param).then((res) => {
      that.setData({
        listdata: res.data.data,
        mycnt: res.data.cnt
      });

    }).catch((errMsg) => {
      console.log(errMsg);
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

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

  },

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

  },

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

  },

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

  }
})