courseChapter.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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.gradeCheckGoodsStudy({
  215. goodsId:this.goodsId,
  216. gradeId:this.gradeId,
  217. moduleId:this.menuItem.moduleId || 0,
  218. chapterId:this.menuItem.chapterId || 0,
  219. examId:id,
  220. }).then( res => {
  221. resolve(res.data.data)
  222. })
  223. })
  224. },
  225. /**
  226. * 去做题
  227. */
  228. async toDo(id, goodsId = 0, moduleId = 0, chapterId = 0, item, index) {
  229. let learnNum = await this.goodsTodayStudySectionNum()
  230. let hasLearn = await this.gradeCheckGoodsStudy(id);
  231. if(this.sectionMaxNum > 0) {
  232. if(learnNum >= this.sectionMaxNum && !hasLearn) {
  233. uni.showToast({
  234. icon:'none',
  235. title:`每天最多学习${this.sectionMaxNum}节`
  236. })
  237. return;
  238. }
  239. }
  240. console.log(this.learningOrder, "this.learningOrder");
  241. if (this.learningOrder == 1) {
  242. if (this.canLearn) {
  243. let num = await this.bankRecordDoNum(item.typeId);
  244. //有次数限制
  245. if (item.answerNum - num > 0 && item.answerNum > 0) {
  246. // this.$set(this.list[index],'doNum',(item.doNum+1))
  247. console.log(this.list[index]);
  248. uni.navigateTo({
  249. url:
  250. "/pages2/class/questionBank?courseId=" +
  251. this.courseId +
  252. "&gradeId=" +
  253. this.gradeId +
  254. "&isFromVideo=1&id=" +
  255. id +
  256. "&goodsid=" +
  257. goodsId +
  258. "&moduleId=" +
  259. moduleId +
  260. "&chapterId=" +
  261. chapterId +
  262. "&orderGoodsId=" + this.orderGoodsId,
  263. });
  264. //没有答题次数限制
  265. } else if (item.answerNum == 0) {
  266. uni.navigateTo({
  267. url:
  268. "/pages2/class/questionBank?courseId=" +
  269. this.courseId +
  270. "&gradeId=" +
  271. this.gradeId +
  272. "&isFromVideo=1&id=" +
  273. id +
  274. "&goodsid=" +
  275. goodsId +
  276. "&moduleId=" +
  277. moduleId +
  278. "&chapterId=" +
  279. chapterId +
  280. "&orderGoodsId=" + this.orderGoodsId,
  281. });
  282. } else {
  283. uni.showToast({
  284. icon: "none",
  285. title: "该试卷只能答题" + item.answerNum + "次",
  286. });
  287. return;
  288. }
  289. } else {
  290. uni.showToast({
  291. icon: "none",
  292. title: "请按顺序学完视频课程再进行练习和测试",
  293. });
  294. }
  295. } else if (this.learningOrder == 2 && !item.rebuild) {
  296. let canLearn = this.list[index - 1].learning == 1;
  297. let rows = await this.studyRecordMenuAllList();
  298. let isStop = false;
  299. let newRows = [];
  300. for (let i = 0; i < rows.length; i++) {
  301. let moduleTrue = rows[i].moduleId == moduleId;
  302. let chapterTrue = rows[i].chapterId == chapterId;
  303. if (moduleTrue && chapterTrue) {
  304. isStop = true;
  305. if (rows[i].sectionType != 2) {
  306. //忽略直播
  307. newRows.push(rows[i]);
  308. }
  309. } else {
  310. if (!isStop) {
  311. if (rows[i].sectionType != 2) {
  312. //忽略直播
  313. newRows.push(rows[i]);
  314. }
  315. } else {
  316. break;
  317. }
  318. }
  319. }
  320. console.log(newRows);
  321. let isAllLearn = newRows.every((item) => {
  322. return item.studyStatus == 1;
  323. });
  324. if (isAllLearn) {
  325. //之前的都学完了
  326. // if(canLearn) { //视频的上一节学完
  327. let num = await this.bankRecordDoNum(item.typeId);
  328. //有次数限制
  329. if (item.answerNum - num > 0 && item.answerNum > 0) {
  330. // this.$set(this.list[index],'doNum',(item.doNum+1))
  331. console.log(this.list[index]);
  332. uni.navigateTo({
  333. url:
  334. "/pages2/class/questionBank?courseId=" +
  335. this.courseId +
  336. "&gradeId=" +
  337. this.gradeId +
  338. "&isFromVideo=1&id=" +
  339. id +
  340. "&goodsid=" +
  341. goodsId +
  342. "&moduleId=" +
  343. moduleId +
  344. "&chapterId=" +
  345. chapterId +
  346. "&orderGoodsId=" + this.orderGoodsId,
  347. });
  348. //没有答题次数限制
  349. } else if (item.answerNum == 0) {
  350. uni.navigateTo({
  351. url:
  352. "/pages2/class/questionBank?courseId=" +
  353. this.courseId +
  354. "&gradeId=" +
  355. this.gradeId +
  356. "&isFromVideo=1&id=" +
  357. id +
  358. "&goodsid=" +
  359. goodsId +
  360. "&moduleId=" +
  361. moduleId +
  362. "&chapterId=" +
  363. chapterId +
  364. "&orderGoodsId=" + this.orderGoodsId,
  365. });
  366. } else {
  367. uni.showToast({
  368. icon: "none",
  369. title: "该试卷只能答题" + item.answerNum + "次",
  370. });
  371. return;
  372. }
  373. } else {
  374. uni.showToast({
  375. icon: "none",
  376. title: "请学完视频课程再进行练习和测试",
  377. });
  378. }
  379. } else {
  380. let num = await this.bankRecordDoNum(item.typeId);
  381. //有次数限制
  382. if (item.answerNum - item.doNum > 0 && item.answerNum > 0) {
  383. // this.$set(this.list[index],'doNum',(item.doNum+1))
  384. console.log(this.list[index]);
  385. uni.navigateTo({
  386. url:
  387. "/pages2/class/questionBank?courseId=" +
  388. this.courseId +
  389. "&gradeId=" +
  390. this.gradeId +
  391. "&isFromVideo=1&id=" +
  392. id +
  393. "&goodsid=" +
  394. goodsId +
  395. "&moduleId=" +
  396. moduleId +
  397. "&chapterId=" +
  398. chapterId +
  399. "&orderGoodsId=" + this.orderGoodsId,
  400. });
  401. //没有答题次数限制
  402. } else if (item.answerNum == 0) {
  403. uni.navigateTo({
  404. url:
  405. "/pages2/class/questionBank?courseId=" +
  406. this.courseId +
  407. "&gradeId=" +
  408. this.gradeId +
  409. "&isFromVideo=1&id=" +
  410. id +
  411. "&goodsid=" +
  412. goodsId +
  413. "&moduleId=" +
  414. moduleId +
  415. "&chapterId=" +
  416. chapterId +
  417. "&orderGoodsId=" + this.orderGoodsId,
  418. });
  419. } else {
  420. uni.showToast({
  421. icon: "none",
  422. title: "该试卷只能答题" + item.answerNum + "次",
  423. });
  424. return;
  425. }
  426. }
  427. },
  428. bankRecordDoNum(examId) {
  429. return new Promise((resolve) => {
  430. this.$api
  431. .bankRecordDoNum({
  432. goodsId: this.goodsId,
  433. gradeId: this.gradeId,
  434. chapterId: this.menuItem.id,
  435. courseId: this.courseId,
  436. moduleId: 0,
  437. examId: examId,
  438. })
  439. .then((res) => {
  440. resolve(res.data.data);
  441. });
  442. });
  443. },
  444. openChapter(item) {
  445. console.log(this.menuItem);
  446. this.down = !this.down;
  447. if (!this.down && this.list.length == 0) {
  448. console.log(item.id, 69);
  449. if (this.isBuy) {
  450. let moduleId = item.moduleId ? item.moduleId : 0;
  451. if (this.isRebuild) {
  452. this.getReSectionList(item.id, item.courseId, moduleId);
  453. } else {
  454. this.getBuySectionList(item.id, item.courseId, moduleId);
  455. // this.getMenuExamList(item.id,item.courseId,moduleId)
  456. }
  457. } else {
  458. this.getSectionList(item.id);
  459. }
  460. }
  461. },
  462. getMenuExamList(chapterId, courseId, moduleId) {
  463. let self = this;
  464. this.$api
  465. .menuExamList({
  466. chapterId: chapterId,
  467. courseId: courseId,
  468. moduleId: moduleId,
  469. })
  470. .then((res) => {
  471. if (res.data.code == 200) {
  472. self.examList = res.data.rows;
  473. }
  474. });
  475. },
  476. getSectionList(chapterId) {
  477. let self = this;
  478. // url: '/app/common/course/sectionList/'+data,
  479. this.$api.sectionList(chapterId).then((res) => {
  480. if (res.data.code == 200) {
  481. for (let i = 0; i < res.data.data.length; i++) {
  482. let item = res.data.data[i];
  483. item.id = item.sectionId;
  484. item.menuType = 3;
  485. //判断是否试听
  486. item.tryListen = false;
  487. if (self.goodsAuditionConfigIdList.indexOf(item.id) !== -1) {
  488. item.tryListen = true;
  489. }
  490. }
  491. let newArr = res.data.data.filter((item) => {
  492. console.log(item);
  493. return item.type != 2;
  494. });
  495. this.canLearn = newArr.every((item) => {
  496. console.log(item);
  497. if (item.learning == 1) {
  498. return true;
  499. } else {
  500. return false;
  501. }
  502. });
  503. self.list = res.data.data;
  504. }
  505. });
  506. },
  507. getReSectionList(chapterId, courseId, moduleId) {
  508. let self = this;
  509. this.$api
  510. .reSectionList({
  511. chapterId: chapterId,
  512. gradeId: this.gradeId,
  513. courseId: courseId,
  514. rebuild: 1,
  515. moduleId: moduleId,
  516. })
  517. .then((res) => {
  518. if (res.data.code == 200) {
  519. for (let i = 0; i < res.data.data.length; i++) {
  520. let item = res.data.data[i];
  521. item.id = item.sectionId;
  522. item.menuType = 3;
  523. //判断是否试听
  524. item.tryListen = false;
  525. if (self.goodsAuditionConfigIdList.indexOf(item.id) !== -1) {
  526. item.tryListen = true;
  527. }
  528. }
  529. let newArr = res.data.data.filter((item) => {
  530. console.log(item);
  531. return item.type != 2;
  532. });
  533. this.canLearn = newArr.every((item) => {
  534. console.log(item);
  535. if (item.learning == 1) {
  536. return true;
  537. } else {
  538. return false;
  539. }
  540. });
  541. self.list = res.data.data;
  542. }
  543. });
  544. },
  545. getBuySectionList(chapterId, courseId, moduleId) {
  546. let self = this;
  547. this.$api
  548. .reSectionList({
  549. chapterId: chapterId,
  550. gradeId: this.gradeId,
  551. courseId: courseId,
  552. moduleId: moduleId,
  553. })
  554. .then((res) => {
  555. if (res.data.code == 200) {
  556. for (let i = 0; i < res.data.data.length; i++) {
  557. let item = res.data.data[i];
  558. item.id = item.sectionId;
  559. item.menuType = 3;
  560. //判断是否试听
  561. item.tryListen = false;
  562. if (self.goodsAuditionConfigIdList.indexOf(item.id) !== -1) {
  563. item.tryListen = true;
  564. }
  565. }
  566. let newArr = res.data.data.filter((item) => {
  567. return item.type != 2;
  568. });
  569. this.canLearn = newArr.every((item) => {
  570. console.log(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. },
  582. computed: { ...mapGetters(["goodsAuditionConfigIdList", "chapterOpen"]) },
  583. };
  584. </script>
  585. <style scoped>
  586. .tagRe {
  587. width: 80rpx;
  588. height: 28rpx;
  589. background: #ff3b30;
  590. border-radius: 8rpx;
  591. font-size: 20rpx;
  592. color: #ffffff;
  593. text-align: center;
  594. }
  595. .tagGreen {
  596. width: 80rpx;
  597. height: 28rpx;
  598. background: #34c759;
  599. border-radius: 8rpx;
  600. font-size: 20rpx;
  601. color: #ffffff;
  602. text-align: center;
  603. }
  604. .eTag {
  605. width:56rpx;
  606. height:42rpx;
  607. text-align: center;
  608. line-height: 42rpx;
  609. font-size: 20rpx;
  610. background: #007aff;
  611. border-radius: 8rpx;
  612. color: #ffffff;
  613. }
  614. .examBox {
  615. display: flex;
  616. align-items: center;
  617. justify-content: space-between;
  618. }
  619. .exam {
  620. font-size: 30rpx;
  621. display: flex;
  622. align-items: center;
  623. margin: 20rpx 0;
  624. }
  625. .icon_up {
  626. width: 24rpx;
  627. height: 24rpx;
  628. }
  629. .title {
  630. font-size: 30rpx;
  631. font-family: PingFang SC;
  632. font-weight: bold;
  633. color: #666666;
  634. white-space: nowrap;
  635. overflow: hidden;
  636. text-overflow: ellipsis;
  637. margin-bottom: 30rpx;
  638. }
  639. </style>