courseChapter.vue 18 KB

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