From bd459420ad636263be458374319c20d3eeb6f61a Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期四, 19 九月 2024 21:09:04 +0800
Subject: [PATCH] detail

---
 packageBookService/pages/bookServices/detail/components/learnTask/index.js |  385 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 326 insertions(+), 59 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/components/learnTask/index.js b/packageBookService/pages/bookServices/detail/components/learnTask/index.js
index e3a9020..71b76f3 100644
--- a/packageBookService/pages/bookServices/detail/components/learnTask/index.js
+++ b/packageBookService/pages/bookServices/detail/components/learnTask/index.js
@@ -5,7 +5,9 @@
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
+    height: '', //灞忓箷楂樺害
     bookId: '',
+    cmsPath: '',
     consumer: '',
     bookInfo: {},
     menuList: [],
@@ -19,15 +21,29 @@
     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
+        });
+      },
+    })
+  },
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
@@ -35,8 +51,27 @@
     if (options) {
       this.setData({
         bookId: options.bookId,
-        consumer: options.consumer
+        cmsPath: options.cmsPath,
+        taskId: options.bookId,
+        consumer: options.consumer,
+        userId: options.userId,
+        userName: JSON.parse(wx.getStorageSync(app.config.userInfoKey)).name
       });
+      if (options.consumer) {
+        this.setData({
+          cmsPath: options.cmsPath,
+          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()
     }
 
@@ -50,7 +85,7 @@
       path: '*',
       queryType: '*',
       productId: this.data.bookId,
-      cmsPath: 'jsek_learningTasks',
+      cmsPath: this.data.cmsPath,
       // cmsType: '*',
       itemFields: {
         SysType: 'CmsFolder'
@@ -66,8 +101,8 @@
       });
       if (res.datas.cmsDatas[0].datas) {
         let list = res.datas.cmsDatas[0].datas
-        let dataLists = []
-        list.forEach(async (item) => {
+        let dataList = []
+        list.forEach((item) => {
           if (item.childrenFolderCount > 0) {
             let query = {
               path: '*',
@@ -83,32 +118,52 @@
                 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
+            app.MG.store.getProductDetail(query).then((res) => {
+              item.children = res.datas.cmsDatas[0].datas
             })
-            item.children = data
           }
-          dataLists.push(item)
+          dataList.push(item)
         })
         this.setData({
-          menuList: dataLists,
-          loading: false
+          menuList: dataList,
+          loading: false,
         });
-        console.log(this.data.menuList)
+        if (this.data.taskId) {
+          setTimeout(() => {
+            this.data.menuList.forEach((item) => {
+              if (item.id == this.data.taskId) {
+                this.setData({
+                  taskInfo: item,
+                });
+              } else if (item.children) {
+                item.children.forEach((item1) => {
+                  if (item1.id == this.data.taskId) {
+                    this.setData({
+                      taskInfo: item1,
+                    });
+                  }
+                })
+              }
+            })
+          }, 500)
+        } else {
+          setTimeout(() => {
+            if (this.data.menuList[0].children) {
+              this.setData({
+                taskInfo: this.data.menuList[0].children[0],
+              });
+            } else {
+              this.setData({
+                taskInfo: this.data.menuList[0],
+              });
+            }
+          }, 500)
+        }
       }
       this.getTasksList()
     })
   },
 
-  getTask(e) {
-    console.log(e, 123)
-    let data = e.currentTarget.dataset.item
-    this.setData({
-      taskShow: true,
-    });
-    this.taskSelect(data)
-  },
   onVisibleChange(e) {
     this.setData({
       taskShow: e.detail.visible,
@@ -136,51 +191,52 @@
       this.setData({
         tasksListData: res.datas,
       });
+      if (this.data.taskInfo) {
+        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 = ''
-                }
-              })
+          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 +273,8 @@
         })
       }
       this.setData({
-        dataList: res.datas.cmsDatas[0].datas
+        dataList: res.datas.cmsDatas[0].datas,
       });
-      console.log(this.data.dataList, 444)
     })
   },
   getChildTasksList() {
@@ -236,8 +291,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 +310,11 @@
               })
             }
           })
+          list.push(item)
         })
+        this.setData({
+          dataList: list
+        });
       }
     })
   },
@@ -263,25 +322,229 @@
   //浠诲姟濉啓
   //鍙嶆��
   onIntrospectionInput(e) {
-    console.log(e)
-
+    let index = e.target.dataset.index
+    let data = 'dataList[' + index + '].introspection'
+    this.setData({
+      [data]: e.detail.value
+    });
   },
   //瀹屾垚鎯呭喌
   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
+    });
   },
   //鍚屼即璇勪环
   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) {
+    this.setData({
+      invitee: e.detail.value
+    });
+  },
+
+  handleClose() {
+    this.setData({
+      dialogVisible: false,
+      invitee: ''
+    });
+  },
+
+  confirmBtn() {
+    wx.showShareMenu({
+      withShareTicket: true
+    });
+  },
+  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 +563,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',
+    }
   }
 })
\ No newline at end of file

--
Gitblit v1.9.1