courseChapter.vue 21 KB

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