courseChapter.vue 21 KB

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