var WxParse = require('../../wxParse/wxParse.js');
const app = getApp();
const baseUrl = getApp();
const api = require('../../config/api.js');
const util = require('../../config/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    now: 1, //当前页码
    all: 15, //总页码
    index:1,
    grouppaper_id:1,//组卷ID
    listdata:[], //数据
    currentdata:[] //当前数据
  },
  onChange:function(event){

        console.log(event.detail.index);
        this.setData({
          active:event.detail.index
        })
  },

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

    this.setData({
      grouppaper_id:options.grouppaper_id,
      active:0
    });
  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

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

  },
  getexammaterial:function(params) {
         //得到练习题目
         const that = this;
         let url = baseUrl.globalData.baseUrl + '/exam/exammaterial';
         var param = {
          grouppaper_id: params
         };
         //此处为使用封装的post请求
         util.post(url, param).then((res) => {
           console.log(res.data[0]);
           that.setData({
             itemdataall: res.data,
             listdata:res.data[0].mitemdata,
             all:res.data[0].mcount,
             currentdata:res.data[0]
           });

         }).catch((errMsg) => {
           console.log(errMsg);
         });      
  },
  clickanswer:function(params) {
       console.log(params.currentTarget.id);
       let grouppaper_id=params.currentTarget.id;
       wx.navigateTo({
        url: '/pages/examproblem/examproblem?grouppaper_id='+grouppaper_id
      })
       
  },
  clickm:function(params) {
    console.log(params.currentTarget.id);
    let grouppaper_id=params.currentTarget.id;
    wx.navigateTo({
      url: '/pages/exammakings/exammakings?grouppaper_id='+grouppaper_id
    })
  }
})