courseChapter.vue 20 KB

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