courseChapter.vue 21 KB

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