courseChapter.vue 17 KB

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