courseModule.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <!-- style="margin: 20rpx 0;" -->
  3. <view>
  4. <view class="title" @click="openModule(menuItem)">
  5. <text class="title_name" style="margin-left: 10rpx"
  6. >{{ menuItem.name }}
  7. </text>
  8. <view class="fl">
  9. <view
  10. class="title_status"
  11. :class="['grey', 'blue', 'gre'][learnStatus + 1]"
  12. style="margin-right: 20rpx"
  13. >
  14. {{ ["待学习", "学习中", "已学完"][learnStatus + 1] }}
  15. </view>
  16. <image src="/static/icon/up.png" class="icon_up" v-if="down"></image>
  17. <image src="/static/icon/down.png" class="icon_up" v-if="!down"></image>
  18. </view>
  19. </view>
  20. <view v-show="!down">
  21. <view v-for="(itemM, indexM) in list" :key="indexM">
  22. <!-- v-if='itemM.type != 2' -->
  23. <courseChapter
  24. v-if="itemM.type != 2"
  25. :orderGoodsId="orderGoodsId"
  26. :isLive="isLive"
  27. :preItem="list[indexM - 1] || preItem"
  28. :sectionMaxNum="sectionMaxNum"
  29. :needOpen="itemM.needOpen"
  30. @playEnd="playEnd($event)"
  31. @toDo="toDo($event)"
  32. :courseId="courseId"
  33. :learningOrder="learningOrder"
  34. :goodsId="goodsId"
  35. :isBuy="isBuy"
  36. :gradeId="gradeId"
  37. :isRebuild="isRebuild"
  38. :menuItem="itemM"
  39. :levelId="levelId + '-' + itemM.chapterId"
  40. :menuAllList="menuAllList"
  41. :sectionItem="sectionItem"
  42. >
  43. </courseChapter>
  44. <u-line v-if="indexM < list.length - 1"></u-line>
  45. <!-- 模块卷 -->
  46. <view v-if="itemM.type == 2">
  47. <view
  48. class="examBox"
  49. @click="
  50. toDoModuleExam(
  51. itemM.typeId,
  52. goodsId,
  53. itemM.moduleId,
  54. itemM.chapterId,
  55. itemM,
  56. indexM
  57. )
  58. "
  59. >
  60. <view class="exam">
  61. <view class="eTag">
  62. {{ itemM.doType == 1 ? "练习" : "考试" }}
  63. </view>
  64. <view style="margin-left: 15rpx; flex: 1">{{ itemM.name }}</view>
  65. </view>
  66. <view v-if="isRebuild || itemM.rebuild > 0" class="tagRe"
  67. >待重修</view
  68. >
  69. <view v-else>
  70. <view
  71. :class="{
  72. tagGreen: itemM.learning == 1,
  73. tagRe: itemM.learning == 0 || itemM.rebuild > 0,
  74. }"
  75. >
  76. <text v-if="itemM.learning == 1">合格</text>
  77. <text v-else-if="itemM.learning == 0">不及格(需重考)</text>
  78. <!-- <text v-else>不合格</text> -->
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <script>
  88. import { mapGetters } from "vuex";
  89. import courseChapter from "@/components/course/courseChapter.vue";
  90. export default {
  91. name: "courseModule",
  92. props: {
  93. isLive: false,
  94. orderGoodsId: {
  95. default: 0,
  96. },
  97. preItem: {
  98. default: undefined,
  99. },
  100. learningOrder: {
  101. //是否设置学习顺序 1 章节顺序 0不设置 2从头学到尾顺序
  102. type: Number,
  103. defaule: 0,
  104. },
  105. needOpen: {
  106. //是否默认展开
  107. type: Boolean,
  108. default: false,
  109. },
  110. menuItem: {
  111. type: Object,
  112. default: {},
  113. },
  114. goodsId: {
  115. type: Number,
  116. default: 0,
  117. },
  118. courseId: {
  119. type: [Number, String],
  120. default: 0,
  121. },
  122. isBuy: {
  123. //是否是已购买商品
  124. type: Boolean,
  125. default: false,
  126. },
  127. levelId: {
  128. type: [Number, String],
  129. default: "",
  130. },
  131. isRebuild: {
  132. //是否重修目录
  133. type: Boolean,
  134. default: false,
  135. },
  136. gradeId: {
  137. //重修需要班级ID
  138. type: Number,
  139. default: 0,
  140. },
  141. sectionMaxNum: {
  142. default: undefined,
  143. },
  144. // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  145. goodsType: {
  146. type: [Number, String],
  147. default: 0,
  148. },
  149. menuAllList: {
  150. // 课程所有子目录结构列表
  151. type: Array,
  152. default: () => [],
  153. },
  154. sectionItem: {
  155. // 用户最后一次看的录播的信息
  156. type: Object,
  157. default: () => {},
  158. },
  159. },
  160. components: {
  161. courseChapter,
  162. },
  163. data() {
  164. return {
  165. down: true,
  166. list: [],
  167. };
  168. },
  169. methods: {
  170. playEnd(isRebuild) {
  171. this.$emit("playEnd", { isRebuild: isRebuild.isRebuild });
  172. },
  173. toDo(item) {
  174. this.$emit("toDo", item);
  175. },
  176. openModule(item) {
  177. this.down = !this.down;
  178. console.log(this.down, 789);
  179. if (!this.down && this.list.length == 0) {
  180. if (this.isBuy) {
  181. if (this.isRebuild) {
  182. this.getReChapterList(item.id, item.courseId);
  183. } else {
  184. this.getBuyChapterList(item.id, item.courseId); //已购买目录
  185. }
  186. } else {
  187. this.getChapterList(item.id); //未购买目录
  188. }
  189. }
  190. },
  191. getChapterList(moduleId) {
  192. // url: '/app/common/course/chapterList/'+data,
  193. this.$api.chapterList(moduleId).then((res) => {
  194. if (res.data.code == 200) {
  195. for (let i = 0; i < res.data.data.length; i++) {
  196. let item = res.data.data[i];
  197. item.id = item.chapterId;
  198. item.menuType = 2;
  199. }
  200. this.list = res.data.data;
  201. }
  202. });
  203. },
  204. getReChapterList(moduleId, courseId) {
  205. this.$api
  206. .reChapterList({
  207. moduleId: moduleId,
  208. gradeId: this.gradeId,
  209. courseId: courseId,
  210. rebuild: 1,
  211. orderGoodsId: this.orderGoodsId
  212. })
  213. .then((res) => {
  214. if (res.data.code == 200) {
  215. for (let i = 0; i < res.data.data.length; i++) {
  216. let item = res.data.data[i];
  217. item.id = item.chapterId;
  218. }
  219. this.list = res.data.data;
  220. }
  221. });
  222. },
  223. getBuyChapterList(moduleId, courseId) {
  224. console.log(moduleId, courseId, "moduleId, courseId");
  225. // course/chapterList
  226. this.$api
  227. .reChapterList({
  228. moduleId: moduleId,
  229. gradeId: this.gradeId,
  230. courseId: courseId,
  231. orderGoodsId: this.orderGoodsId
  232. })
  233. .then((res) => {
  234. if (res.data.code == 200) {
  235. for (let i = 0; i < res.data.data.length; i++) {
  236. let item = res.data.data[i];
  237. item.id = item.chapterId;
  238. item.menuType = 2;
  239. if (Object.keys(this.sectionItem).length) {
  240. item["needOpen"] =
  241. item.chapterId == this.sectionItem.chapterId ? true : false;
  242. } else {
  243. item["needOpen"] = i == 0 ? true : false;
  244. }
  245. }
  246. this.list = res.data.data;
  247. // console.log('章的列表:', this.list);
  248. }
  249. });
  250. },
  251. /**
  252. * 去做题
  253. */
  254. async toDoModuleExam(
  255. id,
  256. goodsId = 0,
  257. moduleId = 0,
  258. chapterId = 0,
  259. item,
  260. index
  261. ) {
  262. if (item.doType === 2 && item.learning == 1) {
  263. return;
  264. }
  265. if (this.learningOrder == 2) {
  266. let newRows = [];
  267. newRows = this.menuAllList.filter((e) => e.moduleId == moduleId);
  268. let isAllLearn = newRows.every((item) => {
  269. return item.studyStatus == 1;
  270. });
  271. if (isAllLearn) {
  272. uni.navigateTo({
  273. url:
  274. "/pages2/class/questionBank?courseId=" +
  275. this.courseId +
  276. "&gradeId=" +
  277. this.gradeId +
  278. "&isFromVideo=1&id=" +
  279. id +
  280. "&goodsid=" +
  281. goodsId +
  282. "&moduleId=" +
  283. moduleId +
  284. "&chapterId=" +
  285. chapterId +
  286. "&orderGoodsId=" +
  287. this.orderGoodsId +
  288. "&type=3" +
  289. "&learning=" +
  290. item.learning +
  291. "&isBackVideo=" +
  292. 1,
  293. });
  294. } else {
  295. uni.showToast({
  296. icon: "none",
  297. title: "请学完视频课程再进行练习和测试",
  298. });
  299. }
  300. } else {
  301. uni.navigateTo({
  302. url:
  303. "/pages2/class/questionBank?courseId=" +
  304. this.courseId +
  305. "&gradeId=" +
  306. this.gradeId +
  307. "&isFromVideo=1&id=" +
  308. id +
  309. "&goodsid=" +
  310. goodsId +
  311. "&moduleId=" +
  312. moduleId +
  313. "&chapterId=" +
  314. chapterId +
  315. "&orderGoodsId=" +
  316. this.orderGoodsId +
  317. "&type=3" +
  318. "&learning=" +
  319. item.learning +
  320. "&isBackVideo=" +
  321. 1,
  322. });
  323. }
  324. },
  325. },
  326. computed: {
  327. ...mapGetters(["chapterOpen"]),
  328. learnStatus() {
  329. let { id, courseId } = this.menuItem;
  330. if (
  331. this.sectionItem.courseId == courseId &&
  332. this.sectionItem.moduleId == id
  333. ) {
  334. return 0;
  335. }
  336. const list = this.menuAllList.filter(
  337. (e) => e.courseId == courseId && e.moduleId == id
  338. );
  339. const isAllLearn = list.every((item) => {
  340. return item.studyStatus == 1;
  341. });
  342. return isAllLearn ? 1 : -1;
  343. },
  344. },
  345. mounted() {
  346. // if (this.needOpen && this.chapterOpen) {
  347. // this.openModule(this.menuItem);
  348. // }
  349. },
  350. watch: {
  351. courseId: {
  352. handler(val) {
  353. console.log(
  354. "🚀 ~ file: courseModule.vue:346 ~ handler ~ val:",
  355. this.sectionItem,
  356. this.menuItem
  357. );
  358. if (this.sectionItem.moduleId == this.menuItem.menuId) {
  359. this.down = true;
  360. this.list = [];
  361. this.openModule(this.menuItem);
  362. }
  363. },
  364. immediate: true,
  365. },
  366. },
  367. };
  368. </script>
  369. <style lang="scss" scoped>
  370. .title {
  371. height: 70rpx;
  372. display: flex;
  373. justify-content: space-between;
  374. align-items: center;
  375. border-bottom: 1rpx solid #eeeeee;
  376. .title_name {
  377. font-size: 24rpx;
  378. font-weight: 500;
  379. color: #333333;
  380. white-space: nowrap;
  381. overflow: hidden;
  382. text-overflow: ellipsis;
  383. }
  384. .icon_up {
  385. width: 24rpx;
  386. height: 24rpx;
  387. }
  388. .title_status {
  389. width: 80rpx;
  390. height: 28rpx;
  391. border-radius: 8rpx;
  392. font-size: 20rpx;
  393. color: #ffffff;
  394. text-align: center;
  395. }
  396. .gre {
  397. background: #34c759;
  398. }
  399. .blue {
  400. background: #409eff;
  401. }
  402. .grey {
  403. background: #909399;
  404. }
  405. }
  406. .examBox {
  407. display: flex;
  408. align-items: center;
  409. justify-content: space-between;
  410. .exam {
  411. font-size: 30rpx;
  412. display: flex;
  413. align-items: center;
  414. margin: 20rpx 0;
  415. }
  416. .eTag {
  417. width: 64rpx;
  418. height: 36rpx;
  419. text-align: center;
  420. line-height: 36rpx;
  421. font-size: 20rpx;
  422. background: #007aff;
  423. border-radius: 8rpx;
  424. color: #ffffff;
  425. }
  426. }
  427. .tagRe {
  428. // width: 80rpx;
  429. line-height: 28rpx;
  430. padding: 0 8rpx;
  431. height: 28rpx;
  432. background: #ff3b30;
  433. border-radius: 8rpx;
  434. font-size: 20rpx;
  435. color: #ffffff;
  436. text-align: center;
  437. }
  438. .tagGreen {
  439. width: 80rpx;
  440. height: 28rpx;
  441. background: #34c759;
  442. border-radius: 8rpx;
  443. font-size: 20rpx;
  444. color: #ffffff;
  445. text-align: center;
  446. }
  447. </style>