courseChapter.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <view style="margin: 20rpx 0;">
  3. <view class="title" @click="openChapter(menuItem)">
  4. <image src="/static/icon/up1.png" class="icon_up" v-if="down"></image>
  5. <image src="/static/icon/down1.png" class="icon_up" v-if="!down"></image>
  6. <text style="margin-left: 30rpx;">{{menuItem.name}}</text>
  7. </view>
  8. <view v-show="!down">
  9. <view v-for="(itemM,indexM) in list" :key="indexM">
  10. <view v-if="itemM.type!=2">
  11. <courseSection :sectionMaxNum="sectionMaxNum" :preItem="list[indexM-1] || preItem" :learningOrder="learningOrder" :courseId="courseId" @playEnd="refreshList($event)" :goodsId="goodsId" :isBuy="isBuy" :nextMenuItem="findNextSection(indexM)" :isRebuild="isRebuild" :gradeId="gradeId" :menuItem="itemM" :levelId="levelId+'-'+itemM.sectionId"></courseSection>
  12. <u-line v-if="indexM<list.length-1"></u-line>
  13. </view>
  14. <view v-if="itemM.type==2">
  15. <u-line ></u-line>
  16. <view class="examBox" @click="toDo(itemM.typeId,goodsId,itemM.moduleId,itemM.chapterId,itemM,indexM)">
  17. <view class="exam">
  18. <view class="eTag">{{itemM.doType==1?'练习':'考试'}}</view>
  19. <view style="margin-left: 15rpx;">{{itemM.name}}</view>
  20. </view>
  21. <view v-if="isRebuild||itemM.rebuild>0" class="tagRe">待重修</view>
  22. <view v-else>
  23. <view :class="{tagGreen:itemM.learning == 1,tagRe:itemM.learning == 0 || itemM.rebuild>0}">
  24. <text v-if="itemM.rebuild > 0">待重测</text>
  25. <text v-else-if="itemM.learning == 1">合格</text>
  26. <text v-else-if="itemM.learning == 0">不合格</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { mapGetters,mapMutations } from 'vuex';
  37. import courseSection from '@/components/course/courseSection.vue';
  38. export default {
  39. name: 'courseChapter',
  40. props: {
  41. preItem:{
  42. default:undefined
  43. },
  44. learningOrder:{ //是否设置学习顺序 1 章节顺序 0不设置 2从头学到尾顺序
  45. type:Number,
  46. default:0
  47. },
  48. needOpen:{ //是否默认展开
  49. type:Boolean,
  50. default:false,
  51. },
  52. menuItem: {
  53. type: Object,
  54. default: {}
  55. },
  56. isBuy: {
  57. type: Boolean,
  58. default: false
  59. },
  60. levelId: {
  61. type: String,
  62. default: ""
  63. },
  64. goodsId: {
  65. type: Number,
  66. default: 0
  67. },
  68. courseId: {
  69. type: Number,
  70. default: 0
  71. },
  72. isRebuild: {
  73. type: Boolean,
  74. default: false
  75. },
  76. gradeId: {
  77. type: Number,
  78. default: 0
  79. },
  80. sectionMaxNum:{
  81. default:undefined
  82. }
  83. },
  84. components: {
  85. courseSection
  86. },
  87. data() {
  88. return {
  89. down:true,
  90. list:[],
  91. examList:{},
  92. canLearn:false, //是否全部视频看完才可以练习、测试
  93. };
  94. },
  95. onLoad() {},
  96. created() {
  97. },
  98. mounted() {
  99. if(this.needOpen && this.chapterOpen) {
  100. this.updateChapterOpen(false)
  101. this.openChapter(this.menuItem)
  102. }
  103. },
  104. onPageShow() {
  105. if(this.isBuy) {
  106. this.refreshList({isRebuild:this.isRebuild});
  107. }
  108. },
  109. methods: {
  110. ...mapMutations(['updateChapterOpen']),
  111. goodsTodayStudySectionNum() {
  112. return new Promise(resolve => {
  113. this.$api.goodsTodayStudySectionNum({goodsId:this.goodsId,gradeId:this.gradeId}).then(res => {
  114. if(res.data.code == 200) {
  115. resolve(res.data.data)
  116. }
  117. })
  118. })
  119. },
  120. refreshList(isRebuild) {
  121. console.log(9999)
  122. let moduleId = this.menuItem.moduleId?this.menuItem.moduleId:0
  123. if(this.isRebuild){
  124. this.getReSectionList(this.menuItem.id,this.menuItem.courseId,moduleId)
  125. }else{
  126. this.getBuySectionList(this.menuItem.id,this.menuItem.courseId,moduleId)
  127. // this.getMenuExamList(item.id,item.courseId,moduleId)
  128. }
  129. this.$emit('playEnd',{isRebuild:isRebuild.isRebuild})
  130. console.log(10000)
  131. // let moduleId = this.menuItem.moduleId?this.menuItem.moduleId:0
  132. // this.getBuySectionList(this.menuItem.id,this.menuItem.courseId,moduleId)
  133. },
  134. findNextSection(index){
  135. for(let i=index+1;i<this.list.length;i++){
  136. return this.list[i];
  137. }
  138. return {}
  139. },
  140. /**
  141. * 去做题
  142. */
  143. async toDo(id,goodsId =0,moduleId = 0, chapterId = 0,item,index) {
  144. // let learnNum = await this.goodsTodayStudySectionNum()
  145. // if(this.sectionMaxNum > 0) {
  146. // if(learnNum >= this.sectionMaxNum) {
  147. // uni.showToast({
  148. // icon:'none',
  149. // title:`每天最多学习${this.sectionMaxNum}节`
  150. // })
  151. // return;
  152. // }
  153. // }
  154. console.log(this.learningOrder,'this.learningOrder')
  155. if(this.learningOrder == 1) {
  156. if(this.canLearn) {
  157. let num = await this.bankRecordDoNum(item.typeId)
  158. //有次数限制
  159. if(item.answerNum - num > 0 && item.answerNum > 0) {
  160. // this.$set(this.list[index],'doNum',(item.doNum+1))
  161. console.log(this.list[index])
  162. uni.navigateTo({
  163. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  164. })
  165. //没有答题次数限制
  166. } else if(item.answerNum == 0) {
  167. uni.navigateTo({
  168. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  169. })
  170. } else {
  171. uni.showToast({
  172. icon:'none',
  173. title:'该试卷只能答题'+item.answerNum+'次'
  174. })
  175. return;
  176. }
  177. } else {
  178. uni.showToast({
  179. icon:'none',
  180. title:'请按顺序学完视频课程再进行练习和测试'
  181. })
  182. }
  183. } else if(this.learningOrder == 2 && !item.rebuild) {
  184. let canLearn = this.list[index-1].learning == 1;
  185. if(canLearn) { //视频的上一节学完
  186. let num = await this.bankRecordDoNum(item.typeId)
  187. //有次数限制
  188. if(item.answerNum - num > 0 && item.answerNum > 0) {
  189. // this.$set(this.list[index],'doNum',(item.doNum+1))
  190. console.log(this.list[index])
  191. uni.navigateTo({
  192. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  193. })
  194. //没有答题次数限制
  195. } else if(item.answerNum == 0) {
  196. uni.navigateTo({
  197. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  198. })
  199. } else {
  200. uni.showToast({
  201. icon:'none',
  202. title:'该试卷只能答题'+item.answerNum+'次'
  203. })
  204. return;
  205. }
  206. } else {
  207. uni.showToast({
  208. icon:'none',
  209. title:'请学完视频课程再进行练习和测试'
  210. })
  211. }
  212. } else {
  213. let num = await this.bankRecordDoNum(item.typeId)
  214. //有次数限制
  215. if(item.answerNum - item.doNum > 0 && item.answerNum > 0) {
  216. // this.$set(this.list[index],'doNum',(item.doNum+1))
  217. console.log(this.list[index])
  218. uni.navigateTo({
  219. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  220. })
  221. //没有答题次数限制
  222. } else if(item.answerNum == 0) {
  223. uni.navigateTo({
  224. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  225. })
  226. } else {
  227. uni.showToast({
  228. icon:'none',
  229. title:'该试卷只能答题'+item.answerNum+'次'
  230. })
  231. return;
  232. }
  233. }
  234. },
  235. bankRecordDoNum(examId) {
  236. return new Promise(resolve => {
  237. this.$api.bankRecordDoNum({
  238. goodsId:this.goodsId,
  239. gradeId:this.gradeId,
  240. chapterId:this.menuItem.id,
  241. courseId:this.courseId,
  242. moduleId:0,
  243. examId:examId,
  244. }).then(res => {
  245. resolve(res.data.data)
  246. })
  247. })
  248. },
  249. openChapter(item){
  250. console.log(this.menuItem)
  251. this.down = !this.down
  252. if(!this.down&&this.list.length==0){
  253. console.log(item.id,69)
  254. if(this.isBuy){
  255. let moduleId = item.moduleId?item.moduleId:0
  256. if(this.isRebuild){
  257. this.getReSectionList(item.id,item.courseId,moduleId)
  258. }else{
  259. this.getBuySectionList(item.id,item.courseId,moduleId)
  260. // this.getMenuExamList(item.id,item.courseId,moduleId)
  261. }
  262. }else{
  263. this.getSectionList(item.id)
  264. }
  265. }
  266. },
  267. getMenuExamList(chapterId,courseId,moduleId) {
  268. let self = this
  269. this.$api.menuExamList({chapterId:chapterId,courseId:courseId,moduleId:moduleId}).then(res => {
  270. if(res.data.code==200){
  271. self.examList = res.data.rows
  272. }
  273. });
  274. },
  275. getSectionList(chapterId) {
  276. let self = this
  277. this.$api.sectionList(chapterId).then(res => {
  278. if(res.data.code==200){
  279. for(let i=0;i<res.data.data.length;i++){
  280. let item = res.data.data[i]
  281. item.id = item.sectionId
  282. item.menuType = 3;
  283. //判断是否试听
  284. item.tryListen = false
  285. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  286. item.tryListen = true
  287. }
  288. }
  289. let newArr = res.data.data.filter(item => {
  290. console.log(item)
  291. return item.type != 2;
  292. })
  293. this.canLearn = newArr.every(item => {
  294. console.log(item)
  295. if(item.learning == 1) {
  296. return true;
  297. } else {
  298. return false;
  299. }
  300. })
  301. self.list = res.data.data
  302. }
  303. });
  304. },
  305. getReSectionList(chapterId,courseId,moduleId) {
  306. let self = this
  307. this.$api.reSectionList({chapterId:chapterId,gradeId:this.gradeId,courseId:courseId,rebuild:1,moduleId:moduleId}).then(res => {
  308. if(res.data.code==200){
  309. for(let i=0;i<res.data.data.length;i++){
  310. let item = res.data.data[i]
  311. item.id = item.sectionId
  312. item.menuType = 3;
  313. //判断是否试听
  314. item.tryListen = false
  315. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  316. item.tryListen = true
  317. }
  318. }
  319. let newArr = res.data.data.filter(item => {
  320. console.log(item)
  321. return item.type != 2;
  322. })
  323. this.canLearn = newArr.every(item => {
  324. console.log(item)
  325. if(item.learning == 1) {
  326. return true;
  327. } else {
  328. return false;
  329. }
  330. })
  331. self.list = res.data.data
  332. }
  333. });
  334. },
  335. getBuySectionList(chapterId,courseId,moduleId) {
  336. let self = this
  337. this.$api.reSectionList({chapterId:chapterId,gradeId:this.gradeId,courseId:courseId,moduleId:moduleId}).then(res => {
  338. if(res.data.code==200){
  339. for(let i=0;i<res.data.data.length;i++){
  340. let item = res.data.data[i]
  341. item.id = item.sectionId
  342. item.menuType = 3;
  343. //判断是否试听
  344. item.tryListen = false
  345. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  346. item.tryListen = true
  347. }
  348. }
  349. let newArr = res.data.data.filter(item => {
  350. return item.type != 2;
  351. })
  352. this.canLearn = newArr.every(item => {
  353. console.log(item)
  354. if(item.learning == 1) {
  355. return true;
  356. } else {
  357. return false;
  358. }
  359. })
  360. self.list = res.data.data
  361. }
  362. });
  363. },
  364. },computed: { ...mapGetters(['goodsAuditionConfigIdList','chapterOpen']) },
  365. };
  366. </script>
  367. <style scoped>
  368. .tagRe{
  369. width: 80rpx;
  370. height: 28rpx;
  371. background: #FF3B30;
  372. border-radius: 8rpx;
  373. font-size: 20rpx;
  374. color: #FFFFFF;
  375. text-align: center;
  376. }
  377. .tagGreen{
  378. width: 80rpx;
  379. height: 28rpx;
  380. background: #34C759;
  381. border-radius: 8rpx;
  382. font-size: 20rpx;
  383. color: #FFFFFF;
  384. text-align: center;
  385. }
  386. .eTag{
  387. width: 56rpx;
  388. height: 28rpx;
  389. background: #007AFF;
  390. border-radius: 8rpx;
  391. color: #FFFFFF;
  392. font-size: 20rpx;
  393. text-align: center;
  394. line-height: 28rpx;
  395. }
  396. .examBox{
  397. display: flex;
  398. align-items: center;
  399. justify-content: space-between;
  400. }
  401. .exam{
  402. display: flex;
  403. align-items: center;
  404. margin: 20rpx 0;
  405. }
  406. .icon_up{
  407. width: 24rpx;
  408. height: 24rpx;
  409. }
  410. .title{
  411. font-size: 30rpx;
  412. font-family: PingFang SC;
  413. font-weight: bold;
  414. color: #666666;
  415. white-space:nowrap;
  416. overflow:hidden;
  417. text-overflow:ellipsis;
  418. margin-bottom:30rpx;
  419. }
  420. </style>