// pages/list/list.js
const app = getApp();
const until = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentSwiper: 0,
    array: ['2019-10.11-10.17', '2019-10.11-10.17', '2019-10.11-10.17'],
    array2: ['9年3班语文强化班', '9年3班语文强化班2', '9年3班语文强化班'],
    index: 0,
    index2: 0,
    id: 1,
    parid: 0,
    one: '',
    two: '',
    there: '',
    listtow: [],
    Nofen: '9',
    onShareImgs: "",
    startTime: until.formatTimeNormal(new Date()),
    endTime: until.formatTimeNormal(new Date()),
    timeLimit: until.formatDate2(new Date()),
    search: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let t = this;
    let inent = wx.getStorageSync('ident');
    this.setData({
      classid: options.classId,
      id: options.style,
      Nofen: options.Nofen
    });
    if (inent == "") {
      wx.redirectTo({
        url: '/pages/home/home',
      })
    } else if (inent === "1") {
      this.listFun();
    } else {
      this.listFun();
    }
    // 获取当前时间
    this.setData({
      today: until.formatTimeDay(new Date())
    })
  },
  closeSearch(){
    this.setData({
      search: false
    })
  },
  searchAction(){
    this.setData({
      search: true
    })
  },
  // 转发图片
  onShareImg() {
    let t = this;
    let url = '/api/shareimg/createimg';
    let params = {
      class_id: t.data.classid,
      style: 4
    };
    app.post(url, params).then((res) => {
      t.setData({
        onShareImgs: res.data.msg
      })
    })
  },
  // 参数
  listFun() {
    let t = this;
    let url = '/api/teacher/paihang';
    let params = {
      class_id: t.data.classid,
      style: t.data.id
    };
    app.post(url, params).then(res => {
      console.log(res)
      t.setData({
        list: res.data.msg,
        listtow: res.data.msg.list,
        one: res.data.msg.bef[0],
        two: res.data.msg.bef[1],
        there: res.data.msg.bef[2],
      })
      let inent = wx.getStorageSync('ident');
      if (inent === "0") {
        wx.redirectTo({
          url: '/pages/parentsList/parentsList?class_id=' + t.data.classid + '&student_id=' + res.data.msg.bef[0].id + '&style=' + t.data.id,
        })
      }
      wx.hideLoading();
    });
    t.onShareImg();
  },
  bindDateChangeStart(e) {
    this.setData({
      startTime: e.detail.value
    })
  },
  bindDateChangeEnd(e) {
    this.setData({
      endTime: e.detail.value
    })
  },
  // 轮播底部原点
  swiperChange: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },
  searchConfirm(){
    let url = '/api/teacher/honghua2',params = {
      starttime: this.data.startTime,
      endtime: this.data.endTime,
      class_id: this.data.classid
    },t = this;
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    app.post(url,params).then(res=>{
      wx.hideLoading();
      t.setData({
        search: false,
        searchShow: true,
        list: res.data.msg,
        listtow: res.data.msg.list,
        one: res.data.msg.bef[0],
        two: res.data.msg.bef[1],
        there: res.data.msg.bef[2],
      })
    })
  },
  // tab切换
  gay(e) {
    wx.showLoading({
      title: '加载中',
    });
    this.setData({
      id: e.currentTarget.dataset.id,
      searchShow: false
    });
    this.listFun();
  },
  // 家长端选择班级
  bindPickerChange2(e) {
    this.setData({
      index2: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    let t = this;
    return {
      title: '我的班级',
      path: '/pages/list/list?classId=' + t.data.classid + '&style=' + t.data.id + '&Nofen=' + '8',
      imageUrl: t.data.onShareImgs,
      success: function (res) {
        console.log('成功', res)
      }
    }
  },

})