courseChapter.vue 20 KB

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