courseChapter.vue 18 KB

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