// pages/t-task/t-task.js
var myRequest = require("../../utils/api.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabPanelCustomStyle: 'display:flex;justify-content:center;align-items:center;min-height: 120px',
    value: '',
    icons: [,
      'chevron-right',
    ],
    time: 96 * 60 * 1000,
    page: 1,
    size: 10,
    projectId: '',
    status: 0,
    taskData: [],
    isFromSearch: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var projectId = wx.getStorageSync('projectId');
    this.setData({
      projectId: projectId
    })
    this.getTaskData()
  },
  //上拉
  onReachBottom() {
    this.setData({
      page: that.data.page+1,
      isFromSearch: false
    });
    this.getTaskData()
  },
  getTaskData() {
    var that = this;
    myRequest.myRequest('task/list', {
      projectId: that.data.projectId,
      page: that.data.page,
      size: that.data.size,
      status: that.data.status
    }, 'get').then(function(res){
      var siteList = res.data.data.items;
      if (siteList.length != 0){
        var list = [];
        //如果isFromSearch是true从data中取出数据，否则先从原来的数据继续添加 
        that.data.isFromSearch ? list = siteList : list = that.data.taskData.concat(siteList) 
        that.setData({ 
          taskData: list, //获取数据数组 
        });
      }
      that.setData({ 
        searchLoadingComplete: true, //把“没有数据”设为true，显示 
        searchLoading: false //把"上拉加载"的变量设为false，隐藏 
       });
    }).catch(function(res){
      console.log(res);
    })
  },
  onTabsChange(event) {
    this.setData({
      status: event.detail.value
    })
    this.getTaskData()
  },
  //任务详情
  tsakDetail(e) {
    var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    var time = e.currentTarget.dataset.time;
    var content = e.currentTarget.dataset.content;
    var handname = e.currentTarget.dataset.handname;
    wx.navigateTo({
      url: '../d-task/d-task?taskId=' + id + '&name=' + name + '&time=' + time + '&content=' + content + '&handname=' + handname,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

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

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

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

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

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

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