task_assistance.js 5.31 KB
var auth = require("../../../utils/auth.js"), rq = require("../../../utils/request.js");
var e = getApp(), app = e, i = require("../../../utils/util.js"),
  ut = i,s = e.globalData.setting, os = s, app_d = e.globalData;
var regeneratorRuntime = require('../../../utils/runtime.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sw_index: 0,//轮播的下标控制
    iurl: s.imghost,
    is_task:0,//判断标题名是任务1还是2
    activity_data:"25:20:59",//活动剩余时间
    task_number:12,//任务数
    is_task:0,//历史记录与任务
    aitem:"",//活动的轮播图
    switch_head: 0, //0:我的任务,1:记录
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var help_id=options.help_id;
    console.log("是什么鬼",help_id);
    var th=this;
    th.close();
  },
  // 轮播图点击左边
  click_pre:function(){
    var index = this.data.sw_index;
    index--;
    if (index < 0) return;
    this.setData({ sw_index: index })
    
  },
   //轮播图点击右边
  click_next:function(){
    var index = this.data.sw_index;
    index++;
    if (index >= this.data.aitem.length) return;
    this.setData({ sw_index: index })

  },
  //任务领取
  onlicke:function(){
    var th=this;
    getApp().my_warnning("任务领取成功", 1, th);
  },

//我的任务和帮拆记录的替换
  switch_head: function (e) {
    var th = this;
    var index = e.currentTarget.dataset.index;//获取当前选择的是任务还是活动说明
    var switch_head = th.data.switch_head;//0任务,1活动说明
    if (index != switch_head) {
      th.setData({
        switch_head: index,
        is_task: index
      })
    }
  },
  //划动的时候监听
  onSli:function(e){
  
    var ind=e.detail.current ;
    this.setData({
      sw_index:ind
    })
  },
  //导航球
  close: function () {
    var th = this;
    var nav_b = th.selectComponent("#nav_b"); //组件的id
    nav_b.close_box();
    nav_b.set_name("助力", "");
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var th=this;
    /*-----统计-----*/
    rq.get("/api/weshop/zl_task", {
      data: { user_id: app_d.user_id,
        strod_id:os.stoid
       },
      success: function (su) {
      
        var data=su.data;
        console.log('waitlist5555555555' + data.code);
        if (data.code!=0){
          getApp().my_warnning(data.msg,0, th);
          return false;
        }
        if (data.code==0){
          //轮播图的数据
          var data_aissa=data.data.pageData;
          //当前时间戳
          var nt = ut.gettimestamp();

          data_aissa.forEach(function (val, ind) {
            console.log(nt, "当前时间","结束时间", val.end_time,"开始时间");
            //已开始
            if (val.start_time < nt && val.end_time > nt) data_aissa[ind].status = 0;
            //未开始
            else if (val.start_time > nt && val.end_time > nt) data_aissa[ind].status = 1;
              //已结束
             
            else if (val.start_time < nt && val.end_time < nt) data_aissa[ind].status = 2;
            
          });

          console.log("是什么东西2222222222",data_aissa);
  
          th.setData({ aitem:data_aissa});


        }
        
      }
    })

  },
  //----助力任务-----
  countDown() {
    if (!this.data.is_timer) return false;
    var th = this;
    // 获取当前时间,同时得到活动结束时间数组
    var newTime = ut.gettimestamp();
    var List = this.data.aitem;
    for (var j = 0; j < List.length; j++) {
      var endTimeList = List[j];
      // 对结束时间进行处理渲染到页面
      for (var i = 0; i < endTimeList.length; i++) {
        var o = endTimeList[i];
        var endTime = o.end_time
        if (o.status == 0) endTime = o.start_time

        var obj = null;
        // 如果活动未结束,对时间进行处理
        if (endTime - newTime > 0) {
          var time = (endTime - newTime);
          // 获取天、时、分、秒
          var day = parseInt(time / (60 * 60 * 24));
          var hou = parseInt(time % (60 * 60 * 24) / 3600);
          var min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
          var sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
          obj = {
            day: this.timeFormat(day),
            hou: this.timeFormat(hou),
            min: this.timeFormat(min),
            sec: this.timeFormat(sec)
          }
        } else {
          //活动已结束,全部设置为'00'
          obj = {
            day: '00',
            hou: '00',
            min: '00',
            sec: '00'
          }
        }
        var txt = "aitem[" + j + "][" + i + "].djs";
        th.setData({
          [txt]: obj
        });
      }

    }
    setTimeout(th.countDown, 1000);
    
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})