const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baseImgUrl: app.globalData.baseImgUrl,
    thumbnail: app.globalData.thumbnail,
    idx: 0,
    isMohu:false,
    learningState: [
    //   {
    //   "name": "积极性",
    //   "type": 1
    // },
    // {
    //   "name": "自律性",
    //   "type": 2
    // },
    // {
    //   "name": "专注度",
    //   "type": 3
    // },
    // {
    //   "name": "作业速度",
    //   "type": 2
    // }
    ],
    subjectList: []


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ options })
    
    const { subject } = options;
    if (subject) {
      wx.setNavigationBarTitle({
        title: `${subject}作业批改详情`,
      })
    }
    this.getSingleSubject()
  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    const { vipId, date, subject } = this.data.options
    return {
      title: `${subject}作业批改详情`,
      path: `pages/single_subject_detail/single_subject_detail?subject=${subject}&vipId=${vipId}&date=${date}`,
      success: res => {
        wx.showToast({
          title: '转发成功',
          icon: 'success'
        })
      }
    }
  },
  //查看图片
  viewImageCtl: app.viewImageCtl,
  /**
   * 路由跳转
   */
  redirectCtl: app.redirectCtl,

  /**
   * 路由跳转
   */
  navigateCtl: app.navigateCtl,
  /**
   * 查看评语
   */
  getWords: function (e) {
    const { method } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `../remark/remark?method=${JSON.stringify(method)}`,
      success: res => { },
      fail: res => {
        wx.showToast({
          title: '跳转失败',
          icon: 'none'
        })
      }
    })
  },

  // 获取作业报告/api/parents/parents/homeworkReport
  getSingleSubject: function () {
    const postData = { fn: this.getSingleSubject, param: { ...arguments } }
    const { idx, options } = this.data
    const { vipId, date,subject} = options;
    const fn = res => {
      if (res.data!=null){
        const { correctTeacherId, homeworkCommentList = [], homeworkId, homeworkList = [], relateKnowledgeList = [], subject, unfinishedList = [], wrongItemList = [], wrongQuestionCount, correctionStatus, homeworkTime} = res.data;
        this.setData({ correctTeacherId, homeworkCommentList, homeworkId, homeworkList, relateKnowledgeList, subject, unfinishedList, wrongItemList, wrongQuestionCount, correctionStatus, homeworkTime});
        
            var temp = {};
            for (var i in homeworkList) {
              if (homeworkList[i].isVague == 1) {
                this.setData({ isMohu: true })
              }
              temp[`homeworkList[${i}].photoKey`] = homeworkList[i].homeworkPictureUrl
              temp[`homeworkList[${i}].isVague`] =homeworkList[i].isVague
            }
            for (var i in homeworkCommentList) {
              temp[`homeworkCommentList[${i}].photoKey`] = homeworkCommentList[i].homeworkCommentUrl
              temp[`homeworkCommentList[${i}].compositionCommentModuleList`] = homeworkCommentList[i].compositionCommentModuleList
              temp[`homeworkCommentList[${i}].isComposition`] = homeworkCommentList[i].isComposition
            }
            this.setData(temp); 
        }else{
        this.setData({ homeworkList:[]});
        } 
      }
    app.post('/api/parents/parents/V2/correctDetail3', { vipId, date, subject}, 0, postData).then(fn)
  },
  
})