courseModule.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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;">{{menuItem.name}}</text>
  6. <view>
  7. <image src="/static/icon/up.png" class="icon_up" v-if="down"></image>
  8. <image src="/static/icon/down.png" class="icon_up" v-if="!down"></image>
  9. </view>
  10. </view>
  11. <view v-show="!down">
  12. <view v-for="(itemM,indexM) in list" :key="indexM">
  13. <!-- v-if='itemM.type != 2' -->
  14. <courseChapter v-if='itemM.type != 2' :orderGoodsId="orderGoodsId"
  15. :isLive="isLive" :preItem="list[indexM - 1] || preItem" :sectionMaxNum="sectionMaxNum" :needOpen="itemM.needOpen" @playEnd="playEnd($event)"
  16. @toDo="toDo($event)" :courseId="courseId" :learningOrder="learningOrder" :goodsId="goodsId" :isBuy="isBuy" :gradeId="gradeId"
  17. :isRebuild="isRebuild" :menuItem="itemM" :levelId="levelId+'-'+itemM.chapterId" :menuAllList="menuAllList">
  18. </courseChapter>
  19. <u-line v-if="indexM<list.length-1"></u-line>
  20. <!-- 模块卷 -->
  21. <view v-if="itemM.type == 2">
  22. <view
  23. class="examBox"
  24. @click="
  25. toDoModuleExam(
  26. itemM.typeId,
  27. goodsId,
  28. itemM.moduleId,
  29. itemM.chapterId,
  30. itemM,
  31. indexM
  32. )
  33. "
  34. >
  35. <view class="exam">
  36. <view class="eTag">{{
  37. itemM.doType == 1 ? "练习" : "考试"
  38. }}</view>
  39. <view style="margin-left: 15rpx; flex: 1">{{ itemM.name }}</view>
  40. </view>
  41. <view>
  42. <view
  43. :class="{
  44. tagGreen: itemM.learning == 1,
  45. tagRe: itemM.learning == 0 || itemM.rebuild > 0,
  46. }"
  47. >
  48. <text v-if="itemM.learning == 1">合格</text>
  49. <text v-else-if="itemM.learning == 0">不合格</text>
  50. <!-- <text v-else>不合格</text> -->
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import { mapGetters } from "vuex";
  61. import courseChapter from "@/components/course/courseChapter.vue";
  62. export default {
  63. name: 'courseModule',
  64. props: {
  65. isLive:false,
  66. orderGoodsId:{
  67. default:0
  68. },
  69. preItem:{
  70. default:undefined
  71. },
  72. learningOrder:{ //是否设置学习顺序 1 章节顺序 0不设置 2从头学到尾顺序
  73. type:Number,
  74. defaule:0
  75. },
  76. needOpen:{ //是否默认展开
  77. type:Boolean,
  78. default:false,
  79. },
  80. menuItem: {
  81. type: Object,
  82. default: {}
  83. },
  84. goodsId: {
  85. type: Number,
  86. default: 0
  87. },
  88. courseId: {
  89. type: Number,
  90. default: 0
  91. },
  92. isBuy: { //是否是已购买商品
  93. type: Boolean,
  94. default: false
  95. },
  96. levelId: {
  97. type: String,
  98. default: ""
  99. },
  100. isRebuild: { //是否重修目录
  101. type: Boolean,
  102. default: false
  103. },
  104. gradeId: { //重修需要班级ID
  105. type: Number,
  106. default: 0
  107. },
  108. sectionMaxNum:{
  109. default:undefined
  110. },
  111. // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  112. goodsType: {
  113. type: [Number, String],
  114. default: 0,
  115. },
  116. menuAllList: { // 课程所有子目录结构列表
  117. type: Array,
  118. default: () => []
  119. },
  120. sectionItem: { // 用户最后一次看的录播的信息
  121. type: Object,
  122. default: () => {}
  123. },
  124. },
  125. components: {
  126. courseChapter
  127. },
  128. data() {
  129. return {
  130. down:true,
  131. list:[],
  132. };
  133. },
  134. mounted() {
  135. console.log('模块的needOpen:', this.needOpen, 'chapterOpen:', this.chapterOpen);
  136. if(this.needOpen && this.chapterOpen) {
  137. this.openModule(this.menuItem)
  138. }
  139. uni.$off('openEmit')
  140. uni.$once('openEmit', (data) => {
  141. console.log('------木块-data:', data);
  142. if (data.moduleId && data.moduleId > 0) {
  143. this.openModule(data)
  144. }
  145. })
  146. },
  147. methods: {
  148. playEnd(isRebuild) {
  149. this.$emit('playEnd',{isRebuild:isRebuild.isRebuild})
  150. },
  151. toDo(item) {
  152. this.$emit('toDo',item)
  153. },
  154. openModule(item){
  155. console.log('打kai模块');
  156. this.down = !this.down
  157. if(!this.down&&this.list.length==0){
  158. if(this.isBuy){
  159. if(this.isRebuild){
  160. this.getReChapterList(item.id,item.courseId)
  161. }else{
  162. this.getBuyChapterList(item.id,item.courseId) //已购买目录
  163. }
  164. }else{
  165. this.getChapterList(item.id) //未购买目录
  166. }
  167. }
  168. },
  169. getChapterList(moduleId) {
  170. // url: '/app/common/course/chapterList/'+data,
  171. this.$api.chapterList(moduleId).then(res => {
  172. if(res.data.code==200){
  173. for(let i=0;i<res.data.data.length;i++){
  174. let item = res.data.data[i]
  175. item.id = item.chapterId
  176. item.menuType = 2;
  177. }
  178. this.list = res.data.data
  179. }
  180. });
  181. },
  182. getReChapterList(moduleId,courseId) {
  183. this.$api.reChapterList({moduleId:moduleId,gradeId:this.gradeId,courseId:courseId,rebuild:1}).then(res => {
  184. if(res.data.code==200){
  185. for(let i=0;i<res.data.data.length;i++){
  186. let item = res.data.data[i]
  187. item.id = item.chapterId
  188. }
  189. this.list = res.data.data
  190. }
  191. });
  192. },
  193. getBuyChapterList(moduleId,courseId) {
  194. // course/chapterList
  195. this.$api.reChapterList({moduleId:moduleId,gradeId:this.gradeId,courseId:courseId}).then(res => {
  196. if(res.data.code==200){
  197. for(let i=0;i<res.data.data.length;i++){
  198. let item = res.data.data[i]
  199. item.id = item.chapterId
  200. item.menuType = 2;
  201. if (Object.keys(this.sectionItem).length) {
  202. item['needOpen'] = item.chapterId == this.sectionItem.chapterId ? true : false
  203. } else {
  204. item['needOpen'] = i == 0 ? true : false
  205. }
  206. }
  207. this.list = res.data.data
  208. console.log('章的列表:', this.list);
  209. }
  210. });
  211. },
  212. /**
  213. * 去做题
  214. */
  215. async toDoModuleExam(id, goodsId = 0, moduleId = 0, chapterId = 0, item, index) {
  216. // console.log('===item', item, this.menuAllList);
  217. let newRows = []
  218. newRows = this.menuAllList.filter(e => e.moduleId == moduleId)
  219. let isAllLearn = newRows.every(item => {
  220. return item.studyStatus == 1
  221. })
  222. if (isAllLearn) {
  223. uni.navigateTo({
  224. url:
  225. "/pages2/class/questionBank?courseId=" +
  226. this.courseId +
  227. "&gradeId=" +
  228. this.gradeId +
  229. "&isFromVideo=1&id=" +
  230. id +
  231. "&goodsid=" +
  232. goodsId +
  233. "&moduleId=" +
  234. moduleId +
  235. "&chapterId=" +
  236. chapterId +
  237. "&orderGoodsId=" +
  238. this.orderGoodsId +
  239. "&type=3" + '&learning=' + item.learning,
  240. })
  241. } else {
  242. uni.showToast({
  243. icon: "none",
  244. title: "请学完视频课程再进行练习和测试",
  245. })
  246. }
  247. },
  248. },
  249. computed: { ...mapGetters(['chapterOpen']) },
  250. };
  251. </script>
  252. <style lang="scss" scoped>
  253. .title{
  254. height: 70rpx;
  255. display: flex;
  256. justify-content: space-between;
  257. align-items: center;
  258. border-bottom: 1rpx solid #EEEEEE;
  259. .title_name {
  260. font-size: 24rpx;
  261. font-weight: 500;
  262. color: #333333;
  263. white-space:nowrap;
  264. overflow:hidden;
  265. text-overflow:ellipsis;
  266. }
  267. .icon_up{
  268. width: 24rpx;
  269. height: 24rpx;
  270. }
  271. }
  272. .examBox {
  273. display: flex;
  274. align-items: center;
  275. justify-content: space-between;
  276. .exam {
  277. font-size: 30rpx;
  278. display: flex;
  279. align-items: center;
  280. margin: 20rpx 0;
  281. }
  282. .eTag {
  283. width: 64rpx;
  284. height: 36rpx;
  285. text-align: center;
  286. line-height: 36rpx;
  287. font-size: 20rpx;
  288. background: #007aff;
  289. border-radius: 8rpx;
  290. color: #ffffff;
  291. }
  292. }
  293. .tagRe {
  294. width: 80rpx;
  295. height: 28rpx;
  296. background: #ff3b30;
  297. border-radius: 8rpx;
  298. font-size: 20rpx;
  299. color: #ffffff;
  300. text-align: center;
  301. }
  302. .tagGreen {
  303. width: 80rpx;
  304. height: 28rpx;
  305. background: #34c759;
  306. border-radius: 8rpx;
  307. font-size: 20rpx;
  308. color: #ffffff;
  309. text-align: center;
  310. }
  311. </style>