CourseTree.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. <template>
  2. <div id="courseTree">
  3. <el-empty description="暂无课程" v-if="courseList.length === 0"></el-empty>
  4. <ul v-else class="courseTree">
  5. <li v-for="(item1, index1) in courseDataList" :key="index1">
  6. <div
  7. class="menu_box"
  8. @click="openMenu(item1)"
  9. :class="isActive(item1) ? 'active' : ''"
  10. >
  11. <div class="left level1">
  12. <el-tag
  13. size="mini"
  14. effect="dark"
  15. :type="getTypeStyle(item1)"
  16. v-if="item1.type == 3 || item1.type == -1"
  17. >{{ changeName(item1) }}</el-tag
  18. >
  19. <span v-else>
  20. {{ changeName(item1) }}
  21. </span>
  22. </div>
  23. <div class="center">
  24. {{ item1.name }}
  25. </div>
  26. <div class="right">
  27. <template v-if="item1.type == 3">
  28. <img
  29. v-if="isActive(item1)"
  30. src="@/assets/learing.gif"
  31. alt=""
  32. class="activeImg_style"
  33. />
  34. <div class="during">
  35. {{ $tools.secondToDate(item1.durationTime) }}
  36. </div>
  37. <template v-if="BackSTATUS(item1)['name']">
  38. <el-tag
  39. size="mini"
  40. effect="light"
  41. :type="BackSTATUS(item1)['style']"
  42. >{{ BackSTATUS(item1)["name"] }}</el-tag
  43. >
  44. </template>
  45. <el-tag
  46. size="mini"
  47. effect="dark"
  48. v-if="item1.examList.length > 0"
  49. @click.stop="doExam(item1.examList[0], 2)"
  50. >习题</el-tag
  51. >
  52. </template>
  53. <template v-else-if="item1.type == -1">
  54. <template v-if="BackExamStatus(item1)['name']">
  55. <el-tag
  56. size="mini"
  57. effect="light"
  58. :type="BackExamStatus(item1)['style']"
  59. >{{ BackExamStatus(item1)["name"] }}</el-tag
  60. >
  61. </template>
  62. </template>
  63. <el-tag
  64. v-else
  65. size="mini"
  66. effect="light"
  67. :type="getStudyStatus(item1)['style']"
  68. >{{ getStudyStatus(item1)["name"] }}</el-tag
  69. >
  70. </div>
  71. </div>
  72. <ul
  73. v-if="item1.children && item1.children.length > 0 && item1.showStatus"
  74. >
  75. <li v-for="(item2, index2) in item1.children" :key="index2">
  76. <div
  77. class="menu_box"
  78. @click="openMenu(item2)"
  79. :class="isActive(item2) ? 'active' : ''"
  80. >
  81. <div class="left level2">
  82. <el-tag
  83. size="mini"
  84. effect="dark"
  85. :type="getTypeStyle(item2)"
  86. v-if="item2.type == 3 || item2.type == -1"
  87. >{{ changeName(item2) }}</el-tag
  88. >
  89. <span v-else>
  90. {{ changeName(item2) }}
  91. </span>
  92. </div>
  93. <div class="center">
  94. {{ item2.name }}
  95. </div>
  96. <div class="right">
  97. <template v-if="item2.type == 3">
  98. <img
  99. v-if="isActive(item2)"
  100. src="@/assets/learing.gif"
  101. alt=""
  102. class="activeImg_style"
  103. />
  104. <div class="during">
  105. {{ $tools.secondToDate(item2.durationTime) }}
  106. </div>
  107. <template v-if="BackSTATUS(item2)['name']">
  108. <el-tag
  109. size="mini"
  110. effect="light"
  111. :type="BackSTATUS(item2)['style']"
  112. >{{ BackSTATUS(item2)["name"] }}</el-tag
  113. >
  114. </template>
  115. <el-tag
  116. size="mini"
  117. effect="dark"
  118. v-if="item2.examList.length > 0"
  119. @click.stop="doExam(item2.examList[0], 2)"
  120. >习题</el-tag
  121. >
  122. </template>
  123. <template v-else-if="item2.type == -1">
  124. <template v-if="BackExamStatus(item2)['name']">
  125. <el-tag
  126. size="mini"
  127. effect="light"
  128. :type="BackExamStatus(item2)['style']"
  129. >{{ BackExamStatus(item2)["name"] }}</el-tag
  130. >
  131. </template>
  132. </template>
  133. <el-tag
  134. v-else
  135. size="mini"
  136. effect="light"
  137. :type="getStudyStatus(item2)['style']"
  138. >{{ getStudyStatus(item2)["name"] }}</el-tag
  139. >
  140. </div>
  141. </div>
  142. <ul
  143. v-if="
  144. item2.children && item2.children.length > 0 && item2.showStatus
  145. "
  146. >
  147. <li v-for="(item3, index3) in item2.children" :key="index3">
  148. <div
  149. class="menu_box"
  150. @click="openMenu(item3)"
  151. :class="isActive(item3) ? 'active' : ''"
  152. >
  153. <div class="left level3">
  154. <el-tag
  155. size="mini"
  156. effect="dark"
  157. :type="getTypeStyle(item3)"
  158. v-if="item3.type == 3 || item3.type == -1"
  159. >{{ changeName(item3) }}</el-tag
  160. >
  161. <span v-else>
  162. {{ changeName(item3) }}
  163. </span>
  164. </div>
  165. <div class="center">
  166. {{ item3.name }}
  167. </div>
  168. <div class="right">
  169. <template v-if="item3.type == 3">
  170. <img
  171. v-if="isActive(item3)"
  172. src="@/assets/learing.gif"
  173. alt=""
  174. class="activeImg_style"
  175. />
  176. <div class="during">
  177. {{ $tools.secondToDate(item3.durationTime) }}
  178. </div>
  179. <template v-if="BackSTATUS(item3)['name']">
  180. <el-tag
  181. size="mini"
  182. effect="light"
  183. :type="BackSTATUS(item3)['style']"
  184. >{{ BackSTATUS(item3)["name"] }}</el-tag
  185. >
  186. </template>
  187. <el-tag
  188. size="mini"
  189. effect="dark"
  190. v-if="item3.examList.length > 0"
  191. @click.stop="doExam(item3.examList[0], 2)"
  192. >习题</el-tag
  193. >
  194. </template>
  195. <template v-else-if="item3.type == -1">
  196. <template v-if="BackExamStatus(item3)['name']">
  197. <el-tag
  198. size="mini"
  199. effect="light"
  200. :type="BackExamStatus(item3)['style']"
  201. >{{ BackExamStatus(item3)["name"] }}</el-tag
  202. >
  203. </template>
  204. </template>
  205. <el-tag v-else size="mini" effect="dark">{{
  206. getStudyStatus(item3)
  207. }}</el-tag>
  208. </div>
  209. </div>
  210. </li>
  211. </ul>
  212. </li>
  213. </ul>
  214. </li>
  215. </ul>
  216. </div>
  217. </template>
  218. <script>
  219. export default {
  220. inject: ["getGoodsData", "getBusinessData"],
  221. data() {
  222. return {
  223. courseList: [], //商品的课程列表
  224. courseDataList: [], //课程内容
  225. allSectionList: [], //商品下所有节和试卷
  226. activeSection: {}, //当前节数据
  227. nowTime: 0 //当前时间
  228. };
  229. },
  230. computed: {
  231. goodsData() {
  232. return this.getGoodsData();
  233. },
  234. businessData() {
  235. return this.getBusinessData();
  236. },
  237. changeName: function() {
  238. return function(item) {
  239. var str = "";
  240. if (item.type == 3) {
  241. switch (item.sectionType) {
  242. case 1:
  243. str = "视频";
  244. break;
  245. case 2:
  246. str = "直播";
  247. break;
  248. case 3:
  249. str = "回放";
  250. break;
  251. default:
  252. break;
  253. }
  254. } else if (item.type == -1) {
  255. if (item.doType == 1) {
  256. str = "练习";
  257. } else {
  258. str = "考试";
  259. }
  260. } else {
  261. if (item.showStatus) {
  262. str = "▼";
  263. } else {
  264. str = "▶";
  265. }
  266. }
  267. return str;
  268. };
  269. },
  270. getTypeStyle: function() {
  271. return function(item) {
  272. if (item.type == 3) {
  273. if (item.sectionType == 2) {
  274. return "danger";
  275. }
  276. if (item.sectionType == 3) {
  277. return "warning";
  278. }
  279. } else {
  280. return "";
  281. }
  282. };
  283. },
  284. BackSTATUS: function() {
  285. return function(item) {
  286. if (item.sectionType == 1) {
  287. if (item.rebuild > 0) {
  288. return {
  289. name: "待重修",
  290. style: "danger"
  291. };
  292. } else if (item.learning == 1) {
  293. return {
  294. name: "已学完",
  295. style: "success"
  296. };
  297. }
  298. }
  299. if (item.sectionType == 2) {
  300. if (item.liveStartTime > this.nowTime) {
  301. return {
  302. name: "待开播",
  303. style: "warning"
  304. };
  305. } else if (
  306. item.liveStartTime <= this.nowTime &&
  307. item.liveEndTime > this.nowTime
  308. ) {
  309. return {
  310. name: "直播中",
  311. style: "success"
  312. };
  313. } else if (item.liveEndTime < this.nowTime) {
  314. return {
  315. name: "已结束",
  316. style: "danger"
  317. };
  318. }
  319. }
  320. return {};
  321. };
  322. },
  323. BackExamStatus: function() {
  324. return function(item) {
  325. if (item.rebuild > 0) {
  326. return {
  327. name: "待重测",
  328. style: "danger"
  329. };
  330. } else if (item.learing == 1) {
  331. return {
  332. name: "合格",
  333. style: "success"
  334. };
  335. } else if (item.learing == 0) {
  336. return {
  337. name: "不及格(需重考)",
  338. style: "danger"
  339. };
  340. }
  341. return {};
  342. };
  343. },
  344. isActive: function() {
  345. return function(item) {
  346. return (
  347. item.courseId == this.activeSection.courseId &&
  348. item.moduleId == this.activeSection.moduleId &&
  349. item.chapterId == this.activeSection.chapterId &&
  350. item.sectionId == this.activeSection.sectionId
  351. );
  352. };
  353. },
  354. getStudyStatus: function() {
  355. return function(item) {
  356. if (item.type == 1) {
  357. var STATUSARRAY = this.allSectionList.filter(i => {
  358. return i.moduleId == item.moduleId;
  359. });
  360. if (
  361. STATUSARRAY.findIndex(
  362. i =>
  363. i.moduleId == this.activeSection.moduleId &&
  364. i.chapterId == this.activeSection.chapterId &&
  365. i.sectionId == this.activeSection.sectionId
  366. ) !== -1
  367. ) {
  368. return {
  369. name: "学习中",
  370. style: "warning"
  371. };
  372. }
  373. }
  374. if (item.type == 2) {
  375. var STATUSARRAY = this.allSectionList.filter(i => {
  376. return i.moduleId == item.moduleId && i.chapterId == item.chapterId;
  377. });
  378. if (
  379. STATUSARRAY.findIndex(
  380. i =>
  381. i.moduleId == this.activeSection.moduleId &&
  382. i.chapterId == this.activeSection.chapterId &&
  383. i.sectionId == this.activeSection.sectionId
  384. ) !== -1
  385. ) {
  386. return {
  387. name: "学习中",
  388. style: "warning"
  389. };
  390. }
  391. }
  392. if (STATUSARRAY.every(i => i.studyStatus == 1)) {
  393. if (STATUSARRAY.findIndex(i => i.rebuild == 1) !== -1) {
  394. return {
  395. name: "待重修",
  396. style: "danger"
  397. };
  398. } else {
  399. return {
  400. name: "已学完",
  401. style: "success"
  402. };
  403. }
  404. } else if (STATUSARRAY.every(i => i.studyStatus == -1)) {
  405. return {
  406. name: "待学习",
  407. style: ""
  408. };
  409. }
  410. // const Array1 = this.allSectionList.filter(
  411. // i =>
  412. // (i.chapterId == item.chapterId || i.chapterId == item.menuId) &&
  413. // (i.moduleId == item.moduleId || i.moduleId == 0)
  414. // );
  415. // var str = "";
  416. // console.log("chapter", this.sectionItem, item);
  417. // if (Array1.every(i => i.studyStatus == 1)) {
  418. // item.studyStatus = 1;
  419. // str = style_type ? 1 : "已学完";
  420. // } else {
  421. // item.studyStatus = -1;
  422. // str = style_type ? -1 : "待学习";
  423. // }
  424. // if (
  425. // (item.menuId == this.sectionItem.chapterId &&
  426. // 0 == this.sectionItem.moduleId) ||
  427. // (item.chapterId == this.sectionItem.chapterId &&
  428. // item.moduleId == this.sectionItem.moduleId)
  429. // ) {
  430. // item.studyStatus = 0;
  431. // str = style_type ? 0 : "学习中";
  432. // }
  433. // return str;
  434. };
  435. }
  436. },
  437. created() {
  438. this.init();
  439. this.nowTime = Number(new Date().getTime() / 1000).toFixed(0);
  440. },
  441. methods: {
  442. async init() {
  443. await this.getGoodsCourseList(); //获取商品课程列表
  444. await this.getCourseData(this.courseList[0].courseId); //获取课程内容
  445. await this.getAllSectionList(); //获取所有节列表
  446. /**播放逻辑 */
  447. this.playBackLogic();
  448. },
  449. //获取商品课程列表
  450. getGoodsCourseList() {
  451. return new Promise((resolve, reject) => {
  452. this.$request
  453. .courseCourseList({
  454. goodsId: this.goodsData.goodsId,
  455. gradeId: this.goodsData.gradeId
  456. })
  457. .then(res => {
  458. if (res.rows && res.rows.length > 0) {
  459. this.courseList = res.rows;
  460. resolve();
  461. } else {
  462. reject();
  463. }
  464. })
  465. .catch(() => {
  466. reject();
  467. });
  468. });
  469. },
  470. //获取课程内容
  471. getCourseData(id) {
  472. return new Promise(async (resolve, reject) => {
  473. const examRes = await this.$request.reSectionExamList({
  474. chapterId: 0,
  475. courseId: id,
  476. gradeId: this.goodsData.gradeId,
  477. orderGoodsId: this.goodsData.orderGoodsId
  478. }); //获取节关联练习试卷
  479. this.$request
  480. .reMenuList({
  481. courseId: id,
  482. gradeId: this.goodsData.gradeId,
  483. orderGoodsId: this.goodsData.orderGoodsId
  484. })
  485. .then(res => {
  486. this.courseDataList = res.rows.map(i => {
  487. return {
  488. level: 1,
  489. type: i.type,
  490. name: i.menuName,
  491. courseId: i.courseId,
  492. moduleId: i.type == 1 ? i.menuId : 0,
  493. chapterId: i.type == 2 ? i.menuId : 0,
  494. sectionId: i.type == 3 ? i.menuId : 0,
  495. sectionType: i.type == 3 ? i.sectionType : null,
  496. durationTime: i.type == 3 ? i.durationTime : null,
  497. recordingUrl: i.type == 3 ? i.recordingUrl : null,
  498. showStatus: false, //展开状态
  499. children: null, //子列表
  500. learning: i.type == 3 ? i.learning : null,
  501. examList:
  502. i.type == 3
  503. ? examRes.data.filter(item => item.sectionId == i.menuId)
  504. : [] //关联试卷
  505. };
  506. });
  507. resolve();
  508. });
  509. });
  510. },
  511. //展开模块
  512. openModule(item) {
  513. if (item.children && item.children.length > 0) {
  514. item.showStatus = !item.showStatus;
  515. } else {
  516. return new Promise(resolve => {
  517. this.$request
  518. .reChapterList({
  519. moduleId: item.moduleId,
  520. gradeId: this.goodsData.gradeId,
  521. courseId: this.courseDataList[0].courseId,
  522. orderGoodsId: this.goodsData.orderGoodsId
  523. // rebuild: isRebuild ? 1 : undefined
  524. })
  525. .then(res => {
  526. this.$set(item, "showStatus", true);
  527. this.$set(
  528. item,
  529. "children",
  530. res.data.map(i => {
  531. if (i.id) {
  532. return {
  533. level: item.level + 1,
  534. type: 2,
  535. name: i.name,
  536. courseId: i.courseId,
  537. moduleId: i.moduleId,
  538. chapterId: i.chapterId,
  539. sectionId: 0,
  540. sectionType: null,
  541. durationTime: null,
  542. recordingUrl: null,
  543. showStatus: false, //展开状态
  544. children: null, //子列表
  545. examList: [] //关联试卷
  546. };
  547. } else {
  548. return Object.assign(i, {
  549. type: -1,
  550. chapterId: 0,
  551. examType: 3
  552. }); //examType:1章卷,2节卷,3模块卷
  553. }
  554. })
  555. );
  556. resolve(item.children);
  557. });
  558. });
  559. }
  560. },
  561. //展开章
  562. openChapter(item) {
  563. if (item.children && item.children.length > 0) {
  564. item.showStatus = !item.showStatus;
  565. } else {
  566. return new Promise(async resolve => {
  567. const examRes = await this.$request.reSectionExamList({
  568. moduleId: item.moduleId,
  569. chapterId: item.chapterId,
  570. courseId: item.courseId,
  571. gradeId: this.goodsData.gradeId,
  572. orderGoodsId: this.goodsData.orderGoodsId
  573. }); //获取节关联练习试卷
  574. this.$request
  575. .reSectionList({
  576. chapterId: item.chapterId,
  577. gradeId: this.goodsData.gradeId,
  578. courseId: item.courseId,
  579. // rebuild: isRebuild ? 1 : undefined,
  580. moduleId: item.moduleId,
  581. orderGoodsId: this.goodsData.orderGoodsId
  582. })
  583. .then(res => {
  584. this.$set(item, "showStatus", true);
  585. this.$set(
  586. item,
  587. "children",
  588. res.data.map(i => {
  589. if (i.id) {
  590. return {
  591. level: item.level + 1,
  592. type: 3,
  593. name: i.name,
  594. courseId: item.courseId,
  595. moduleId: i.moduleId,
  596. chapterId: i.chapterId,
  597. sectionId: i.sectionId,
  598. sectionType: i.sectionType,
  599. durationTime: i.durationTime,
  600. recordingUrl: i.recordingUrl,
  601. learning: i.learning,
  602. rebuild: i.rebuild,
  603. showStatus: false, //展开状态
  604. children: null, //子列表
  605. examList:
  606. examRes.data.filter(
  607. item => item.sectionId == i.sectionId
  608. ) || [] //关联试卷
  609. };
  610. } else {
  611. return Object.assign(i, { type: -1, examType: 1 }); //examType:1章卷,2节卷,3模块卷
  612. }
  613. })
  614. );
  615. resolve();
  616. });
  617. });
  618. }
  619. },
  620. //获取所有节列表
  621. getAllSectionList() {
  622. return new Promise((resolve, reject) => {
  623. this.$request
  624. .studyrecordgoodsAllListWithExam({
  625. gradeId: this.goodsData.gradeId,
  626. goodsId: this.goodsData.goodsId,
  627. courseId: this.courseList[0].courseId,
  628. orderGoodsId: this.goodsData.orderGoodsId
  629. // rebuild: this.rebuild
  630. })
  631. .then(res => {
  632. let ary = res.data.map(i => {
  633. if (i.type === 3) {
  634. return {
  635. type: 3,
  636. name: i.sectionName,
  637. courseId: i.courseId,
  638. moduleId: i.moduleId,
  639. chapterId: i.chapterId,
  640. sectionId: i.sectionId,
  641. sectionType: i.sectionType,
  642. recordingUrl: i.recordingUrl,
  643. studyStatus: i.studyStatus
  644. };
  645. } else {
  646. return Object.assign(i, {
  647. type: -1,
  648. typeId: i.examId,
  649. chapterId: i.chapterId || 0
  650. });
  651. }
  652. });
  653. this.allSectionList = ary.filter(i => i.sectionType != 2);
  654. resolve();
  655. });
  656. });
  657. },
  658. //点击菜单
  659. async openMenu(item) {
  660. if (item.type == 1) {
  661. await this.openModule(item); //展开模块
  662. } else if (item.type == 2) {
  663. await this.openChapter(item); //展开章
  664. } else {
  665. try {
  666. await this.waitCheckStatus(item); //检查是否可以继续执行
  667. if (item.type == 3) {
  668. if (item.sectionType == 1) {
  669. this.watchSection(item);
  670. } else {
  671. this.watchJumpSection(item);
  672. }
  673. }
  674. if (item.type == -1) {
  675. this.doExam(item);
  676. }
  677. } catch (error) {
  678. console.log(error, "error");
  679. }
  680. }
  681. },
  682. //检查是否可以继续执行
  683. waitCheckStatus(item) {
  684. return new Promise(async (resolve, reject) => {
  685. if (
  686. item.type == 3 &&
  687. ((item.sectionType == 1 && !item.recordingUrl) ||
  688. (item.sectionType == 2 && !item.liveUrl) ||
  689. (item.sectionType == 3 && !item.recordingUrl))
  690. ) {
  691. this.$message({
  692. type: "warning",
  693. message: `暂无播放地址数据`
  694. });
  695. return reject();
  696. }
  697. if (
  698. item.type == -1 &&
  699. item.doType != 1 &&
  700. item.learning == 1 &&
  701. !(item.rebuild > 0)
  702. ) {
  703. this.$message.warning("考试已通过,请勿重复考试");
  704. return reject();
  705. }
  706. if (!this.orderTopTobottom(item)) {
  707. this.$message({
  708. type: "warning",
  709. message:
  710. item.type == -1
  711. ? "请学完视频课程再进行练习和测试"
  712. : "请按顺序学习视频课程"
  713. });
  714. return reject();
  715. }
  716. // 检查学习次数
  717. if (!(await this.exceedLearnNum(item))) {
  718. return reject();
  719. }
  720. resolve();
  721. });
  722. },
  723. //播放视频节
  724. watchSection(item) {
  725. if (this.isActive(item)) return;
  726. this.$bus.$emit("toPlay", item);
  727. this.$emit("backActiveSection", item);
  728. this.activeSection = item;
  729. let query = {
  730. gradeId: this.goodsData.gradeId,
  731. orderGoodsId: this.goodsData.orderGoodsId,
  732. courseId: item.courseId,
  733. moduleId: item.moduleId || 0,
  734. chapterId: item.chapterId || 0,
  735. sectionId: item.sectionId || 0
  736. };
  737. this.$router.replace({ path: this.$route.path, query });
  738. },
  739. //回放或直播
  740. async watchJumpSection(item) {
  741. if (item.sectionType == 2) {
  742. let data = await this.studyRecordGetChannelBasicInfo(item.liveUrl);
  743. if (data.watchStatus == "end" || data.watchStatus == "playback") {
  744. this.$message({
  745. type: "warning",
  746. message: `直播已结束`
  747. });
  748. return;
  749. }
  750. if (data.watchStatus == "waiting") {
  751. this.$message({
  752. type: "warning",
  753. message: `直播未开始`
  754. });
  755. return;
  756. }
  757. }
  758. this.toPlaySection(item);
  759. },
  760. toPlaySection(item) {},
  761. //跳转试卷
  762. async doExam(section, type) {
  763. // 试卷学习次数
  764. let num =
  765. this.businessData.goodsLearningOrder != 2 || section.rebuild
  766. ? await this.bankRecordDoNum(section)
  767. : section.doNum;
  768. if (
  769. (section.answerNum - num > 0 && section.answerNum > 0) ||
  770. section.answerNum == 0
  771. ) {
  772. this.$confirm("是否跳转做题页面?", "提示", {
  773. confirmButtonText: "确定",
  774. cancelButtonText: "取消",
  775. type: "warning"
  776. })
  777. .then(() => {
  778. this.$router.push({
  779. path: "/course-exam/" + this.goodsData.goodsId,
  780. query: {
  781. gradeId: this.goodsData.gradeId,
  782. courseId: this.courseList[0].courseId,
  783. moduleId: section.moduleId || 0,
  784. chapterId: section.chapterId || 0,
  785. sectionId: section.sectionId || 0,
  786. examId: section.typeId,
  787. learning: section.learning,
  788. type: type || section.examType,
  789. nextStatus: "next", //是否继续播放课程
  790. orderGoodsId: this.goodsData.orderGoodsId
  791. }
  792. });
  793. })
  794. .catch(() => {});
  795. } else {
  796. this.$message({
  797. type: "warning",
  798. message: "该试卷只能答题" + section.answerNum + "次"
  799. });
  800. return;
  801. }
  802. },
  803. //查看直播状态
  804. studyRecordGetChannelBasicInfo(channelId) {
  805. return new Promise(resolve => {
  806. this.$request
  807. .studyRecordGetChannelBasicInfo({
  808. channelId
  809. })
  810. .then(res => {
  811. resolve(res.data);
  812. })
  813. .catch(err => {});
  814. });
  815. },
  816. //限制播放顺序
  817. orderTopTobottom(item) {
  818. if (this.businessData.goodsLearningOrder != 2 || item.sectionType == 2) {
  819. return true;
  820. }
  821. const Findex = this.allSectionList.findIndex(i => {
  822. if (item.type == 3) {
  823. return (
  824. i.type == item.type &&
  825. i.moduleId == item.moduleId &&
  826. i.chapterId == item.chapterId &&
  827. i.sectionId == item.sectionId
  828. );
  829. } else {
  830. return (
  831. i.type == item.type &&
  832. i.typeId == item.typeId &&
  833. i.moduleId == item.moduleId &&
  834. i.chapterId == item.chapterId
  835. );
  836. }
  837. });
  838. if (Findex == -1) {
  839. return true;
  840. } else {
  841. const Ary = this.allSectionList.slice(0, Findex);
  842. if (Ary.length == 0) {
  843. return true;
  844. } else {
  845. return Ary.every(i => i.studyStatus == 1 && !(i.rebuild > 0));
  846. }
  847. }
  848. },
  849. // 检查学习次数
  850. async exceedLearnNum(section) {
  851. let learnNum = await this.goodsTodayStudySectionNum();
  852. let hasLearn = await this.gradeCheckGoodsStudy(section);
  853. if (
  854. this.goodsData.sectionMaxNum > 0 &&
  855. learnNum >= this.goodsData.sectionMaxNum &&
  856. !hasLearn
  857. ) {
  858. this.$message({
  859. type: "warning",
  860. message: `每天最多学习${this.goodsData.sectionMaxNum}节`
  861. });
  862. return false;
  863. }
  864. return true;
  865. },
  866. goodsTodayStudySectionNum() {
  867. return new Promise(resolve => {
  868. this.$request
  869. .goodsTodayStudySectionNum({
  870. goodsId: this.goodsData.goodsId,
  871. gradeId: this.goodsData.gradeId
  872. })
  873. .then(res => {
  874. resolve(res.data);
  875. });
  876. });
  877. },
  878. gradeCheckGoodsStudy(option) {
  879. return new Promise(resolve => {
  880. let data = {
  881. type: option.type == -1 ? 2 : 1,
  882. goodsId: this.goodsData.goodsId,
  883. gradeId: this.goodsData.gradeId,
  884. moduleId: option.moduleId || 0,
  885. chapterId: option.chapterId || 0
  886. };
  887. if (option.type == -1) {
  888. data.examId = option.typeId;
  889. } else {
  890. data.sectionId = option.sectionId;
  891. }
  892. this.$request.gradeCheckGoodsStudy(data).then(res => {
  893. resolve(res.data);
  894. });
  895. });
  896. },
  897. bankRecordDoNum(section) {
  898. return new Promise(resolve => {
  899. this.$request
  900. .bankRecordDoNum({
  901. goodsId: this.goodsData.goodsId,
  902. gradeId: this.goodsData.gradeId,
  903. courseId: this.courseList[0].courseId,
  904. moduleId: 0,
  905. chapterId: section.chapterId,
  906. examId: section.typeId
  907. })
  908. .then(res => {
  909. resolve(res.data);
  910. });
  911. });
  912. },
  913. //播放逻辑
  914. async playBackLogic() {
  915. const { courseId, moduleId, chapterId, sectionId } = this.$route.query;
  916. if (courseId >= 0 && moduleId >= 0 && chapterId >= 0 && sectionId >= 0) {
  917. let data = this.allSectionList.find(
  918. e =>
  919. e.courseId == courseId &&
  920. e.moduleId == moduleId &&
  921. e.chapterId == chapterId &&
  922. e.sectionId == sectionId
  923. );
  924. this.openMenu(data);
  925. this.unfoldFunc(data); //展开定位列表
  926. } else {
  927. this.$request
  928. .studyRecordQueryLiveLast({
  929. gradeId: this.goodsData.gradeId,
  930. orderGoodsId: this.goodsData.orderGoodsId,
  931. courseId: this.courseList[0].courseId
  932. })
  933. .then(res => {
  934. let data = res.data;
  935. if (!data.sectionId) {
  936. data = this.allSectionList[0];
  937. } else {
  938. data.type = 3;
  939. }
  940. if (
  941. data.learning == 1 &&
  942. this.businessData.goodsLearningOrder == 2
  943. ) {
  944. let next = this.allSectionList.find(e => e.studyStatus != 1);
  945. next && (data = next);
  946. }
  947. this.openMenu(data);
  948. this.unfoldFunc(data); //展开定位列表
  949. });
  950. }
  951. },
  952. //展开定位列表
  953. async unfoldFunc(item) {
  954. if (item.moduleId) {
  955. var ary = this.courseDataList.find(i => i.moduleId == item.moduleId);
  956. let moduleChildren = await this.openModule(ary);
  957. if (item.chapterId) {
  958. await this.openChapter(
  959. moduleChildren.find(i => i.chapterId == item.chapterId)
  960. );
  961. }
  962. }
  963. if (!item.moduleId && item.chapterId) {
  964. var ary = this.courseDataList.find(i => i.chapterId == item.chapterId);
  965. await this.openChapter(ary);
  966. }
  967. }
  968. }
  969. };
  970. </script>
  971. <style lang="scss" scoped>
  972. .active {
  973. background-color: rgb(107, 107, 107) !important;
  974. }
  975. .activeImg_style {
  976. width: 20px;
  977. height: 30px;
  978. }
  979. .courseTree {
  980. height: 416px;
  981. overflow: auto;
  982. user-select: none;
  983. &::-webkit-scrollbar {
  984. width: 5px;
  985. height: 9px;
  986. }
  987. /*定义滚动条轨道 内阴影+圆角*/
  988. &::-webkit-scrollbar-track {
  989. background-color: inherit;
  990. border: none;
  991. border-radius: 10px;
  992. }
  993. /*定义滑块 内阴影+圆角*/
  994. &::-webkit-scrollbar-thumb {
  995. border-radius: 10px;
  996. position: relative;
  997. right: 2px;
  998. background-color: #c6c6cd;
  999. width: 6px;
  1000. }
  1001. }
  1002. .level1 {
  1003. padding-left: 0px;
  1004. }
  1005. .level2 {
  1006. padding-left: 10px;
  1007. }
  1008. .level3 {
  1009. padding-left: 20px;
  1010. }
  1011. .menu_box {
  1012. margin-top: 4px;
  1013. padding: 0px 10px;
  1014. display: flex;
  1015. align-items: center;
  1016. min-height: 30px;
  1017. max-height: 60px;
  1018. color: #fff;
  1019. cursor: pointer;
  1020. &:hover {
  1021. background-color: rgb(81, 81, 81);
  1022. }
  1023. & > .left {
  1024. flex-shrink: 0;
  1025. padding-right: 10px;
  1026. }
  1027. & > .center {
  1028. flex: 1;
  1029. word-break: break-all;
  1030. text-overflow: ellipsis;
  1031. overflow: hidden;
  1032. display: -webkit-box;
  1033. -webkit-line-clamp: 2;
  1034. -webkit-box-orient: vertical;
  1035. }
  1036. & > .right {
  1037. & > .during {
  1038. margin-right: 4px;
  1039. }
  1040. display: flex;
  1041. align-items: center;
  1042. // width: 80px;
  1043. flex-shrink: 0;
  1044. }
  1045. }
  1046. </style>