courseChapter.vue 20 KB

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