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

  /**
   * 页面的初始数据
   */
  data: {
    startPageX: 0,
    currentView: DEFAULT_PAGE,
    baseurl:baseUrl.globalData.baseimgurl,
    movies: [],
    active: 1,
    challengeactive: 1,
    toView: `card_${DEFAULT_PAGE}`,
    list: [],    
    itemdata: [],
    pid:0,
    classname:""
  },
  touchStart(e) {
    this.startPageX = e.changedTouches[0].pageX;
  },
  touchEnd(e) {

    const moveX = e.changedTouches[0].pageX - this.startPageX;
    const maxPage = this.data.list.length - 1;
    if (Math.abs(moveX) >= 150) {
      if (moveX > 0) {
        this.currentView = this.currentView !== 0 ? this.currentView - 1 : 0;
      } else {
        this.currentView = this.currentView !== maxPage ? this.currentView + 1 : maxPage;
      }
    }
    this.setData({
      toView: `card_${this.currentView}`
    });
  },
  touchecard(e) {
    console.log(e.currentTarget.id);
    this.setData({
      active: e.currentTarget.id
    })
    this.getpaperattrlist(e.currentTarget.id);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
        console.log(options);
        this.setData({
           pid:options.id
        })

        wx.setNavigationBarTitle({
          title: '班级资料类型列表'})
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      // this.getpapertype();
      // this.getpaperattrlist(1);
      this.getpaperattrlist(this.data.pid);
     
  },

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

  },

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

  },

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

  },

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

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

  },
  examclicking:function(e){

    console.log(e);
    let id=e.currentTarget.id;
    let indexclassrestype_id=e.currentTarget.dataset.indexclassrestypeid;
    wx.navigateTo({
      url: '/pages/indexclassres/indexclassres?classid='+indexclassrestype_id+"&indexclassrestype_id="+id,
    })
  },
  getpapertype:function(){
    const that = this;
    let url = baseUrl.globalData.baseUrl + '/paperlist/getpapertypelist';
    var param = {
      id: '123456789'
    };
    //此处为使用封装的post请求
    util.get(url, param).then((res) => {
       console.log(res);
      that.setData({
        list: res.data
      });

    }).catch((errMsg) => {
      console.log(errMsg);
    });
  },
  getpaperattrlist:function(params) {
      const that = this;
      let url = baseUrl.globalData.baseUrl + '/res/indexclassrestype';
      var param = {
        indexclasslist_id: params
      };
      //此处为使用封装的post请求
      util.get(url, param).then((res) => {
        console.log(res);
        that.setData({
          itemdata: res.data
        });

      }).catch((errMsg) => {
        console.log(errMsg);
      });
  }
})