Explorar el Código

fix:开始学习-进入考试

Tang hace 3 años
padre
commit
39ab42e637
Se han modificado 2 ficheros con 367 adiciones y 20 borrados
  1. 1 0
      src/pages/course-detail/index.vue
  2. 366 20
      src/pages/person-center/my-course/index.vue

+ 1 - 0
src/pages/course-detail/index.vue

@@ -5146,6 +5146,7 @@ export default {
 
         if (this.businessData.goodsLearningOrder == 1) {
           if (section.parent.canLearn) {
+            console.log(section.parent,'section.parent')
             let num = await this.bankRecordDoNum(section);
             //有次数限制
             if (section.answerNum - num > 0 && section.answerNum > 0) {

+ 366 - 20
src/pages/person-center/my-course/index.vue

@@ -113,7 +113,11 @@
                               ? "直播"
                               : is.sectionType === 3
                               ? "回放"
-                              : "练习"
+                              : is.doType == 1
+                              ? "练习"
+                              : is.doType != 1
+                              ? "考试"
+                              : ""
                           }}</span>
                           <span class="span_style">{{ is.name }}</span>
                           <span v-if="is.recordStatus" class="upStudyStyle"
@@ -145,10 +149,27 @@
                             }}
                           </span>
                         </el-col>
+                        <el-col :span="2" :offset="1" v-if="!is.sectionType">
+                          <el-button
+                            size="mini"
+                            style="width: 90px !important"
+                            type="text"
+                            v-if="is.doType == 1"
+                            @click="getResource(item, is)"
+                            >进入学习</el-button
+                          ><el-button
+                            size="mini"
+                            style="width: 90px !important"
+                            type="text"
+                            v-else
+                            @click="getResource(item, is)"
+                            >进入考试</el-button
+                          >
+                        </el-col>
                         <el-col
                           :span="2"
                           :offset="1"
-                          v-if="is.sectionType != 2"
+                          v-else-if="is.sectionType != 2"
                         >
                           <el-button
                             size="mini"
@@ -254,7 +275,11 @@
                           ? "直播"
                           : i.sectionType === 3
                           ? "回放"
-                          : "练习"
+                          : i.doType == 1
+                          ? "练习"
+                          : i.doType != 1
+                          ? "考试"
+                          : ""
                       }}</span>
                       <span class="span_style">
                         {{ i.name }}
@@ -288,7 +313,28 @@
                         }}
                       </span>
                     </el-col>
-                    <el-col :span="2" :offset="1" v-if="i.sectionType != 2">
+                    <el-col :span="2" :offset="1" v-if="!i.sectionType">
+                      <el-button
+                        size="mini"
+                        style="width: 90px !important"
+                        type="text"
+                        v-if="i.doType == 1"
+                        @click="getResource(item, i)"
+                        >进入学习</el-button
+                      ><el-button
+                        size="mini"
+                        style="width: 90px !important"
+                        type="text"
+                        v-else
+                        @click="getResource(item, i)"
+                        >进入考试</el-button
+                      >
+                    </el-col>
+                    <el-col
+                      :span="2"
+                      :offset="1"
+                      v-else-if="i.sectionType != 2"
+                    >
                       <el-button
                         size="mini"
                         type="text"
@@ -375,7 +421,11 @@
                       ? "直播"
                       : items.sectionType === 3
                       ? "回放"
-                      : "练习"
+                      : items.doType == 1
+                      ? "练习"
+                      : items.doType != 1
+                      ? "考试"
+                      : ""
                   }}</span>
                   <span class="span_style">
                     {{ items.menuName }}
@@ -409,7 +459,28 @@
                     }}
                   </span>
                 </el-col>
-                <el-col :span="2" :offset="1" v-if="items.sectionType != 2">
+                <el-col :span="2" :offset="1" v-if="!items.sectionType">
+                  <el-button
+                    size="mini"
+                    style="width: 90px !important"
+                    type="text"
+                    v-if="items.doType == 1"
+                    @click="getResource(item, items)"
+                    >进入学习</el-button
+                  ><el-button
+                    size="mini"
+                    style="width: 90px !important"
+                    type="text"
+                    v-else
+                    @click="getResource(item, items)"
+                    >进入考试</el-button
+                  >
+                </el-col>
+                <el-col
+                  :span="2"
+                  :offset="1"
+                  v-else-if="items.sectionType != 2"
+                >
                   <el-button
                     size="mini"
                     style="width: 90px !important"
@@ -563,24 +634,25 @@ export default {
       appointModal: false, // 预约考试弹窗
       subjectList: [], //当前商品课程科目汇总
       newActiveSubjectId: "", //当前选中ID
+      businessData: {},
     };
   },
   computed: {
     ...mapGetters(["userInfo"]),
-    filterList:function(){
-      return function(item){
-        console.log(this.newActiveSubjectId)
-        let array = []
-        if(this.newActiveSubjectId){
-          array = item.filter(items => {
-            return items.subjectId === this.newActiveSubjectId
-          })
-        }else{
-          return item
+    filterList: function () {
+      return function (item) {
+        console.log(this.newActiveSubjectId);
+        let array = [];
+        if (this.newActiveSubjectId) {
+          array = item.filter((items) => {
+            return items.subjectId === this.newActiveSubjectId;
+          });
+        } else {
+          return item;
         }
-        return array
-      }
-    }
+        return array;
+      };
+    },
   },
   mounted() {
     this.getRecord();
@@ -615,6 +687,7 @@ export default {
     },
     backData(item) {
       this.goodsData = item;
+      this.courseBusiness();
       this.getGoodsCourseList(item);
     },
     //数组对象去重
@@ -670,6 +743,7 @@ export default {
               let array = result.rows[0];
               array.orderGoodsId = res.data.orderGoodsId;
               this.goodsData = array;
+              this.courseBusiness();
               await this.getGoodsCourseList(array);
               resolve();
             }
@@ -875,7 +949,7 @@ export default {
      */
     changeChapterStatus(type, item, courseIndex, index, indexs) {
       return new Promise((resolve, reject) => {
-        console.log(item,'定位')
+        console.log(item, "定位");
         if (item.children && item.children.length > 0) {
           item.showStatus = !item.showStatus;
           return;
@@ -889,6 +963,19 @@ export default {
             orderGoodsId: this.goodsData.orderGoodsId,
           })
           .then((res) => {
+            let newArr = res.data.filter((item) => {
+              return item.type != 2;
+            });
+            let canLearn = newArr.every((item) => {
+              if (item.learning == 1) {
+                return true;
+              } else {
+                return false;
+              }
+            });
+            res.data.forEach((section) => {
+              section.canLearn = canLearn;
+            });
             if (type === 1) {
               this.$set(
                 this.courseList[courseIndex].children[index],
@@ -1075,7 +1162,266 @@ export default {
             });
         });
     },
+    async getResource(courseLists, section) {
+      console.log(section);
+      if (section.type == 2) {
+        //试卷
+        console.log("试卷");
+        console.log(courseLists, section, this.goodsData);
+        let learnNum = await this.goodsTodayStudySectionNum(section);
+        let hasLearn = await this.gradeCheckGoodsStudy(courseLists, section);
+
+        if (this.goodsData.sectionMaxNum > 0) {
+          if (learnNum >= this.goodsData.sectionMaxNum && !hasLearn) {
+            this.$message({
+              type: "warning",
+              message: `每天最多学习${this.goodsData.sectionMaxNum}节`,
+            });
+            return;
+          }
+        }
+        if (this.businessData.goodsLearningOrder == 1) {
+          if (section.canLearn) {
+            let num = await this.bankRecordDoNum(courseLists, section);
+            //有次数限制
+            if (section.answerNum - num > 0 && section.answerNum > 0) {
+              // this.$set(this.list[index],'doNum',(item.doNum+1))
+              this.$router.push({
+                path: "/course-exam/" + this.goodsData.goodsId,
+                query: {
+                  courseId: courseLists.courseId,
+                  gradeId: this.goodsData.gradeId,
+                  moduleId: section.moduleId || 0,
+                  examId: section.typeId,
+                  chapterId: section.chapterId || 0,
+                  orderGoodsId: this.goodsData.orderGoodsId,
+                },
+              });
 
+              //没有答题次数限制
+            } else if (section.answerNum == 0) {
+              this.$router.push({
+                path: "/course-exam/" + this.goodsData.goodsId,
+                query: {
+                  courseId: courseLists.courseId,
+                  gradeId: this.goodsData.gradeId,
+                  moduleId: section.moduleId || 0,
+                  examId: section.typeId,
+                  chapterId: section.chapterId || 0,
+                  orderGoodsId: this.goodsData.orderGoodsId,
+                },
+              });
+            } else {
+              this.$message({
+                type: "warning",
+                message: "该试卷只能答题" + section.answerNum + "次",
+              });
+
+              return;
+            }
+            this.studyLog(
+              (section.moduleId = 0),
+              (section.chapterId = 0),
+              section.typeId,
+              courseLists
+            );
+          } else {
+            this.$message({
+              type: "warning",
+              message: "请按顺序学完视频课程再进行练习和测试",
+            });
+          }
+        } else if (
+          this.businessData.goodsLearningOrder == 2 &&
+          !section.rebuild
+        ) {
+          let rows = await this.studyRecordMenuAllList(courseLists);
+          let isStop = false;
+          let newRows = [];
+          for (let i = 0; i < rows.length; i++) {
+            let moduleTrue = rows[i].moduleId == section.moduleId;
+            let chapterTrue = rows[i].chapterId == section.chapterId;
+            if (moduleTrue && chapterTrue) {
+              isStop = true;
+              if (rows[i].sectionType != 2) {
+                //忽略直播
+                newRows.push(rows[i]);
+              }
+            } else {
+              if (!isStop) {
+                if (rows[i].sectionType != 2) {
+                  //忽略直播
+                  newRows.push(rows[i]);
+                }
+              } else {
+                break;
+              }
+            }
+          }
+          console.log(newRows);
+          let isAllLearn = newRows.every((item) => {
+            return item.studyStatus == 1;
+          });
+
+          if (isAllLearn) {
+            //之前的都学完了
+
+            // if(canLearn) { //视频的上一节学完
+
+            let num = await this.bankRecordDoNum(courseLists, section);
+            //有次数限制
+            if (section.answerNum - num > 0 && section.answerNum > 0) {
+              console.log(this.list[index]);
+              this.$router.push({
+                path: "/course-exam/" + this.goodsData.goodsId,
+                query: {
+                  courseId: courseLists.courseId,
+                  gradeId: this.goodsData.gradeId,
+                  moduleId: section.moduleId || 0,
+                  examId: section.typeId,
+                  chapterId: section.chapterId || 0,
+                  orderGoodsId: this.goodsData.orderGoodsId,
+                },
+              });
+              //没有答题次数限制
+            } else if (section.answerNum == 0) {
+              this.$router.push({
+                path: "/course-exam/" + this.goodsData.goodsId,
+                query: {
+                  courseId: courseLists.courseId,
+                  gradeId: this.goodsData.gradeId,
+                  moduleId: section.moduleId || 0,
+                  examId: section.typeId,
+                  chapterId: section.chapterId || 0,
+                  orderGoodsId: this.goodsData.orderGoodsId,
+                },
+              });
+            } else {
+              this.$message({
+                type: "warning",
+                message: "该试卷只能答题" + section.answerNum + "次",
+              });
+
+              return;
+            }
+            this.studyLog(
+              (section.moduleId = 0),
+              (section.chapterId = 0),
+              section.typeId,
+              courseLists
+            );
+          } else {
+            this.$message({
+              type: "warning",
+              message: "请学完视频课程再进行练习和测试",
+            });
+          }
+        } else {
+          let num = await this.bankRecordDoNum(courseLists, section);
+          //有次数限制
+          if (section.answerNum - section.doNum > 0 && section.answerNum > 0) {
+            // this.$set(this.list[index],'doNum',(item.doNum+1))
+            this.$router.push({
+              path: "/course-exam/" + this.goodsData.goodsId,
+              query: {
+                courseId: courseLists.courseId,
+                gradeId: this.goodsData.gradeId,
+                moduleId: section.moduleId || 0,
+                examId: section.typeId,
+                chapterId: section.chapterId || 0,
+                orderGoodsId: this.goodsData.orderGoodsId,
+              },
+            });
+
+            //没有答题次数限制
+          } else if (section.answerNum == 0) {
+            this.$router.push({
+              path: "/course-exam/" + this.goodsData.goodsId,
+              query: {
+                courseId: courseLists.courseId,
+                gradeId: this.goodsData.gradeId,
+                moduleId: section.moduleId || 0,
+                examId: section.typeId,
+                chapterId: section.chapterId || 0,
+                orderGoodsId: this.goodsData.orderGoodsId,
+              },
+            });
+          } else {
+            this.$message({
+              type: "warning",
+              message: "该试卷只能答题" + section.answerNum + "次",
+            });
+
+            return;
+          }
+          this.studyLog(
+            (section.moduleId = 0),
+            (section.chapterId = 0),
+            section.typeId,
+            courseLists
+          );
+        }
+        return;
+      }
+    },
+
+    // 新增用户视频学习日志
+    studyLog(moduleId, chapterId, sectionId, courseLists) {
+      this.$axios({
+        url: "/user/study/log",
+        method: "post",
+        data: {
+          goodsId: this.goodsData.goodsId,
+          courseId: courseLists.courseId,
+          moduleId: moduleId || 0,
+          chapterId: chapterId || 0,
+          sectionId: sectionId || 0,
+          fromPlat: 2, //来源平台 1小程序 2PC网站
+          goodsType: 1, // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
+          orderGoodsId: this.goodsData.orderGoodsId,
+        },
+      }).then((res) => {
+        console.log("直播的用户学习日志:", res);
+      });
+    },
+    /**
+     * 获取培训项目详情
+     */
+    courseBusiness() {
+      this.$request.courseBusiness(this.goodsData.businessId).then((res) => {
+        this.businessData = res.data;
+      });
+    },
+    bankRecordDoNum(courseLists, section) {
+      return new Promise((resolve) => {
+        this.$request
+          .bankRecordDoNum({
+            goodsId: this.goodsData.goodsId,
+            gradeId: this.goodsData.gradeId,
+            chapterId: section.chapterId,
+            courseId: courseLists.courseId,
+            moduleId: 0,
+            examId: section.typeId,
+          })
+          .then((res) => {
+            resolve(res.data);
+          });
+      });
+    },
+
+    studyRecordMenuAllList(courseLists) {
+      return new Promise((resolve) => {
+        this.$request
+          .studyRecordMenuAllList({
+            courseId: courseLists.courseId,
+            gradeId: this.goodsData.gradeId,
+            goodsId: this.goodsData.goodsId,
+          })
+          .then((res) => {
+            resolve(res.data);
+          });
+      });
+    },
     gradeCheckGoodsStudy(courseItem, option) {
       return new Promise((resolve) => {
         this.$request