courseChapter.vue 19 KB

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