courseChapter.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <template>
  2. <view>
  3. <view class="title" @click="openChapter(menuItem)">
  4. <view>
  5. <u-icon name="arrow-down" color="#999" size="24" v-if="!down"></u-icon>
  6. <u-icon name="arrow-right" color="#999" size="24" v-if="down"></u-icon>
  7. <text class="menu_name">{{ menuItem.name }}</text>
  8. </view>
  9. <view class="fl">
  10. <view class="title_status gre" v-if="menuItem.commonSign == 1"
  11. >公共章</view
  12. >
  13. <view
  14. class="title_status"
  15. :class="['grey', 'blue', 'gre'][learnStatus + 1]"
  16. >
  17. {{ ["待学习", "学习中", "已学完"][learnStatus + 1] }}
  18. </view>
  19. </view>
  20. </view>
  21. <view v-show="!down">
  22. <view v-for="(itemM, indexM) in list" :key="indexM">
  23. <view v-if="itemM.type != 2">
  24. <courseSection
  25. ref="ChapterSection"
  26. :isLive="isLive"
  27. :sectionMaxNum="sectionMaxNum"
  28. :preItem="list[indexM - 1] || preItem"
  29. @playEnd="getSectionList"
  30. :isBuy="isBuy"
  31. :nextMenuItem="findNextSection(indexM)"
  32. :isRebuild="isRebuild"
  33. :menuItem="itemM"
  34. :levelId="levelId + '-' + itemM.sectionId"
  35. :testType="2"
  36. :ChapterSectionExam="sectionExam"
  37. ></courseSection>
  38. <!-- @togoBack='togoBack()' -->
  39. <u-line v-if="indexM < list.length - 1"></u-line>
  40. </view>
  41. <!-- 章卷 -->
  42. <view v-if="itemM.type == 2">
  43. <u-line></u-line>
  44. <view
  45. class="examBox"
  46. @click="
  47. toDo(
  48. itemM.typeId,
  49. goodsId,
  50. itemM.moduleId,
  51. itemM.chapterId,
  52. itemM,
  53. indexM
  54. )
  55. "
  56. >
  57. <view class="exam">
  58. <view class="eTag">
  59. {{ itemM.doType == 1 ? "练习" : "考试" }}
  60. </view>
  61. <view style="margin-left: 15rpx; flex: 1">{{ itemM.name }}</view>
  62. </view>
  63. <view v-if="isRebuild || itemM.rebuild > 0" class="tagRe"
  64. >待重修</view
  65. >
  66. <view v-else>
  67. <view
  68. :class="{
  69. tagGreen: itemM.learning == 1,
  70. tagRe: itemM.learning == 0 || itemM.rebuild > 0,
  71. }"
  72. >
  73. <text v-if="itemM.rebuild > 0">待重测</text>
  74. <text v-else-if="itemM.learning == 1">合格</text>
  75. <text v-else-if="itemM.learning == 0">不及格(需重考)</text>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. import { mapMutations } from "vuex";
  86. import courseSection from "@/components/course/courseSection.vue";
  87. export default {
  88. name: "courseChapter",
  89. inject: ["paramsFn"],
  90. props: {
  91. isLive: false,
  92. preItem: {
  93. default: undefined,
  94. },
  95. needOpen: {
  96. //是否默认展开
  97. type: Boolean,
  98. default: false,
  99. },
  100. menuItem: {
  101. type: Object,
  102. default: {},
  103. },
  104. isBuy: {
  105. type: Boolean,
  106. default: false,
  107. },
  108. levelId: {
  109. type: String,
  110. default: "",
  111. },
  112. isRebuild: {
  113. type: Boolean,
  114. default: false,
  115. },
  116. sectionMaxNum: {
  117. default: undefined,
  118. },
  119. // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  120. goodsType: {
  121. type: [Number, String],
  122. default: 0,
  123. },
  124. },
  125. components: {
  126. courseSection,
  127. },
  128. data() {
  129. return {
  130. down: true,
  131. list: [],
  132. canLearn: false, //是否全部视频看完才可以练习、测试
  133. sectionExam: [],
  134. };
  135. },
  136. methods: {
  137. ...mapMutations(["updateChapterOpen"]),
  138. // 调用节的方法
  139. // togoBack(value) {
  140. // this.$refs.ChapterSection[0].ChapterExam()
  141. // },
  142. goodsTodayStudySectionNum() {
  143. return new Promise((resolve) => {
  144. this.$api
  145. .goodsTodayStudySectionNum({
  146. goodsId: this.goodsId,
  147. gradeId: this.gradeId,
  148. orderGoodsId: this.orderGoodsId,
  149. })
  150. .then((res) => {
  151. if (res.data.code == 200) {
  152. resolve(res.data.data);
  153. }
  154. });
  155. });
  156. },
  157. findNextSection(index) {
  158. for (let i = index + 1; i < this.list.length; i++) {
  159. return this.list[i];
  160. }
  161. return {};
  162. },
  163. gradeCheckGoodsStudy(id) {
  164. return new Promise((resolve) => {
  165. this.$api
  166. .gradeCheckGoodsStudy({
  167. goodsId: this.goodsId,
  168. gradeId: this.gradeId,
  169. moduleId: this.menuItem.moduleId || 0,
  170. chapterId: this.menuItem.chapterId || 0,
  171. examId: id,
  172. orderGoodsId: this.orderGoodsId,
  173. })
  174. .then((res) => {
  175. resolve(res.data.data);
  176. });
  177. });
  178. },
  179. // 新增用户视频学习日志
  180. studyLog() {
  181. this.$http({
  182. url: "/user/study/log",
  183. method: "post",
  184. data: {
  185. goodsId: this.goodsId,
  186. courseId: this.courseId,
  187. moduleId: this.menuItem.moduleId || 0,
  188. chapterId: this.menuItem.chapterId || 0,
  189. sectionId: this.menuItem.sectionId || this.menuItem.menuId,
  190. fromPlat: 1, //来源平台 1小程序 2PC网站
  191. goodsType: this.goodsType, // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  192. orderGoodsId: this.orderGoodsId,
  193. },
  194. }).then((res) => {
  195. console.log("考试的用户学习日志:", res);
  196. });
  197. },
  198. /**
  199. * 去做题
  200. */
  201. async toDo(id, goodsId = 0, moduleId = 0, chapterId = 0, item, index) {
  202. if (item.doType === 2 && item.learning == 1) {
  203. return;
  204. }
  205. // 查询用户商品今天学习节数- /goods/todayStudySectionNum
  206. let learnNum = await this.goodsTodayStudySectionNum();
  207. // 检查用户是否学习过节 - /grade/grade/checkGoodsStudy
  208. let hasLearn = await this.gradeCheckGoodsStudy(id);
  209. if (this.sectionMaxNum > 0) {
  210. if (learnNum >= this.sectionMaxNum && !hasLearn) {
  211. uni.showToast({
  212. icon: "none",
  213. title: `每天最多学习${this.sectionMaxNum}节`,
  214. });
  215. return;
  216. }
  217. }
  218. if (this.params.orderNum == 1) {
  219. if (this.canLearn) {
  220. let num = await this.bankRecordDoNum(item.typeId);
  221. //有次数限制
  222. if (item.answerNum - num > 0 && item.answerNum > 0) {
  223. // this.$set(this.list[index],'doNum',(item.doNum+1))
  224. // console.log(this.list[index]);
  225. uni.navigateTo({
  226. url:
  227. "/pages2/class/questionBank?courseId=" +
  228. this.courseId +
  229. "&gradeId=" +
  230. this.gradeId +
  231. "&isFromVideo=1&id=" +
  232. id +
  233. "&goodsid=" +
  234. goodsId +
  235. "&moduleId=" +
  236. moduleId +
  237. "&chapterId=" +
  238. chapterId +
  239. "&orderGoodsId=" +
  240. this.orderGoodsId +
  241. "&type=1" +
  242. "&learning=" +
  243. item.learning +
  244. "&isBackVideo=" +
  245. 1,
  246. });
  247. this.studyLog();
  248. //没有答题次数限制
  249. } else if (item.answerNum == 0) {
  250. uni.navigateTo({
  251. url:
  252. "/pages2/class/questionBank?courseId=" +
  253. this.courseId +
  254. "&gradeId=" +
  255. this.gradeId +
  256. "&isFromVideo=1&id=" +
  257. id +
  258. "&goodsid=" +
  259. goodsId +
  260. "&moduleId=" +
  261. moduleId +
  262. "&chapterId=" +
  263. chapterId +
  264. "&orderGoodsId=" +
  265. this.orderGoodsId +
  266. "&type=1" +
  267. "&learning=" +
  268. item.learning +
  269. "&isBackVideo=" +
  270. 1,
  271. });
  272. this.studyLog();
  273. } else {
  274. uni.showToast({
  275. icon: "none",
  276. title: "该试卷只能答题" + item.answerNum + "次",
  277. });
  278. return;
  279. }
  280. } else {
  281. uni.showToast({
  282. icon: "none",
  283. title: "请按顺序学完视频课程再进行练习和测试",
  284. });
  285. }
  286. } else if (this.params.orderNum == 2) {
  287. // !item.rebuild
  288. let rows = this.menuAllList;
  289. const index = this.menuAllList.findIndex((e) => {
  290. let i_sectionId = e.sectionId || 0;
  291. let i_chapterId = e.chapterId || 0;
  292. let i_moduleId = e.moduleId || 0;
  293. return (
  294. i_sectionId == item.sectionId &&
  295. i_chapterId == item.chapterId &&
  296. i_moduleId == item.moduleId
  297. );
  298. });
  299. let isStop = false;
  300. let newRows = [];
  301. for (let i = 0; i < index; i++) {
  302. let moduleTrue = rows[i].moduleId == moduleId;
  303. let chapterTrue = rows[i].chapterId == chapterId;
  304. if (moduleTrue && chapterTrue) {
  305. isStop = true;
  306. if (rows[i].sectionType != 2) {
  307. //忽略直播
  308. newRows.push(rows[i]);
  309. }
  310. } else {
  311. if (!isStop) {
  312. if (rows[i].sectionType != 2) {
  313. //忽略直播
  314. newRows.push(rows[i]);
  315. }
  316. } else {
  317. break;
  318. }
  319. }
  320. }
  321. let isAllLearn = newRows.every((item) => {
  322. return item.studyStatus == 1;
  323. });
  324. if (isAllLearn) {
  325. //之前的都学完了
  326. // if(canLearn) { //视频的上一节学完
  327. let num = await this.bankRecordDoNum(item.typeId);
  328. //有次数限制
  329. if (item.answerNum - num > 0 && item.answerNum > 0) {
  330. // this.$set(this.list[index],'doNum',(item.doNum+1))
  331. // console.log(this.list[index]);
  332. uni.navigateTo({
  333. url:
  334. "/pages2/class/questionBank?courseId=" +
  335. this.courseId +
  336. "&gradeId=" +
  337. this.gradeId +
  338. "&isFromVideo=1&id=" +
  339. id +
  340. "&goodsid=" +
  341. goodsId +
  342. "&moduleId=" +
  343. moduleId +
  344. "&chapterId=" +
  345. chapterId +
  346. "&orderGoodsId=" +
  347. this.orderGoodsId +
  348. "&type=1" +
  349. "&learning=" +
  350. item.learning +
  351. "&isBackVideo=" +
  352. 1,
  353. });
  354. this.studyLog();
  355. //没有答题次数限制
  356. } else if (item.answerNum == 0) {
  357. uni.navigateTo({
  358. url:
  359. "/pages2/class/questionBank?courseId=" +
  360. this.courseId +
  361. "&gradeId=" +
  362. this.gradeId +
  363. "&isFromVideo=1&id=" +
  364. id +
  365. "&goodsid=" +
  366. goodsId +
  367. "&moduleId=" +
  368. moduleId +
  369. "&chapterId=" +
  370. chapterId +
  371. "&orderGoodsId=" +
  372. this.orderGoodsId +
  373. "&type=1" +
  374. "&learning=" +
  375. item.learning +
  376. "&isBackVideo=" +
  377. 1,
  378. });
  379. this.studyLog();
  380. } else {
  381. uni.showToast({
  382. icon: "none",
  383. title: "该试卷只能答题" + item.answerNum + "次",
  384. });
  385. return;
  386. }
  387. } else {
  388. uni.showToast({
  389. icon: "none",
  390. title: "请学完视频课程再进行练习和测试",
  391. });
  392. }
  393. } else {
  394. let num = await this.bankRecordDoNum(item.typeId);
  395. //有次数限制
  396. if (item.answerNum - item.doNum > 0 && item.answerNum > 0) {
  397. // this.$set(this.list[index],'doNum',(item.doNum+1))
  398. // console.log(this.list[index]);
  399. uni.navigateTo({
  400. url:
  401. "/pages2/class/questionBank?courseId=" +
  402. this.courseId +
  403. "&gradeId=" +
  404. this.gradeId +
  405. "&isFromVideo=1&id=" +
  406. id +
  407. "&goodsid=" +
  408. goodsId +
  409. "&moduleId=" +
  410. moduleId +
  411. "&chapterId=" +
  412. chapterId +
  413. "&orderGoodsId=" +
  414. this.orderGoodsId +
  415. "&type=1" +
  416. "&learning=" +
  417. item.learning +
  418. "&isBackVideo=" +
  419. 1,
  420. });
  421. this.studyLog();
  422. //没有答题次数限制
  423. } else if (item.answerNum == 0) {
  424. uni.navigateTo({
  425. url:
  426. "/pages2/class/questionBank?courseId=" +
  427. this.courseId +
  428. "&gradeId=" +
  429. this.gradeId +
  430. "&isFromVideo=1&id=" +
  431. id +
  432. "&goodsid=" +
  433. goodsId +
  434. "&moduleId=" +
  435. moduleId +
  436. "&chapterId=" +
  437. chapterId +
  438. "&orderGoodsId=" +
  439. this.orderGoodsId +
  440. "&type=1" +
  441. "&learning=" +
  442. item.learning +
  443. "&isBackVideo=" +
  444. 1,
  445. });
  446. this.studyLog();
  447. } else {
  448. uni.showToast({
  449. icon: "none",
  450. title: "该试卷只能答题" + item.answerNum + "次",
  451. });
  452. return;
  453. }
  454. }
  455. },
  456. bankRecordDoNum(examId) {
  457. return new Promise((resolve) => {
  458. this.$api
  459. .bankRecordDoNum({
  460. goodsId: this.goodsId,
  461. gradeId: this.gradeId,
  462. chapterId: this.menuItem.id,
  463. courseId: this.courseId,
  464. moduleId: 0,
  465. examId: examId,
  466. orderGoodsId: this.orderGoodsId,
  467. })
  468. .then((res) => {
  469. resolve(res.data.data);
  470. });
  471. });
  472. },
  473. async openChapter(item) {
  474. this.down = !this.down;
  475. if (!this.down && this.list.length == 0) {
  476. //获取章下面所有节试卷列表-course/sectionExamList
  477. this.$method.isLogin() &&
  478. (await this.$api
  479. .reSectionExamList({
  480. chapterId: item.chapterId || item.menuId,
  481. courseId: item.courseId,
  482. gradeId: item.gradeId,
  483. orderGoodsId: this.orderGoodsId,
  484. })
  485. .then((res) => {
  486. if (res.data.code == 200) {
  487. this.sectionExam = res.data.data || [];
  488. }
  489. }));
  490. this.getSectionList();
  491. }
  492. },
  493. getSectionList() {
  494. const fn = this.isBuy ? "reSectionList" : "sectionList";
  495. let chapterId = this.menuItem.chapterId || this.menuItem.menuId;
  496. this.$api[fn](
  497. this.isBuy
  498. ? {
  499. chapterId,
  500. gradeId: this.gradeId,
  501. courseId: this.courseId,
  502. moduleId: this.menuItem.moduleId || 0,
  503. orderGoodsId: this.orderGoodsId,
  504. rebuild: +this.isRebuild,
  505. }
  506. : chapterId
  507. ).then((res) => {
  508. if (res.data.code == 200) {
  509. for (let i = 0; i < res.data.data.length; i++) {
  510. let item = res.data.data[i];
  511. item.courseId = this.courseId;
  512. item.id = item.sectionId;
  513. item.menuType = 3;
  514. }
  515. let newArr = res.data.data.filter((item) => {
  516. return item.type != 2;
  517. });
  518. this.canLearn = newArr.every((item) => item.learning == 1);
  519. this.list = res.data.data;
  520. }
  521. });
  522. },
  523. },
  524. computed: {
  525. learnStatus() {
  526. if (!this.isBuy || !this.sectionItem) {
  527. return;
  528. }
  529. let { id, courseId, moduleId } = this.menuItem;
  530. if (
  531. this.sectionItem.courseId == courseId &&
  532. this.sectionItem.moduleId == (moduleId || 0) &&
  533. this.sectionItem.chapterId == id
  534. ) {
  535. return 0;
  536. }
  537. const list = this.menuAllList.filter(
  538. (e) =>
  539. e.courseId == courseId &&
  540. e.moduleId == (moduleId || 0) &&
  541. e.chapterId == id
  542. );
  543. const isAllLearn = list.every((item) => {
  544. return item.studyStatus == 1;
  545. });
  546. return isAllLearn ? 1 : -1;
  547. },
  548. params() {
  549. return this.paramsFn([
  550. "orderGoodsId",
  551. "gradeId",
  552. "courseId",
  553. "sectionItem",
  554. "menuAllList",
  555. "orderNum",
  556. "goodsId",
  557. ]);
  558. },
  559. courseId() {
  560. return this.params.courseId;
  561. },
  562. gradeId() {
  563. return this.params.gradeId;
  564. },
  565. orderGoodsId() {
  566. return this.params.orderGoodsId;
  567. },
  568. sectionItem() {
  569. return this.params.sectionItem;
  570. },
  571. menuAllList() {
  572. return this.params.menuAllList;
  573. },
  574. goodsId() {
  575. return this.params.goodsId;
  576. },
  577. },
  578. watch: {
  579. courseId: {
  580. handler(val) {
  581. if (this.needOpen) {
  582. this.down = true;
  583. this.list = [];
  584. this.updateChapterOpen(false);
  585. this.openChapter(this.menuItem);
  586. }
  587. },
  588. immediate: true,
  589. },
  590. },
  591. };
  592. </script>
  593. <style lang="scss" scoped>
  594. .tagRe {
  595. // width: 80rpx;
  596. line-height: 28rpx;
  597. padding: 0 8rpx;
  598. height: 28rpx;
  599. background: #ff3b30;
  600. border-radius: 8rpx;
  601. font-size: 20rpx;
  602. color: #ffffff;
  603. text-align: center;
  604. }
  605. .tagGreen {
  606. width: 80rpx;
  607. height: 28rpx;
  608. background: #34c759;
  609. border-radius: 8rpx;
  610. font-size: 20rpx;
  611. color: #ffffff;
  612. text-align: center;
  613. }
  614. .eTag {
  615. width: 64rpx;
  616. height: 36rpx;
  617. text-align: center;
  618. line-height: 36rpx;
  619. font-size: 20rpx;
  620. background: #007aff;
  621. border-radius: 8rpx;
  622. color: #ffffff;
  623. }
  624. .examBox {
  625. display: flex;
  626. align-items: center;
  627. justify-content: space-between;
  628. }
  629. .exam {
  630. font-size: 30rpx;
  631. display: flex;
  632. align-items: center;
  633. margin: 20rpx 0;
  634. }
  635. .icon_up {
  636. width: 24rpx;
  637. height: 24rpx;
  638. }
  639. .title {
  640. // margin-bottom: 30rpx;
  641. height: 78rpx;
  642. display: flex;
  643. justify-content: space-between;
  644. align-items: center;
  645. border-bottom: 1rpx solid #eeeeee;
  646. .menu_name {
  647. font-size: 24rpx;
  648. font-family: PingFang SC;
  649. font-weight: bold;
  650. color: #333;
  651. white-space: nowrap;
  652. overflow: hidden;
  653. text-overflow: ellipsis;
  654. margin-left: 8rpx;
  655. }
  656. .title_status {
  657. padding: 2rpx 8rpx;
  658. border-radius: 8rpx;
  659. font-size: 20rpx;
  660. color: #ffffff;
  661. text-align: center;
  662. margin-left: 4rpx;
  663. }
  664. .gre {
  665. background: #34c759;
  666. }
  667. .blue {
  668. background: #409eff;
  669. }
  670. .grey {
  671. background: #909399;
  672. }
  673. }
  674. </style>