courseChapter.vue 21 KB

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