courseModule.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. mounted() {
  170. // console.log('模块的needOpen:', this.needOpen, 'chapterOpen:', this.chapterOpen);
  171. if (this.needOpen && this.chapterOpen) {
  172. this.openModule(this.menuItem);
  173. }
  174. },
  175. methods: {
  176. playEnd(isRebuild) {
  177. this.$emit("playEnd", { isRebuild: isRebuild.isRebuild });
  178. },
  179. toDo(item) {
  180. this.$emit("toDo", item);
  181. },
  182. openModule(item) {
  183. this.down = !this.down;
  184. if (!this.down && this.list.length == 0) {
  185. if (this.isBuy) {
  186. if (this.isRebuild) {
  187. this.getReChapterList(item.id, item.courseId);
  188. } else {
  189. this.getBuyChapterList(item.id, item.courseId); //已购买目录
  190. }
  191. } else {
  192. this.getChapterList(item.id); //未购买目录
  193. }
  194. }
  195. },
  196. getChapterList(moduleId) {
  197. // url: '/app/common/course/chapterList/'+data,
  198. this.$api.chapterList(moduleId).then((res) => {
  199. if (res.data.code == 200) {
  200. for (let i = 0; i < res.data.data.length; i++) {
  201. let item = res.data.data[i];
  202. item.id = item.chapterId;
  203. item.menuType = 2;
  204. }
  205. this.list = res.data.data;
  206. }
  207. });
  208. },
  209. getReChapterList(moduleId, courseId) {
  210. this.$api
  211. .reChapterList({
  212. moduleId: moduleId,
  213. gradeId: this.gradeId,
  214. courseId: courseId,
  215. rebuild: 1,
  216. orderGoodsId: this.orderGoodsId
  217. })
  218. .then((res) => {
  219. if (res.data.code == 200) {
  220. for (let i = 0; i < res.data.data.length; i++) {
  221. let item = res.data.data[i];
  222. item.id = item.chapterId;
  223. }
  224. this.list = res.data.data;
  225. }
  226. });
  227. },
  228. getBuyChapterList(moduleId, courseId) {
  229. // course/chapterList
  230. this.$api
  231. .reChapterList({
  232. moduleId: moduleId,
  233. gradeId: this.gradeId,
  234. courseId: courseId,
  235. orderGoodsId: this.orderGoodsId
  236. })
  237. .then((res) => {
  238. if (res.data.code == 200) {
  239. for (let i = 0; i < res.data.data.length; i++) {
  240. let item = res.data.data[i];
  241. item.id = item.chapterId;
  242. item.menuType = 2;
  243. if (Object.keys(this.sectionItem).length) {
  244. item["needOpen"] =
  245. item.chapterId == this.sectionItem.chapterId ? true : false;
  246. } else {
  247. item["needOpen"] = i == 0 ? true : false;
  248. }
  249. }
  250. this.list = res.data.data;
  251. // console.log('章的列表:', this.list);
  252. }
  253. });
  254. },
  255. /**
  256. * 去做题
  257. */
  258. async toDoModuleExam(
  259. id,
  260. goodsId = 0,
  261. moduleId = 0,
  262. chapterId = 0,
  263. item,
  264. index
  265. ) {
  266. if (item.doType === 2 && item.learning == 1) {
  267. return;
  268. }
  269. if (this.learningOrder == 2) {
  270. let newRows = [];
  271. newRows = this.menuAllList.filter((e) => e.moduleId == moduleId);
  272. let isAllLearn = newRows.every((item) => {
  273. return item.studyStatus == 1;
  274. });
  275. if (isAllLearn) {
  276. uni.navigateTo({
  277. url:
  278. "/pages2/class/questionBank?courseId=" +
  279. this.courseId +
  280. "&gradeId=" +
  281. this.gradeId +
  282. "&isFromVideo=1&id=" +
  283. id +
  284. "&goodsid=" +
  285. goodsId +
  286. "&moduleId=" +
  287. moduleId +
  288. "&chapterId=" +
  289. chapterId +
  290. "&orderGoodsId=" +
  291. this.orderGoodsId +
  292. "&type=3" +
  293. "&learning=" +
  294. item.learning +
  295. "&isBackVideo=" +
  296. 1,
  297. });
  298. } else {
  299. uni.showToast({
  300. icon: "none",
  301. title: "请学完视频课程再进行练习和测试",
  302. });
  303. }
  304. } else {
  305. uni.navigateTo({
  306. url:
  307. "/pages2/class/questionBank?courseId=" +
  308. this.courseId +
  309. "&gradeId=" +
  310. this.gradeId +
  311. "&isFromVideo=1&id=" +
  312. id +
  313. "&goodsid=" +
  314. goodsId +
  315. "&moduleId=" +
  316. moduleId +
  317. "&chapterId=" +
  318. chapterId +
  319. "&orderGoodsId=" +
  320. this.orderGoodsId +
  321. "&type=3" +
  322. "&learning=" +
  323. item.learning +
  324. "&isBackVideo=" +
  325. 1,
  326. });
  327. }
  328. },
  329. },
  330. computed: {
  331. ...mapGetters(["chapterOpen"]),
  332. learnStatus() {
  333. let { id, courseId } = this.menuItem;
  334. if (
  335. this.sectionItem.courseId == courseId &&
  336. this.sectionItem.moduleId == id
  337. ) {
  338. return 0;
  339. }
  340. const list = this.menuAllList.filter(
  341. (e) => e.courseId == courseId && e.moduleId == id
  342. );
  343. const isAllLearn = list.every((item) => {
  344. return item.studyStatus == 1;
  345. });
  346. return isAllLearn ? 1 : -1;
  347. },
  348. },
  349. };
  350. </script>
  351. <style lang="scss" scoped>
  352. .title {
  353. height: 70rpx;
  354. display: flex;
  355. justify-content: space-between;
  356. align-items: center;
  357. border-bottom: 1rpx solid #eeeeee;
  358. .title_name {
  359. font-size: 24rpx;
  360. font-weight: 500;
  361. color: #333333;
  362. white-space: nowrap;
  363. overflow: hidden;
  364. text-overflow: ellipsis;
  365. }
  366. .icon_up {
  367. width: 24rpx;
  368. height: 24rpx;
  369. }
  370. .title_status {
  371. width: 80rpx;
  372. height: 28rpx;
  373. border-radius: 8rpx;
  374. font-size: 20rpx;
  375. color: #ffffff;
  376. text-align: center;
  377. }
  378. .gre {
  379. background: #34c759;
  380. }
  381. .blue {
  382. background: #409eff;
  383. }
  384. .grey {
  385. background: #909399;
  386. }
  387. }
  388. .examBox {
  389. display: flex;
  390. align-items: center;
  391. justify-content: space-between;
  392. .exam {
  393. font-size: 30rpx;
  394. display: flex;
  395. align-items: center;
  396. margin: 20rpx 0;
  397. }
  398. .eTag {
  399. width: 64rpx;
  400. height: 36rpx;
  401. text-align: center;
  402. line-height: 36rpx;
  403. font-size: 20rpx;
  404. background: #007aff;
  405. border-radius: 8rpx;
  406. color: #ffffff;
  407. }
  408. }
  409. .tagRe {
  410. // width: 80rpx;
  411. line-height: 28rpx;
  412. padding: 0 8rpx;
  413. height: 28rpx;
  414. background: #ff3b30;
  415. border-radius: 8rpx;
  416. font-size: 20rpx;
  417. color: #ffffff;
  418. text-align: center;
  419. }
  420. .tagGreen {
  421. width: 80rpx;
  422. height: 28rpx;
  423. background: #34c759;
  424. border-radius: 8rpx;
  425. font-size: 20rpx;
  426. color: #ffffff;
  427. text-align: center;
  428. }
  429. </style>