courseChapter.vue 20 KB

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