const app = require('../../utils/util.js');
const tools = require('../../utils/tools.js');
const tips = {
  identify: {
    image: 'default',
    desc: '您还没有进行身份认证哦!',
    showBtn: true
  },
  openClass: {
    image: 'default',
    desc: '您当前还没有正在开放的班级!'
  },
  studentErr: {
    image: 'error',
    desc: '学员不可同时存在多个班级中哦!'
  }
};
Page({
  data: {
    isLoading: true,//是否正在加载数据
    pageTip: {
      show: false,
      detail: {}
    },
    isRz: false, // false -- 已认证 / true -- 未认证
    showewm: false, //是否显示班级群二维码
    showzs: false, //是否显示毕业证书
    show: false, //协议显示
    kcArr: [], //课程列表
    sfmArr: [], //课程的时间换算成（时分秒）
    istask1: false, //第一个任务加入班级群
    istask2: false, //第二个任务学员登记表
    istask3: false, //第三个任务所有课程是否学完
    istask4: false, //第四个任务是否完成期末开始
    istask5: false, //第五个任务综合反馈
    istask6: false, //第六个任务是否领取毕业证书
    studentName: "", //学生的名字用于毕业证书
    classInfo: {}, //有关我这个班级的所有信息
    byzsbj: "../../images/zsbj.jpg", //毕业证书的背景 用于合成图片
    myCanvasId: 0, //画布的id 再次绘制不成功的原因是id不能一致  所以id为变量++
    IngCourseArr: [], //如果有正在进行的课就存一下
    currentId: null,
    currentName: "",
    tva:32,
  },
  // 检查第一个任务 班级二维码是否点击 && 检查第二个任务 学员登记表  &&   第六个任务 领取结业证
  checkTaskList(sessionKey) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
      method: "post",
      data: {
        sessionKey: sessionKey
      },
      success: (res) => {
        if (res.data.code == 0) {
          this.setData({
            studentName: res.data.data.studentName,
          })
          if (res.data.data.joinClas == 0) {
            this.setData({
              istask1: true
            })
          }
          if (res.data.data.register == 0) {
            this.setData({
              istask2: true
            })
          }
          if (res.data.data.graduation == 0) {
            this.setData({
              istask6: true
            })
          }
        }
      }
    })
  },
  //保存班级二维码
  saveImg() {
    console.log(this.data.classInfo.codeImg)
    wx.showLoading({
      title: '保存中...'
    })
    wx.downloadFile({
      url: this.data.classInfo.codeImg,
      success: (res) => {
        console.log(res)
        //图片保存到本地
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: () => {
            wx.hideLoading()
            wx.showModal({
              title: '提示',
              content: '保存成功',
              showCancel: false,
            })
          },
          fail: (err) => {
            console.log(err, "我保存失败了")
            if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
              wx.showModal({
                title: '提示',
                content: '需要您授权保存相册',
                showCancel: false,
                success: () => {
                  wx.hideLoading()
                  wx.openSetting({
                    success(settingdata) {
                      if (settingdata.authSetting['scope.writePhotosAlbum']) {
                        wx.showModal({
                          title: '提示',
                          content: '获取权限成功,再次点击即可保存',
                          showCancel: false,
                        })
                      } else {
                        wx.showModal({
                          title: '提示',
                          content: '获取权限失败，将无法保存到相册哦~',
                          showCancel: false,
                        })
                      }
                    },
                    fail(failData) {
                      console.log("failData", failData)
                    },
                    complete(finishData) {
                      console.log("finishData", finishData)
                    }
                  })
                }
              })
            }
          }
        })
      },
      fail: (res) => {
        console.log(res, "我下载失败了")
        wx.hideLoading()
        wx.showModal({
          title: '提示',
          content: '下载失败',
          showCancel: false,
        })
      }
    })
  },
  // (第三个任务在获取列表是做了 --getMycourse()) 第四个任务  期末考试
  checkTaskList4(sessionKey, id) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/exam/clasExamstatus',
      method: "post",
      data: {
        sessionKey: sessionKey,
        clasId: id
      },
      success: (res) => {
        console.log(res)
        if (res.data.code == 0 && res.data.status == 1) {
          this.setData({
            istask4: true
          })
        }
      }
    })
  },
  // 检查第五个任务 综合反馈表
  checkTaskList5(sessionKey, id) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/exam/status',
      method: "post",
      data: {
        sessionKey: sessionKey,
        clasId: id
      },
      success: (res) => {
        if (res.data.code == 0 && res.data.status == 1) {
          this.setData({
            istask5: true
          })
        }
      }
    })
  },
  // 是否认证
  isRz(sessionKey) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
      method: "post",
      data: {
        sessionKey: sessionKey
      },
      success: (res) => {
        if (res.data.code == 0 && (res.data.data !== null || res.data.data !== "")) {
          this.isClass(sessionKey)
          this.setData({
            isRz: false
          })
        } else {
          this.setData({
            isRz: true,
            pageTip: {
              show: true,
              detail: tips.identify
            }
          });
          this.stopLoading();
          // wx.showModal({
          //   content: "您还没有进行身份认证哦",
          //   showCancel: false,
          //   success(res) {
          //     if (res.confirm) {
          //       wx.redirectTo({
          //         url: '../Identity/Identity'
          //       })
          //     }
          //   }
          // })
        }
      }
    })
  },
  escRz() {
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  goRz() {
    wx.navigateTo({
      url: '/pages/Identity/Identity',
    })
  },
  // 查询我是否有班&&班级名字
  isClass(sessionKey) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/student/selMyClas',
      method: "post",
      data: {
        sessionKey: sessionKey
      },
      complete: () => {
        this.stopLoading();
      },
      success: (res) => {
        console.log(res);
        if (res.data.code == 0) {
          this.setData({
            classInfo: res.data.data,
            'pageTip.show': false
          });
          this.isAgree(sessionKey);
          this.getMycourse(sessionKey);
          this.checkTaskList(sessionKey);
          this.checkTaskList4(sessionKey, res.data.data.id)
          this.checkTaskList5(sessionKey, res.data.data.id)
        } else {
          if (res.data.msg == "运行时异常:学员不可同时存在两个班级中。") {
            // wx.showModal({
            //   content: "学员不可同时存在多个班级中哦",
            //   showCancel: false,
            //   success(res) {
            //     if (res.confirm) {
            //       wx.switchTab({
            //         url: '../index/index'
            //       })
            //     }
            //   }
            // })
            this.setData({
              pageTip: {
                show: true,
                detail: tips.studentErr
              }
            });
            return false;
          } else {
            // wx.showModal({
            //   content: "您当前还没有正在开放的班级！",
            //   showCancel: false,
            //   success(res) {
            //     if (res.confirm) {
            //       wx.switchTab({
            //         url: '../index/index'
            //       })
            //     }
            //   }
            // })
            this.setData({
              pageTip: {
                show: true,
                detail: tips.openClass
              }
            });
            return false;
          }
        }
      }
    })
  },
  // 协议是否已同意  
  isAgree(sessionKey) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
      method: "post",
      data: {
        sessionKey
      },
      success: (res) => {
        if (res.data.code == 0 && res.data.data) {
          if (res.data.data.agreement == 0) {
            this.setData({
              studentName: res.data.data.studentName,
              show: false
            });
          } else {
            this.setData({
              studentName: res.data.data.studentName,
              show: true
            });
          }
        }
      }
    })
  },
  moreThink() {
    wx.switchTab({
      url: '../index/index'
    })
  },
  // 点击同意协议 并且记一下
  hidePopup() {
    wx.request({
      url: app.globalData.publicUrl + '/wx/student/verification',
      method: "post",
      data: {
        sessionKey: this.data.sessionKey
      },
      success: (res) => {
        this.setData({
          show: false
        });
      }
    })
  },
  // 获取我的课程表
  getMycourse(sessionKey) {
    
    wx.request({
      url: app.globalData.publicUrl + '/wx/course/selectBySessionKey',
      method: "post",
      data: {
        sessionKey: sessionKey
      },
      success: (res) => {
        console.log(res,"我的课程")
        if (res.data.code == 0 && res.data.list.length !== 0) {
          this.setData({
            kcArr: res.data.list,
            istask3: res.data.allDone,
            currentName: "",
            currentId: null
          });
          // 过滤数组
          for (let i = 0; i < res.data.list.length; i++) {
            // 这个节课未全部完成
            if (res.data.list[i].isLive == -1) {
              if (res.data.list[i].isDone == 0) {
                // 这个视频已经进行了 看一半或者看完了
                if (res.data.list[i].isStudyDone == 0 || res.data.list[i].isStudyDone == 1) {
                  this.setData({
                    currentName: res.data.list[i].courseName,
                    currentId: res.data.list[i].id
                  })
                }
              }
            }
          }
          // 换算时间
          let result = [];
          if (res.data.list)
            for (let i = 0; i < res.data.list.length; i++) {
              result.push({
                courseTime: res.data.list[i].courseTime
              });
            }
          const timesArr = result.map((item) => {
            return item.courseTime;
          });
          let sfmArr = [];
          for (let i = 0; i < timesArr.length; i++) {
            let value = timesArr[i];
            const resultValue = this.handler(value);
            sfmArr.push({
              courseTime: resultValue
            })
            this.setData({
              sfmArr: sfmArr
            })
          }
        }
      }
    })
  },
  // 记录二维码已经点击
  showEwm() {
    wx.showLoading({
      title: '记载中',
      mask: true
    })
    wx.request({
      url: app.globalData.publicUrl + '/wx/student/wxGroup',
      method: "post",
      data: {
        sessionKey: this.data.sessionKey
      },
      success: () => {
        this.setData({
          showewm: true,
          istask1: true
        })
        wx.hideLoading();
      },
      fail: () => {
        wx.hideLoading();
      }
    })
  },
  // 二维码隐藏
  onClose() {
    wx.hideLoading()
    this.setData({
      showewm: false
    });
  },
  // 填写学员登记表
  goWrite() {
    if (this.data.istask1 == false) {
      wx.showModal({
        showCancel: false,
        content: "请先去扫描班级二维码加入班级群吧！"
      })
      return false
    }
    wx.navigateTo({
      url: '../studentRegistration/studentRegistration'
    })
  },
  // 去学习
  goStudy(e) {
    let id = e.currentTarget.dataset.item.id //此课程的id
    let courseUrl = e.currentTarget.dataset.item.courseUrl //此课程的id
    let courseName = e.currentTarget.dataset.item.courseName //此课程的id
    let courseInfo = e.currentTarget.dataset.item.courseInfo //此课程的id
    if (!this.data.istask2) {
      wx.showModal({
        showCancel: false,
        content: "请先去填写学院登记表吧！"
      })
      return false
    }
    // 直播
    if (e.currentTarget.dataset.item.isLive == 1) {
      if (e.currentTarget.dataset.item.isActive == 1) {
        wx.navigateTo({
          url: '../zbDetails/zbDetails?id=' + id
        })
      }
      //  else if (e.currentTarget.dataset.item.isActive == -1) {
      //   wx.navigateTo({
      //     url: '../livePlayback/livePlayback?courseName=' + courseName + '&courseUrl=' + courseUrl + '&courseInfo=' + courseInfo
      //   })
      // } 
      else if (e.currentTarget.dataset.item.isActive == -1) {
        if(courseUrl==null||courseUrl==""){
          wx.showModal({
            showCancel: false,
            content: "直播回放还未上传噢"
          })
        }else{
          wx.navigateTo({
            url: '../livePlayback/livePlayback?courseName=' + courseName + '&courseUrl=' + courseUrl + '&courseInfo=' + courseInfo
          })
        }
      }else {
        wx.showModal({
          showCancel: false,
          content: "直播还未开始哦"
        })
        return false;
      }
    } else {
      if (this.data.currentId != null) {
        // 没学或者没学完
        if (e.currentTarget.dataset.item.isDone == 0) {
          if (id == this.data.currentId) {
            wx.navigateTo({
              url: '../dbDetails/dbDetails?id=' + id
            })
          } else {
            wx.showModal({
              showCancel: false,
              content: "请确认您的 ‘" + this.data.currentName + "’ 这节课中的学习、考试、评价是否都已完成？"
            })
          }
        } else {
          // 我看完了这个视频 还能看
          wx.navigateTo({
            url: '../dbDetails/dbDetails?id=' + id
          })
        }
      } else {
        wx.navigateTo({
          url: '../dbDetails/dbDetails?id=' + id
        })
      }
    }
  },
  // 去考试
  gokhAnswer(e) {
    if (!this.data.istask2) {
      wx.showModal({
        showCancel: false,
        content: "请先去填写学院登记表吧！"
      })
      return false
    }
    let isStudyDone = e.currentTarget.dataset.item.isStudyDone
    if (isStudyDone != 1) {
      wx.showModal({
        showCancel: false,
        content: "您当前的学习课程还未完成哦，请先完成再来考试吧！"
      })
      return false
    } else {
      wx.request({
        url: app.globalData.publicUrl + '/wx/exam/examList',
        method: "post",
        data: {
          sessionKey: this.data.sessionKey,
          courseId: e.currentTarget.dataset.item.id,
          clasId: this.data.classInfo.id
        },
        success: (res) => {
          if (res.data.code == 0) {
            if (res.data.list.length == 0) {
              wx.showModal({
                showCancel: false,
                content: '此课程还没有考试噢'
              })
            } else {
              if (res.data.list[0]) {
                if (res.data.list[0].answersId) {
                  this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass');
                } else {
                  this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass');
                }
              }
            }
          }
        }
      })
    }
  },
  //去评价
  gopjClass(e) {
    if (!this.data.istask2) {
      wx.showModal({
        showCancel: false,
        content: "请先去填写学院登记表吧！"
      })
      return false
    }
    let isStudyDone = e.currentTarget.dataset.item.isStudyDone
    if (isStudyDone != 1) {
      wx.showModal({
        showCancel: false,
        content: "您的学习课程还未完成哦，请先完成学习任务后再来评价吧！"
      })
      return false
    } else {
      wx.request({
        url: app.globalData.publicUrl + '/wx/exam/quesExamList',
        method: "post",
        data: {
          sessionKey: this.data.sessionKey,
          // questSub: '3',
          courseId: e.currentTarget.dataset.item.id,
          clasId: this.data.classInfo.id
        },
        success: (res) => {
          if (res.data.code == 0) {
            if (res.data.list.length == 0) {
              wx.showModal({
                showCancel: false,
                content: '此课程还不可以评价哦！'
              })
            } else {
              if (res.data.list[0]) {
                if (res.data.list[0].answersId) {
                  this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'evaluationCourse');
                } else {
                  this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'evaluationCourse');
                }
              }
            }

          }
        }
      })
    }
  },
  // 期末考试
  goQmks() {
    if (!this.data.istask1) {
      wx.showModal({
        showCancel: false,
        content: "请先去扫描二维码加入班级群吧",
        success(res) {
          if (res.confirm) {
            wx.switchTab({
              url: '../myMission/myMission'
            })
          }
        }
      })
      return false
    }
    if (!this.data.istask3) {
      wx.showModal({
        showCancel: false,
        content: "您的课程任务还未全部完成哦！请先去完成再来期末考试吧！"
      })
      return false
    }
    wx.request({
      url: app.globalData.publicUrl + '/wx/exam/examList',
      method: "post",
      data: {
        sessionKey: this.data.sessionKey,
        clasId: this.data.classInfo.id
      },
      success: (res) => {
        if (res.data.code == 0) {
          if (res.data.list.length == 0) {
            wx.showModal({
              showCancel: false,
              content: '期末考试还未开始哦！'
            })
          } else {
            if (res.data.list[0].answersId) {
              if (res.data.list[0].status == '1') {
                wx.request({
                  url: app.globalData.publicUrl + '/wx/answer/detail',
                  method: "post",
                  data: {
                    answersId: res.data.list[0].answersId
                  },
                  success: (res1) => {
                    if (res1.data.list[0].answerScore >= 0 && res1.data.list[0].answerScore != null) {
                      wx.navigateTo({
                        url: '/pages/grade/grade?answersId=' + res.data.list[0].answersId,
                      })
                    } else {
                      wx.showModal({
                        showCancel: false,
                        content: '当前老师批阅中,请耐心等待'
                      })
                    }
                  }
                })
              } else {
                this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass');
              }
            } else {
              this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass');
            }
          }
        }
      }
    })
  },
  // 综合反馈表
  goWrite2() {
    wx.request({
      url: app.globalData.publicUrl + '/wx/exam/quesExamList',
      method: "post",
      data: {
        sessionKey: this.data.sessionKey,
        questSub: '1',
        clasId: this.data.classInfo.id
      },
      success: (res) => {
        if (res.data.code == 0) {
          if (res.data.list.length == 0) {
            wx.showModal({
              showCancel: false,
              content: '当前综合反馈还不可以填写哦！'
            })
          } else {
            if (res.data.list[0]) {
              if (res.data.list[0].answersId) {
                if (res.data.list[0].status == '1') {
                  wx.navigateTo({
                    url: '/pages/feedBackDetail/feedBackDetail?answersId=' + res.data.list[0].answersId,
                  })
                } else {
                  this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'feedBack');
                }
              } else {
                this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'feedBack');
              }
            }
          }

        }
      }
    })
  },
  // 考试需要的方法
  toPath(id, paperId, answersId, address, status) {
    wx.navigateTo({
      url: '/pages/' + address + '/' + address + '?id=' + id + '&paperId=' + paperId + '&answersId=' + answersId + '&status=' + status,
    })
  },
  // 考试需要的方法
  beginKao(id, paperId, sessionKey, address) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/exam/begin',
      method: "post",
      data: {
        sessionKey: sessionKey,
        id: id,
        paperId: paperId
      },
      success: (res) => {
        if (res.data.code == 0) {
          this.setData({
            status: res.data.status
          })
          this.toPath(id, paperId, res.data.answersId, address, );
        }
      }
    })
  },
  // 领取结业证
  // lq() {
  //   if (!this.data.istask4) {
  //     wx.showModal({
  //       showCancel: false,
  //       content: "请先去期末考试再来领取结业证吧！"
  //     })
  //     return false
  //   }
  //   wx.showLoading({
  //     mask: true,
  //     title: '加载中',
  //   })
  //   this.setData({
  //     myCanvasId: this.data.myCanvasId + 1
  //   })
  //   let str = this.data.studentName + "同志："
  //   let str1 = "于" + this.data.classInfo.beginDate + "至" + this.data.classInfo.endDate + "参加学习" + this.data.classInfo.clasName + "完成规定培训内容。准予结业，特发此证。"
  //   let strArr1 = [];
  //   let a = str1.slice(0, 22);
  //   let b = str1.slice(22, 37);
  //   let c = str1.slice(37, 52);
  //   let d = str1.slice(52, 67);
  //   strArr1.push(a, b, c, d);
  //   const ctx = wx.createCanvasContext(this.data.myCanvasId);
  //   ctx.drawImage(this.data.byzsbj, 0, 0, 300, 415); //里面的参数无非就是图片放置的位置即图片的横纵坐标，图片的宽高
  //   ctx.setFillStyle("#000");
  //   ctx.setFontSize(15); //字大小
  //   ctx.font = 'normal bold 15px sans-serif'
  //   ctx.setTextAlign('left'); //是否居中显示，参考点画布中线
  //   let leftPositionAarr = [60, 30, 30, 30]
  //   ctx.fillText(str, 30, 160);
  //   for (let i = 0; i < strArr1.length; i++) {
  //     ctx.fillText(strArr1[i], leftPositionAarr[i], 190 + i * 30);
  //   }
  //   ctx.draw();
  //   wx.hideLoading();
  //   this.setData({
  //     showzs: true
  //   });
  //   wx.request({
  //     url: app.globalData.publicUrl + '/wx/student/wxGraduation',
  //     method: "post",
  //     data: {
  //       sessionKey: this.data.sessionKey
  //     },
  //     success: (res) => {
  //       console.log(res.data, "领取结业证提交")
  //     }
  //   })
  // },


  //孙喆 2020-9-22 10:38最后更改
  lq() {
    var that = this;
    if (!this.data.istask4) {
      wx.showModal({
        showCancel: false,
        content: "您的期末考试还未完成哦！"
      })
      return false
    }
    wx.showLoading({
      mask: true,
      title: '加载中',
    })
    wx.request({
      url: app.globalData.publicUrl + '/wx/student/wxGraduation',
      method: "post",
      data: {
        sessionKey: this.data.sessionKey
      },
      success: (res) => {
        console.log(res);
        console.log(res.data, "领取结业证提交")
        wx.hideLoading();
        if(res.data.code==500){
          wx.showModal({
            showCancel: false,
            content: "领取失败，请稍后再试"
          })
        }else{
          that.setData({
            myCanvasId: that.data.myCanvasId + 1
          })
          let str = that.data.studentName + " 同志于" + app.dateFilter(that.data.classInfo.beginDate) + "-" + app.dateFilter(that.data.classInfo.endDate) + "参加" + that.data.classInfo.clasName + ",完成规定培训内容。准予结业，特发此证。"
          //汉字占两格，英文数字占一格
          let re = /^[\u4e00-\u9fa5]$/;
          let stra = str.split("");
          let tva = 30;  //阈值
          let strTar = [];
          let num = 0;
          let st = "";
          for (let i = 0; i < str.length; i++) {
            let s = stra.shift()
            st = st + s;
            num += re.test(s) ? 2 : 1;
            tva = strTar.length < 1 ? that.data.tva - 4 : that.data.tva;
            if (num >= tva || i == str.length - 1) {
              strTar.push(st);
              num = 0;
              st = "";
            }
          }
          const ctx = wx.createCanvasContext(that.data.myCanvasId);
          ctx.drawImage(that.data.byzsbj, 0, 0, 300, 415); //里面的参数无非就是图片放置的位置即图片的横纵坐标，图片的宽高
          ctx.setFillStyle("#000");
          ctx.setFontSize(14); //字大小
          ctx.font = 'normal bold 14px sans-serif'
          ctx.setTextAlign('left'); //是否居中显示，参考点画布中线
          let leftPositionAarr = [59, 30]
          let graduationNum =res.data.data.graduationNum!=""? "编号：" + res.data.data.graduationNum:"";
          ctx.fillText(graduationNum, 130, 150);
          
          let topPt=190-(strTar.length-4)*5;
          let lineHeight=30-(strTar.length>4?strTar.length>6?10:(strTar.length-4)*5:0)
          for (let i = 0; i < strTar.length; i++) {
  
            ctx.fillText(strTar[i], i == 0 ? leftPositionAarr[0] : leftPositionAarr[1], topPt + i * lineHeight);
          }
          ctx.draw();
  
          that.setData({
            showzs: true
          });
        }
        
      },
      fail: () => {
        wx.hideLoading();
        wx.showModal({
          showCancel: false,
          content: "网络错误，请稍后再试"
        })
      }
    })
  },
  // 保存结业证
  saveZs() {
    wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片
      canvasId: this.data.myCanvasId,
      success(res) {
        wx.authorize({ //向用户发起授权请求
          scope: 'scope.writePhotosAlbum', //保存相册授权
          success: () => {
            wx.saveImageToPhotosAlbum({ //保存图片到系统相册
              filePath: res.tempFilePath,
              success: () => {
                wx.showToast({
                  title: '图片保存成功'
                })
              }
            })
          }
        })
      }
    })
  },
  // 视频时长换算  换成多少时多少分多少秒
  handler(value) {
    //换算为秒 进制1000
    const second = Math.floor(value / 1000); //判断是否够1秒
    if (second < 1) {
      return "0秒";
    }
    const secondValue = second % 60; // 秒
    const minutes = Math.floor(second / 60); //判断是否够1分钟
    if (minutes < 1) {
      return `${secondValue}秒`;
    }
    const minutesValue = minutes % 60; //分
    const hours = Math.floor(minutes / 60); //判断是否够1小时
    if (hours < 1) {
      return `${minutesValue}分${secondValue}秒`;
    }
    const hoursValue = hours % 60; //小时
    return `${hoursValue}时${minutesValue}分${secondValue}秒`;
  },
  // 结业证隐藏
  onClose1() {
    this.setData({
      showzs: false
    });
  },
  // 查看详情成绩
  gockcj(e) {
    if (e.currentTarget.dataset.item.isExamId) {
      wx.request({
        url: app.globalData.publicUrl + '/wx/answer/detail',
        method: "post",
        data: {
          answersId: e.currentTarget.dataset.item.isExamId
        },
        success: (res) => {
          if (res.data.list[0] &&res.data.list[0].answerScore >= 0 && res.data.list[0].answerScore != null) {
            wx.navigateTo({
              url: '/pages/grade/grade?answersId=' + e.currentTarget.dataset.item.isExamId,
            })
          } else {
            wx.showModal({
              showCancel: false,
              content: '当前老师批阅中,请耐心等待'
            })
          }
        }
      })
    }
  },
  // 查看详情评价
  gockpj(e) {
    wx.navigateTo({
      url: '/pages/evaluationCourseDetail/evaluationCourseDetail?answersId=' + e.currentTarget.dataset.item.isFeedbackId,
    })
  },
  async onShow() {
    wx.showLoading({
      title: '正在加载',
    });
    const sessionKey = await tools.checkSessionAndLogin();
    this.setData({
      sessionKey
    })
    this.isRz(sessionKey);
  },
  onHide(){
    this.setData({
      isLoading: true
    });
  },
  stopLoading() {
    this.setData({
      isLoading: false
    });
    wx.hideLoading();
  }
})