bug
litian
2024-09-10 99dfeb5fc86bce593a5d3f43f45c26eedc00ab0a
packageBookService/pages/bookServices/detail/components/learnTask/index.js
@@ -5,6 +5,7 @@
   * 页面的初始数据
   */
  data: {
    height: '', //屏幕高度
    bookId: '',
    consumer: '',
    bookInfo: {},
@@ -19,24 +20,56 @@
    tasksListData: [], //已填写任务单messsge
    taskInfo: {}, //选中任务单目录
    tasksData: {}, //已填写任务单
    userId: JSON.parse(wx.getStorageSync(app.config.userInfoKey)).id,
    userId: 0,
    userName: '',
    isUpdate: false,
    taskId: 0, //默认选中目录id
    autosize: {
      maxHeight: 120,
      minHeight: 80,
    },
    disabled: false,
    dialogVisible: false,
    invitee: "",
  },
  onShow() {
    var that = this;
    // 动态获取屏幕高度
    wx.getSystemInfo({
      success: (result) => {
        that.setData({
          height: result.windowHeight
        });
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options) {
      console.log(options, 666)
      this.setData({
        bookId: options.bookId,
        consumer: options.consumer
        taskId: options.bookId,
        consumer: options.consumer,
        userId: options.userId,
        userName: JSON.parse(wx.getStorageSync(app.config.userInfoKey)).name
      });
      if (options.consumer) {
        this.setData({
          bookId: options.bookId,
          taskId: options.bookId,
          consumer: options.consumer,
          userId: options.userId,
          disabled: true
        });
      } else {
        this.setData({
          userId: JSON.parse(wx.getStorageSync(app.config.userInfoKey)).userId,
          disabled: false
        });
      }
      this.getResourceData()
    }
@@ -66,36 +99,22 @@
      });
      if (res.datas.cmsDatas[0].datas) {
        let list = res.datas.cmsDatas[0].datas
        let dataLists = []
        list.forEach(async (item) => {
          if (item.childrenFolderCount > 0) {
            let query = {
              path: '*',
              queryType: '*',
              productId: this.data.bookId,
              cmsPath: item.productLinkPath,
              // cmsType: '*',
              itemFields: {
                SysType: 'CmsFolder'
              },
              pading: {
                start: 0,
                size: 99
              }
            }
            const data = await app.MG.store.getProductDetail(query).then((res1) => {
              // item.children = res1.datas.cmsDatas[0].datas
              return res1.datas.cmsDatas[0].datas
            })
            item.children = data
          }
          dataLists.push(item)
        })
        this.setData({
          menuList: dataLists,
          loading: false
          menuList: list,
        });
        console.log(this.data.menuList)
        if (this.data.taskId) {
          this.data.menuList.forEach((item) => {
            if (item.id == this.data.taskId) {
              this.setData({
                taskInfo: item,
              });
            }
          })
        } else {
          this.setData({
            taskInfo: this.data.menuList[0],
          });
        }
      }
      this.getTasksList()
    })
@@ -104,10 +123,35 @@
  getTask(e) {
    console.log(e, 123)
    let data = e.currentTarget.dataset.item
    this.setData({
      taskShow: true,
    });
    if (data.childrenFolderCount > 0) {
      let query = {
        path: '*',
        queryType: '*',
        productId: this.data.bookId,
        cmsPath: data.productLinkPath,
        // cmsType: '*',
        itemFields: {
          SysType: 'CmsFolder'
        },
        pading: {
          start: 0,
          size: 99
        }
      }
      app.MG.store.getProductDetail(query).then((res1) => {
        this.data.menuList.forEach((item) => {
          if (item.id == data.id) {
            item.children = res1.datas.cmsDatas[0].datas
          }
        })
      })
    } else {
      this.setData({
        taskShow: true,
      });
    }
    this.taskSelect(data)
  },
  onVisibleChange(e) {
    this.setData({
@@ -136,51 +180,56 @@
      this.setData({
        tasksListData: res.datas,
      });
      this.taskSelect(this.data.taskInfo)
    })
  },
  taskSelect(item) {
    if (!item.children) {
      this.setData({
        taskInfo: item,
        dataList: []
        dataList: [],
      });
      if (this.data.tasksListData.length > 0) {
        this.data.tasksListData.forEach((item1) => {
          let content = JSON.parse(item1.content)
          if (content.id == this.data.taskInfo.id && content.userId == this.data.userId) {
            isUpdate.value = true
            tasksData.value = item1
            form.name = content.userName
            form.school = content.school
            form.class = content.class
            form.learnTime = content.learnTime
            this.setData({
              isUpdate: true,
              tasksData: item1,
              name: content.userName,
              school: content.school,
              class: content.class,
              learnTime: content.learnTime
            });
            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 = ''
                }
              })
          this.setData({
            name: content.userName,
            school: content.school,
            class: content.class,
            learnTime: content.learnTime,
          });
          if (content.id == this.data.taskInfo.id) {
            if (content.userId == this.data.userId) {
              this.setData({
                dataList: content.evaluate
                isUpdate: true,
                tasksData: item1,
                name: content.userName,
                school: content.school,
                class: content.class,
                learnTime: content.learnTime,
                taskShow: true,
              });
              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 = ''
                  }
                })
                this.setData({
                  dataList: content.evaluate,
                });
              }
            }
            console.log(1111)
          } else {
            this.goDetail(item)
          }
        })
      } else {
        this.goDetail(item)
      }
@@ -217,9 +266,8 @@
        })
      }
      this.setData({
        dataList: res.datas.cmsDatas[0].datas
        dataList: res.datas.cmsDatas[0].datas,
      });
      console.log(this.data.dataList, 444)
    })
  },
  getChildTasksList() {
@@ -236,8 +284,8 @@
    }
    app.MG.ugc.getChildTopicMessageList(query).then((res) => {
      if (res.datas.length > 0) {
        let list = []
        this.data.dataList.forEach((item) => {
          console.log(item, 1)
          res.datas.forEach((item1) => {
            let content = JSON.parse(item1.content)
            if (content.teacherComment) {
@@ -255,7 +303,11 @@
              })
            }
          })
          list.push(item)
        })
        this.setData({
          dataList: list
        });
      }
    })
  },
@@ -264,24 +316,233 @@
  //反思
  onIntrospectionInput(e) {
    console.log(e)
    let index = e.target.dataset.index
    let data = 'dataList[' + index + '].introspection'
    this.setData({
      [data]: e.detail.value
    });
    console.log(this.data.dataList)
  },
  //完成情况
  onCompletionInput(e) {
    let index = e.target.dataset.index
    let data = 'dataList[' + index + '].completion'
    this.setData({
      [data]: e.detail.value
    });
  },
  //自己评价
  onSelfInput(e) {
    let index = e.target.dataset.index
    let data = 'dataList[' + index + '].selfEvaluation'
    this.setData({
      [data]: e.detail.value
    });
    console.log(this.data.dataList)
  },
  //同伴评价
  onMateInput(e) {
    let index = e.target.dataset.index
    let data = 'dataList[' + index + '].mateEvaluation'
    this.setData({
      [data]: e.detail.value
    });
  },
  //老师评价
  onTeacherInput(e) {
    let index = e.target.dataset.index
    let data = 'dataList[' + index + '].teacherEvaluation'
    this.setData({
      [data]: e.detail.value
    });
  },
  //提交自己填写
  inviteBtn() {
    let empty = false
    this.data.dataList.forEach((item) => {
      if (item.introspection == '' || item.completion == '' || item.selfEvaluation == '') {
        empty = true
        return false
      }
    })
    if (empty) {
      wx.showToast({
        title: "请先填写完自己学习情况",
        icon: 'none',
        duration: 1000
      })
    } else {
      let evaluate = []
      this.data.dataList.forEach((item) => {
        evaluate.push({
          id: item.id,
          name: item.name,
          subtaskDescription: item.subtaskDescription,
          learningSuggestions: item.subtaskDescription,
          introspection: item.introspection,
          completion: item.completion,
          selfEvaluation: item.selfEvaluation,
          mateEvaluation: [],
          teacherEvaluation: []
        })
      })
      let content = {
        bookName: this.data.bookInfo.name,
        userName: this.data.name,
        userId: this.data.userId,
        school: this.data.school,
        class: this.data.class,
        learnTime: this.data.learnTime,
        id: this.data.taskInfo.id,
        taskName: this.data.taskInfo.name,
        productLinkPath: this.data.taskInfo.productLinkPath,
        evaluate: evaluate
      }
      let query = {
        topicIdOrRefCode: 'learningTasks',
        name: this.data.bookInfo.name,
        content: JSON.stringify(content),
        type: 'learningTasks',
        cmsTypeRefCode: '',
        newDataListRequest: []
      }
      app.MG.ugc.newTopicMessage(query).then((res) => {
        this.getTasksList()
        this.setData({
          dialogVisible: true
        });
      })
    }
  },
  updateSubmit() {
    let evaluate = []
    this.data.dataList.forEach((item) => {
      evaluate.push({
        id: item.id,
        name: item.name,
        subtaskDescription: item.subtaskDescription,
        learningSuggestions: item.subtaskDescription,
        introspection: item.introspection,
        completion: item.completion,
        selfEvaluation: item.selfEvaluation,
        mateEvaluation: [],
        teacherEvaluation: []
      })
    })
    let content = {
      bookName: this.data.bookInfo.name,
      userName: this.data.name,
      userId: this.data.userId,
      school: this.data.school,
      class: this.data.class,
      learnTime: this.data.learnTime,
      id: this.data.taskInfo.id,
      taskName: this.data.taskInfo.name,
      productLinkPath: this.data.taskInfo.productLinkPath,
      evaluate: evaluate
    }
    let query = {
      topicIdOrRefCode: 'learningTasks',
      id: this.data.tasksData.id,
      name: this.data.bookInfo.name,
      type: 'learningTasks',
      content: JSON.stringify(content),
      newDataRequests: [],
      updateDataRequests: []
    }
    app.MG.ugc.updateTopicMessage(query).then((res) => {
      this.getTasksList()
      this.setData({
        dialogVisible: true
      });
    })
  },
  onInviteeChange(e) {
    console.log(e)
    this.setData({
      invitee: e.detail.value
    });
  },
  handleClose() {
    this.setData({
      dialogVisible: false,
      invitee: ''
    });
  },
  confirmBtn() {
    wx.showShareMenu({
      withShareTicket: true
    });
    console.log(888)
  },
  submitComment() {
    let mateEvaluationList = []
    let teacherEvaluationList = []
    this.data.dataList.forEach((item) => {
      if (this.data.consumer == 'classmate') {
        if (item.mateEvaluation == '') {
          wx.showToast({
            title: "请先填评价",
            icon: 'none',
            duration: 1000
          })
        } else {
          mateEvaluationList.push({
            childTaskId: item.id,
            userName: this.data.userName,
            evaluation: item.mateEvaluation
          })
        }
      }
      if (this.data.consumer == 'teacher') {
        if (item.teacherEvaluation == '') {
          wx.showToast({
            title: "请先填评价",
            icon: 'none',
            duration: 1000
          })
        } else {
          teacherEvaluationList.push({
            childTaskId: item.id,
            userName: this.data.userName,
            evaluation: item.teacherEvaluation
          })
        }
      }
    })
    let content = {
      id: this.data.taskInfo.id,
      taskName: this.data.taskInfo.name,
      productLinkPath: this.data.taskInfo.productLinkPath,
      mateComment: mateEvaluationList,
      teacherComment: teacherEvaluationList
    }
    let query = {
      topicIdOrRefCode: 'learningTasks',
      parentId: this.data.tasksData.id,
      name: this.data.bookInfo.name,
      type: 'learningTasks',
      content: JSON.stringify(content),
      cmsTypeRefCode: '',
      newDataListRequest: []
    }
    app.MG.ugc.newTopicMessage(query).then((res) => {
      this.getTasksList()
      wx.showToast({
        title: "评价已提交",
        icon: 'success',
        duration: 1000
      })
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
@@ -300,6 +561,10 @@
   * 用户点击右上角分享
   */
  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}`,
      imgUrl: 'https://jsek.bnuic.com/home/image/click-icon.png',
    }
  }
})