rwd
litian
2024-09-23 fa93e847216dfe1da8920aecfa37c37b887c0f29
packageBookService/pages/bookServices/detail/components/learnTask/index.js
@@ -15,7 +15,7 @@
    name: '',
    school: '',
    class: '',
    learnTime: '2',
    learnTime: '0小时',
    taskShow: false,
    dataList: [], //任务单
    tasksListData: [], //已填写任务单messsge
@@ -24,7 +24,7 @@
    userId: 0,
    userName: '',
    isUpdate: false,
    taskId: 0, //默认选中目录id
    taskId: '', //默认选中目录id
    autosize: {
      maxHeight: 120,
      minHeight: 80,
@@ -32,6 +32,8 @@
    disabled: false,
    dialogVisible: false,
    invitee: "",
    teacherEvaluated: false,
    evaluated: false
  },
  onShow() {
    var that = this;
@@ -55,7 +57,7 @@
        taskId: options.bookId,
        consumer: options.consumer,
        userId: options.userId,
        userName: JSON.parse(wx.getStorageSync(app.config.userInfoKey)).name
        userName: JSON.parse(wx.getStorageSync(app.config.userInfoKey)).nickName
      });
      if (options.consumer) {
        this.setData({
@@ -72,13 +74,44 @@
          disabled: false
        });
      }
      console.log(options.consumer, 77)
      this.getResourceData()
      this.getLearnTime()
    }
  },
  getLearnTime() {
    app.MG.identity
      .getUserKey({
        domain: 'cloudLearningTime',
        keys: [this.data.bookId + '']
      })
      .then((res) => {
        if (res.length > 0 && JSON.parse(res[0].value) && JSON.parse(res[0].value).length > 0) {
          let time = JSON.parse(res[0].value)[0].learnTime
          let minutes = Number(time) / (1000 * 60)
          let hours = Number(time) / (1000 * 60 * 60)
          if (minutes > 0 && minutes < 60) {
            this.setData({
              learnTime: Math.round(minutes) + '分钟',
            });
          } else if (minutes > 60) {
            this.setData({
              learnTime: Math.round(hours) + '小时',
            });
          } else {
            this.setData({
              learnTime: '0小时',
            });
          }
        }
      })
  },
  getResourceData() {
    this.setData({
      menuList: [],
      loading: true,
    });
    let query = {
@@ -124,10 +157,12 @@
          }
          dataList.push(item)
        })
        setTimeout(() => {
        this.setData({
          menuList: dataList,
          loading: false,
        });
        }, 500)
        if (this.data.taskId) {
          setTimeout(() => {
            this.data.menuList.forEach((item) => {
@@ -163,6 +198,11 @@
      this.getTasksList()
    })
  },
  getTask(e) {
    console.log(e)
    let item = e.currentTarget.dataset.item
    this.taskSelect(item)
  },
  onVisibleChange(e) {
    this.setData({
@@ -191,7 +231,7 @@
      this.setData({
        tasksListData: res.datas,
      });
      if (this.data.taskInfo) {
      if (this.data.taskInfo.name) {
        this.taskSelect(this.data.taskInfo)
      }
    })
@@ -218,28 +258,27 @@
              });
              this.getChildTasksList()
              if (content.evaluate.length > 0) {
                content.evaluate.forEach((element) => {
                  if (this.data.consumer == 'classmate') {
                    element.mateEvaluation = ''
                  }
                  if (this.data.consumer == 'teacher') {
                    element.teacherEvaluation = ''
                  }
                })
                // content.evaluate.forEach((element) => {
                //   if (this.data.consumer == 'classmate') {
                //     element.mateEvaluation = ''
                //   }
                //   if (this.data.consumer == 'teacher') {
                //     element.teacherEvaluation = ''
                //   }
                // })
                this.setData({
                  dataList: content.evaluate,
                });
              }
            }
          } else {
            this.goDetail(item)
            return false
          }
        })
      } else {
        this.goDetail(item)
      }
    }
    if (this.data.dataList.length == 0) {
      this.goDetail(item)
    }
  },
  goDetail(item) {
@@ -274,6 +313,7 @@
      }
      this.setData({
        dataList: res.datas.cmsDatas[0].datas,
        taskShow: true,
      });
    })
  },
@@ -293,19 +333,50 @@
      if (res.datas.length > 0) {
        let list = []
        this.data.dataList.forEach((item) => {
          item.teacherEvaluation = []
          item.mateEvaluation = []
          res.datas.forEach((item1) => {
            let content = JSON.parse(item1.content)
            if (content.teacherComment) {
            if (content.teacherComment.length > 0) {
              content.teacherComment.forEach((item2) => {
                if (item.id == item2.childTaskId) {
                  item.teacherEvaluation.push(item2)
                  item.mateEvaluation = [item2]
                  if (this.data.consumer == 'teacher') {
                    this.setData({
                      evaluated: true
                    });
                  }
                }
              })
            }
            if (content.mateComment) {
            if (item.teacherEvaluation && item.teacherEvaluation.length > 0) {
              this.setData({
                teacherEvaluated: true
              });
            }
            if (content.mateComment.length > 0) {
              content.mateComment.forEach((item3) => {
                if (item.id == item3.childTaskId) {
                  item.mateEvaluation.push(item3)
                  item.mateEvaluation = [...item.mateEvaluation, item3]
                  console.log(item.mateEvaluation, 123)
                  if (this.data.consumer == 'classmate') {
                    if (item.mateEvaluation && item.mateEvaluation.length > 0) {
                      let data = item.mateEvaluation.find(
                        (item) => item.userId == this.data.userId
                      )
                      if (data) {
                        this.setData({
                          evaluated: true
                        });
                        item.mateEvaluation = [data]
                      } else {
                        this.setData({
                          evaluated: false
                        });
                        item.mateEvaluation = ''
                      }
                    }
                  }
                }
              })
            }
@@ -363,6 +434,7 @@
  //提交自己填写
  inviteBtn() {
    let empty = false
    console.log(this.data.dataList, 123)
    this.data.dataList.forEach((item) => {
      if (item.introspection == '' || item.completion == '' || item.selfEvaluation == '') {
        empty = true
@@ -422,6 +494,7 @@
  },
  updateSubmit() {
    let evaluate = []
    console.log(this.data.dataList, 211)
    this.data.dataList.forEach((item) => {
      evaluate.push({
        id: item.id,
@@ -478,6 +551,14 @@
  },
  confirmBtn() {
    if (this.data.invitee == 'teacher' && this.data.teacherEvaluated) {
      wx.showToast({
        title: "教师已经评价,不能再邀请教师评价!",
        icon: 'none',
        duration: 1000
      })
      return false
    }
    wx.showShareMenu({
      withShareTicket: true
    });
@@ -487,37 +568,44 @@
    let teacherEvaluationList = []
    this.data.dataList.forEach((item) => {
      if (this.data.consumer == 'classmate') {
        if (item.mateEvaluation == '') {
          wx.showToast({
            title: "请先填评价",
            icon: 'none',
            duration: 1000
          })
        } else {
        if (item.mateEvaluation && item.mateEvaluation != '') {
          mateEvaluationList.push({
            childTaskId: item.id,
            userId: this.data.userId,
            userName: this.data.userName,
            evaluation: item.mateEvaluation
          })
        }
      }
      if (this.data.consumer == 'teacher') {
        if (item.teacherEvaluation == '') {
          wx.showToast({
            title: "请先填评价",
            icon: 'none',
            duration: 1000
          })
        } else {
        if (item.teacherEvaluation && item.teacherEvaluation != '') {
          teacherEvaluationList.push({
            childTaskId: item.id,
            userId: this.data.userId,
            userName: this.data.userName,
            evaluation: item.teacherEvaluation
          })
        }
      }
    })
    if (this.data.consumer == 'classmate') {
      if (mateEvaluationList.length < this.data.dataList.length) {
        wx.showToast({
          title: "请先填写评价",
          icon: 'none',
          duration: 1000
        })
      }
    }
    if (this.data.consumer == 'teacher') {
      if (teacherEvaluationList.length < this.data.dataList.length) {
        wx.showToast({
          title: "请先填写评价",
          icon: 'none',
          duration: 1000
        })
      }
    }
    let content = {
      id: this.data.taskInfo.id,
      taskName: this.data.taskInfo.name,
@@ -565,7 +653,7 @@
  onShareAppMessage() {
    return {
      title: '评价学习任务单',
      path: `packageBookService/pages/bookServices/detail/components/learnTask/index?bookId=${this.data.bookId}&consumer=${this.data.invitee}&taskId=${this.data.taskInfo.id}&userId=${this.data.userId}`,
      path: `packageBookService/pages/bookServices/detail/components/learnTask/index?bookId=${this.data.bookId}&consumer=${this.data.invitee}&taskId=${this.data.taskInfo.id}&userId=${this.data.userId}&cmsPath=${this.data.cmsPath}`,
      imgUrl: 'https://jsek.bnuic.com/home/image/click-icon.png',
    }
  }