courseChapter.vue 18 KB

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