courseChapter.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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="refreshList($event)"
  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 { mapGetters, 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. examList: {},
  133. canLearn: false, //是否全部视频看完才可以练习、测试
  134. sectionExam: [],
  135. };
  136. },
  137. methods: {
  138. ...mapMutations(["updateChapterOpen"]),
  139. // 调用节的方法
  140. // togoBack(value) {
  141. // this.$refs.ChapterSection[0].ChapterExam()
  142. // },
  143. goodsTodayStudySectionNum() {
  144. return new Promise((resolve) => {
  145. this.$api
  146. .goodsTodayStudySectionNum({
  147. goodsId: this.goodsId,
  148. gradeId: this.gradeId,
  149. orderGoodsId: this.orderGoodsId,
  150. })
  151. .then((res) => {
  152. if (res.data.code == 200) {
  153. resolve(res.data.data);
  154. }
  155. });
  156. });
  157. },
  158. async refreshList(isRebuild) {
  159. // console.log('节的播放结束');
  160. let moduleId = this.menuItem.moduleId ? this.menuItem.moduleId : 0;
  161. if (this.isRebuild) {
  162. this.getReSectionList(
  163. this.menuItem.id,
  164. this.menuItem.courseId,
  165. moduleId
  166. );
  167. } else {
  168. // console.log('重新请求');
  169. this.getBuySectionList(
  170. this.menuItem.id,
  171. this.menuItem.courseId,
  172. moduleId
  173. );
  174. // this.getMenuExamList(item.id,item.courseId,moduleId)
  175. }
  176. this.$emit("playEnd", { isRebuild: isRebuild.isRebuild });
  177. // this.newMenuAllList = await this.studyRecordMenuAllList()
  178. // console.log('播放器节:', this.newMenuAllList);
  179. },
  180. findNextSection(index) {
  181. for (let i = index + 1; i < this.list.length; i++) {
  182. return this.list[i];
  183. }
  184. return {};
  185. },
  186. // /study/record/menuAllList - 查询课程所有子目录结构列表
  187. studyRecordMenuAllList() {
  188. return new Promise((resolve) => {
  189. this.$api
  190. .studyRecordMenuAllList({
  191. courseId: this.courseId,
  192. gradeId: this.gradeId,
  193. goodsId: this.goodsId,
  194. orderGoodsId: this.orderGoodsId,
  195. })
  196. .then((res) => {
  197. if (res.data.code == 200) {
  198. resolve(res.data.data);
  199. }
  200. });
  201. });
  202. },
  203. gradeCheckGoodsStudy(id) {
  204. return new Promise((resolve) => {
  205. this.$api
  206. .gradeCheckGoodsStudy({
  207. goodsId: this.goodsId,
  208. gradeId: this.gradeId,
  209. moduleId: this.menuItem.moduleId || 0,
  210. chapterId: this.menuItem.chapterId || 0,
  211. examId: id,
  212. orderGoodsId: this.orderGoodsId,
  213. })
  214. .then((res) => {
  215. resolve(res.data.data);
  216. });
  217. });
  218. },
  219. // 新增用户视频学习日志
  220. studyLog() {
  221. this.$http({
  222. url: "/user/study/log",
  223. method: "post",
  224. data: {
  225. goodsId: this.goodsId,
  226. courseId: this.courseId,
  227. moduleId: this.menuItem.moduleId || 0,
  228. chapterId: this.menuItem.chapterId || 0,
  229. sectionId: this.menuItem.sectionId || this.menuItem.menuId,
  230. fromPlat: 1, //来源平台 1小程序 2PC网站
  231. goodsType: this.goodsType, // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  232. orderGoodsId: this.orderGoodsId,
  233. },
  234. }).then((res) => {
  235. console.log("考试的用户学习日志:", res);
  236. });
  237. },
  238. /**
  239. * 去做题
  240. */
  241. async toDo(id, goodsId = 0, moduleId = 0, chapterId = 0, item, index) {
  242. if (item.doType === 2 && item.learning == 1) {
  243. return;
  244. }
  245. // 查询用户商品今天学习节数- /goods/todayStudySectionNum
  246. let learnNum = await this.goodsTodayStudySectionNum();
  247. // 检查用户是否学习过节 - /grade/grade/checkGoodsStudy
  248. let hasLearn = await this.gradeCheckGoodsStudy(id);
  249. if (this.sectionMaxNum > 0) {
  250. if (learnNum >= this.sectionMaxNum && !hasLearn) {
  251. uni.showToast({
  252. icon: "none",
  253. title: `每天最多学习${this.sectionMaxNum}节`,
  254. });
  255. return;
  256. }
  257. }
  258. if (this.params.orderNum == 1) {
  259. if (this.canLearn) {
  260. let num = await this.bankRecordDoNum(item.typeId);
  261. //有次数限制
  262. if (item.answerNum - num > 0 && item.answerNum > 0) {
  263. // this.$set(this.list[index],'doNum',(item.doNum+1))
  264. // console.log(this.list[index]);
  265. uni.navigateTo({
  266. url:
  267. "/pages2/class/questionBank?courseId=" +
  268. this.courseId +
  269. "&gradeId=" +
  270. this.gradeId +
  271. "&isFromVideo=1&id=" +
  272. id +
  273. "&goodsid=" +
  274. goodsId +
  275. "&moduleId=" +
  276. moduleId +
  277. "&chapterId=" +
  278. chapterId +
  279. "&orderGoodsId=" +
  280. this.orderGoodsId +
  281. "&type=1" +
  282. "&learning=" +
  283. item.learning +
  284. "&isBackVideo=" +
  285. 1,
  286. });
  287. this.studyLog();
  288. //没有答题次数限制
  289. } else if (item.answerNum == 0) {
  290. uni.navigateTo({
  291. url:
  292. "/pages2/class/questionBank?courseId=" +
  293. this.courseId +
  294. "&gradeId=" +
  295. this.gradeId +
  296. "&isFromVideo=1&id=" +
  297. id +
  298. "&goodsid=" +
  299. goodsId +
  300. "&moduleId=" +
  301. moduleId +
  302. "&chapterId=" +
  303. chapterId +
  304. "&orderGoodsId=" +
  305. this.orderGoodsId +
  306. "&type=1" +
  307. "&learning=" +
  308. item.learning +
  309. "&isBackVideo=" +
  310. 1,
  311. });
  312. this.studyLog();
  313. } else {
  314. uni.showToast({
  315. icon: "none",
  316. title: "该试卷只能答题" + item.answerNum + "次",
  317. });
  318. return;
  319. }
  320. } else {
  321. uni.showToast({
  322. icon: "none",
  323. title: "请按顺序学完视频课程再进行练习和测试",
  324. });
  325. }
  326. } else if (this.params.orderNum == 2) {
  327. // !item.rebuild
  328. let rows = this.menuAllList;
  329. const index = this.menuAllList.findIndex((e) => {
  330. let i_sectionId = e.sectionId || 0;
  331. let i_chapterId = e.chapterId || 0;
  332. let i_moduleId = e.moduleId || 0;
  333. return (
  334. i_sectionId == item.sectionId &&
  335. i_chapterId == item.chapterId &&
  336. i_moduleId == item.moduleId
  337. );
  338. });
  339. let isStop = false;
  340. let newRows = [];
  341. for (let i = 0; i < index; i++) {
  342. let moduleTrue = rows[i].moduleId == moduleId;
  343. let chapterTrue = rows[i].chapterId == chapterId;
  344. if (moduleTrue && chapterTrue) {
  345. isStop = true;
  346. if (rows[i].sectionType != 2) {
  347. //忽略直播
  348. newRows.push(rows[i]);
  349. }
  350. } else {
  351. if (!isStop) {
  352. if (rows[i].sectionType != 2) {
  353. //忽略直播
  354. newRows.push(rows[i]);
  355. }
  356. } else {
  357. break;
  358. }
  359. }
  360. }
  361. let isAllLearn = newRows.every((item) => {
  362. return item.studyStatus == 1;
  363. });
  364. if (isAllLearn) {
  365. //之前的都学完了
  366. // if(canLearn) { //视频的上一节学完
  367. let num = await this.bankRecordDoNum(item.typeId);
  368. //有次数限制
  369. if (item.answerNum - num > 0 && item.answerNum > 0) {
  370. // this.$set(this.list[index],'doNum',(item.doNum+1))
  371. // console.log(this.list[index]);
  372. uni.navigateTo({
  373. url:
  374. "/pages2/class/questionBank?courseId=" +
  375. this.courseId +
  376. "&gradeId=" +
  377. this.gradeId +
  378. "&isFromVideo=1&id=" +
  379. id +
  380. "&goodsid=" +
  381. goodsId +
  382. "&moduleId=" +
  383. moduleId +
  384. "&chapterId=" +
  385. chapterId +
  386. "&orderGoodsId=" +
  387. this.orderGoodsId +
  388. "&type=1" +
  389. "&learning=" +
  390. item.learning +
  391. "&isBackVideo=" +
  392. 1,
  393. });
  394. this.studyLog();
  395. //没有答题次数限制
  396. } else if (item.answerNum == 0) {
  397. uni.navigateTo({
  398. url:
  399. "/pages2/class/questionBank?courseId=" +
  400. this.courseId +
  401. "&gradeId=" +
  402. this.gradeId +
  403. "&isFromVideo=1&id=" +
  404. id +
  405. "&goodsid=" +
  406. goodsId +
  407. "&moduleId=" +
  408. moduleId +
  409. "&chapterId=" +
  410. chapterId +
  411. "&orderGoodsId=" +
  412. this.orderGoodsId +
  413. "&type=1" +
  414. "&learning=" +
  415. item.learning +
  416. "&isBackVideo=" +
  417. 1,
  418. });
  419. this.studyLog();
  420. } else {
  421. uni.showToast({
  422. icon: "none",
  423. title: "该试卷只能答题" + item.answerNum + "次",
  424. });
  425. return;
  426. }
  427. } else {
  428. uni.showToast({
  429. icon: "none",
  430. title: "请学完视频课程再进行练习和测试",
  431. });
  432. }
  433. } else {
  434. let num = await this.bankRecordDoNum(item.typeId);
  435. //有次数限制
  436. if (item.answerNum - item.doNum > 0 && item.answerNum > 0) {
  437. // this.$set(this.list[index],'doNum',(item.doNum+1))
  438. // console.log(this.list[index]);
  439. uni.navigateTo({
  440. url:
  441. "/pages2/class/questionBank?courseId=" +
  442. this.courseId +
  443. "&gradeId=" +
  444. this.gradeId +
  445. "&isFromVideo=1&id=" +
  446. id +
  447. "&goodsid=" +
  448. goodsId +
  449. "&moduleId=" +
  450. moduleId +
  451. "&chapterId=" +
  452. chapterId +
  453. "&orderGoodsId=" +
  454. this.orderGoodsId +
  455. "&type=1" +
  456. "&learning=" +
  457. item.learning +
  458. "&isBackVideo=" +
  459. 1,
  460. });
  461. this.studyLog();
  462. //没有答题次数限制
  463. } else if (item.answerNum == 0) {
  464. uni.navigateTo({
  465. url:
  466. "/pages2/class/questionBank?courseId=" +
  467. this.courseId +
  468. "&gradeId=" +
  469. this.gradeId +
  470. "&isFromVideo=1&id=" +
  471. id +
  472. "&goodsid=" +
  473. goodsId +
  474. "&moduleId=" +
  475. moduleId +
  476. "&chapterId=" +
  477. chapterId +
  478. "&orderGoodsId=" +
  479. this.orderGoodsId +
  480. "&type=1" +
  481. "&learning=" +
  482. item.learning +
  483. "&isBackVideo=" +
  484. 1,
  485. });
  486. this.studyLog();
  487. } else {
  488. uni.showToast({
  489. icon: "none",
  490. title: "该试卷只能答题" + item.answerNum + "次",
  491. });
  492. return;
  493. }
  494. }
  495. },
  496. bankRecordDoNum(examId) {
  497. return new Promise((resolve) => {
  498. this.$api
  499. .bankRecordDoNum({
  500. goodsId: this.goodsId,
  501. gradeId: this.gradeId,
  502. chapterId: this.menuItem.id,
  503. courseId: this.courseId,
  504. moduleId: 0,
  505. examId: examId,
  506. orderGoodsId: this.orderGoodsId,
  507. })
  508. .then((res) => {
  509. resolve(res.data.data);
  510. });
  511. });
  512. },
  513. async openChapter(item) {
  514. this.down = !this.down;
  515. if (!this.down && this.list.length == 0) {
  516. //获取章下面所有节试卷列表-course/sectionExamList
  517. this.$method.isLogin() &&
  518. (await this.$api
  519. .reSectionExamList({
  520. chapterId: item.chapterId || item.menuId,
  521. courseId: item.courseId,
  522. gradeId: item.gradeId,
  523. orderGoodsId: this.orderGoodsId,
  524. })
  525. .then((res) => {
  526. if (res.data.code == 200) {
  527. this.sectionExam = res.data.data || [];
  528. }
  529. }));
  530. this.getSectionList();
  531. }
  532. },
  533. getMenuExamList(chapterId, courseId, moduleId) {
  534. let self = this;
  535. this.$api
  536. .menuExamList({
  537. chapterId: chapterId,
  538. courseId: courseId,
  539. moduleId: moduleId,
  540. })
  541. .then((res) => {
  542. if (res.data.code == 200) {
  543. self.examList = res.data.rows;
  544. }
  545. });
  546. },
  547. getSectionList() {
  548. const fn = this.isBuy ? "reSectionList" : "sectionList";
  549. let chapterId = this.menuItem.chapterId || this.menuItem.menuId;
  550. this.$api[fn](
  551. this.isBuy
  552. ? {
  553. chapterId,
  554. gradeId: this.gradeId,
  555. courseId: this.courseId,
  556. moduleId: this.menuItem.moduleId || 0,
  557. orderGoodsId: this.orderGoodsId,
  558. rebuild: +this.isRebuild,
  559. }
  560. : chapterId
  561. ).then((res) => {
  562. if (res.data.code == 200) {
  563. for (let i = 0; i < res.data.data.length; i++) {
  564. let item = res.data.data[i];
  565. item.courseId = this.courseId;
  566. item.id = item.sectionId;
  567. item.menuType = 3;
  568. }
  569. let newArr = res.data.data.filter((item) => {
  570. return item.type != 2;
  571. });
  572. this.canLearn = newArr.every((item) => item.learning == 1);
  573. this.list = res.data.data;
  574. }
  575. });
  576. },
  577. },
  578. computed: {
  579. ...mapGetters(["goodsAuditionConfigIdList"]),
  580. learnStatus() {
  581. if (!this.isBuy || !this.sectionItem) {
  582. return;
  583. }
  584. let { id, courseId, moduleId } = this.menuItem;
  585. if (
  586. this.sectionItem.courseId == courseId &&
  587. this.sectionItem.moduleId == (moduleId || 0) &&
  588. this.sectionItem.chapterId == id
  589. ) {
  590. return 0;
  591. }
  592. const list = this.menuAllList.filter(
  593. (e) =>
  594. e.courseId == courseId &&
  595. e.moduleId == (moduleId || 0) &&
  596. e.chapterId == id
  597. );
  598. const isAllLearn = list.every((item) => {
  599. return item.studyStatus == 1;
  600. });
  601. return isAllLearn ? 1 : -1;
  602. },
  603. params() {
  604. return this.paramsFn([
  605. "orderGoodsId",
  606. "gradeId",
  607. "courseId",
  608. "sectionItem",
  609. "menuAllList",
  610. "orderNum",
  611. "goodsId",
  612. ]);
  613. },
  614. courseId() {
  615. return this.params.courseId;
  616. },
  617. gradeId() {
  618. return this.params.gradeId;
  619. },
  620. orderGoodsId() {
  621. return this.params.orderGoodsId;
  622. },
  623. sectionItem() {
  624. return this.params.sectionItem;
  625. },
  626. menuAllList() {
  627. return this.params.menuAllList;
  628. },
  629. goodsId() {
  630. return this.params.goodsId;
  631. },
  632. },
  633. watch: {
  634. courseId: {
  635. handler(val) {
  636. if (this.needOpen) {
  637. this.down = true;
  638. this.list = [];
  639. this.updateChapterOpen(false);
  640. this.openChapter(this.menuItem);
  641. }
  642. },
  643. immediate: true,
  644. },
  645. },
  646. };
  647. </script>
  648. <style lang="scss" scoped>
  649. .tagRe {
  650. // width: 80rpx;
  651. line-height: 28rpx;
  652. padding: 0 8rpx;
  653. height: 28rpx;
  654. background: #ff3b30;
  655. border-radius: 8rpx;
  656. font-size: 20rpx;
  657. color: #ffffff;
  658. text-align: center;
  659. }
  660. .tagGreen {
  661. width: 80rpx;
  662. height: 28rpx;
  663. background: #34c759;
  664. border-radius: 8rpx;
  665. font-size: 20rpx;
  666. color: #ffffff;
  667. text-align: center;
  668. }
  669. .eTag {
  670. width: 64rpx;
  671. height: 36rpx;
  672. text-align: center;
  673. line-height: 36rpx;
  674. font-size: 20rpx;
  675. background: #007aff;
  676. border-radius: 8rpx;
  677. color: #ffffff;
  678. }
  679. .examBox {
  680. display: flex;
  681. align-items: center;
  682. justify-content: space-between;
  683. }
  684. .exam {
  685. font-size: 30rpx;
  686. display: flex;
  687. align-items: center;
  688. margin: 20rpx 0;
  689. }
  690. .icon_up {
  691. width: 24rpx;
  692. height: 24rpx;
  693. }
  694. .title {
  695. // margin-bottom: 30rpx;
  696. height: 78rpx;
  697. display: flex;
  698. justify-content: space-between;
  699. align-items: center;
  700. border-bottom: 1rpx solid #eeeeee;
  701. .menu_name {
  702. font-size: 24rpx;
  703. font-family: PingFang SC;
  704. font-weight: bold;
  705. color: #333;
  706. white-space: nowrap;
  707. overflow: hidden;
  708. text-overflow: ellipsis;
  709. margin-left: 8rpx;
  710. }
  711. .title_status {
  712. padding: 2rpx 8rpx;
  713. border-radius: 8rpx;
  714. font-size: 20rpx;
  715. color: #ffffff;
  716. text-align: center;
  717. margin-left: 4rpx;
  718. }
  719. .gre {
  720. background: #34c759;
  721. }
  722. .blue {
  723. background: #409eff;
  724. }
  725. .grey {
  726. background: #909399;
  727. }
  728. }
  729. </style>