courseChapterMulu.vue 19 KB

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