courseModule.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. })
  217. .then((res) => {
  218. if (res.data.code == 200) {
  219. for (let i = 0; i < res.data.data.length; i++) {
  220. let item = res.data.data[i];
  221. item.id = item.chapterId;
  222. }
  223. this.list = res.data.data;
  224. }
  225. });
  226. },
  227. getBuyChapterList(moduleId, courseId) {
  228. // course/chapterList
  229. this.$api
  230. .reChapterList({
  231. moduleId: moduleId,
  232. gradeId: this.gradeId,
  233. courseId: courseId,
  234. })
  235. .then((res) => {
  236. if (res.data.code == 200) {
  237. for (let i = 0; i < res.data.data.length; i++) {
  238. let item = res.data.data[i];
  239. item.id = item.chapterId;
  240. item.menuType = 2;
  241. if (Object.keys(this.sectionItem).length) {
  242. item["needOpen"] =
  243. item.chapterId == this.sectionItem.chapterId ? true : false;
  244. } else {
  245. item["needOpen"] = i == 0 ? true : false;
  246. }
  247. }
  248. this.list = res.data.data;
  249. // console.log('章的列表:', this.list);
  250. }
  251. });
  252. },
  253. /**
  254. * 去做题
  255. */
  256. async toDoModuleExam(
  257. id,
  258. goodsId = 0,
  259. moduleId = 0,
  260. chapterId = 0,
  261. item,
  262. index
  263. ) {
  264. if (item.doType === 2 && item.learning == 1) {
  265. return;
  266. }
  267. let newRows = [];
  268. newRows = this.menuAllList.filter((e) => e.moduleId == moduleId);
  269. let isAllLearn = newRows.every((item) => {
  270. return item.studyStatus == 1;
  271. });
  272. if (isAllLearn) {
  273. uni.navigateTo({
  274. url:
  275. "/pages2/class/questionBank?courseId=" +
  276. this.courseId +
  277. "&gradeId=" +
  278. this.gradeId +
  279. "&isFromVideo=1&id=" +
  280. id +
  281. "&goodsid=" +
  282. goodsId +
  283. "&moduleId=" +
  284. moduleId +
  285. "&chapterId=" +
  286. chapterId +
  287. "&orderGoodsId=" +
  288. this.orderGoodsId +
  289. "&type=3" +
  290. "&learning=" +
  291. item.learning +
  292. "&isBackVideo=" +
  293. 1,
  294. });
  295. } else {
  296. uni.showToast({
  297. icon: "none",
  298. title: "请学完视频课程再进行练习和测试",
  299. });
  300. }
  301. },
  302. },
  303. computed: {
  304. ...mapGetters(["chapterOpen"]),
  305. learnStatus() {
  306. let { id, courseId } = this.menuItem;
  307. if (
  308. this.sectionItem.courseId == courseId &&
  309. this.sectionItem.moduleId == id
  310. ) {
  311. return 0;
  312. }
  313. const list = this.menuAllList.filter(
  314. (e) => e.courseId == courseId && e.moduleId == id
  315. );
  316. const isAllLearn = list.every((item) => {
  317. return item.studyStatus == 1;
  318. });
  319. return isAllLearn ? 1 : -1;
  320. },
  321. },
  322. };
  323. </script>
  324. <style lang="scss" scoped>
  325. .title {
  326. height: 70rpx;
  327. display: flex;
  328. justify-content: space-between;
  329. align-items: center;
  330. border-bottom: 1rpx solid #eeeeee;
  331. .title_name {
  332. font-size: 24rpx;
  333. font-weight: 500;
  334. color: #333333;
  335. white-space: nowrap;
  336. overflow: hidden;
  337. text-overflow: ellipsis;
  338. }
  339. .icon_up {
  340. width: 24rpx;
  341. height: 24rpx;
  342. }
  343. .title_status {
  344. width: 80rpx;
  345. height: 28rpx;
  346. border-radius: 8rpx;
  347. font-size: 20rpx;
  348. color: #ffffff;
  349. text-align: center;
  350. }
  351. .gre {
  352. background: #34c759;
  353. }
  354. .blue {
  355. background: #409eff;
  356. }
  357. .grey {
  358. background: #909399;
  359. }
  360. }
  361. .examBox {
  362. display: flex;
  363. align-items: center;
  364. justify-content: space-between;
  365. .exam {
  366. font-size: 30rpx;
  367. display: flex;
  368. align-items: center;
  369. margin: 20rpx 0;
  370. }
  371. .eTag {
  372. width: 64rpx;
  373. height: 36rpx;
  374. text-align: center;
  375. line-height: 36rpx;
  376. font-size: 20rpx;
  377. background: #007aff;
  378. border-radius: 8rpx;
  379. color: #ffffff;
  380. }
  381. }
  382. .tagRe {
  383. // width: 80rpx;
  384. line-height: 28rpx;
  385. padding: 0 8rpx;
  386. height: 28rpx;
  387. background: #ff3b30;
  388. border-radius: 8rpx;
  389. font-size: 20rpx;
  390. color: #ffffff;
  391. text-align: center;
  392. }
  393. .tagGreen {
  394. width: 80rpx;
  395. height: 28rpx;
  396. background: #34c759;
  397. border-radius: 8rpx;
  398. font-size: 20rpx;
  399. color: #ffffff;
  400. text-align: center;
  401. }
  402. </style>