courseChapter.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. studyRecordMenuAllList() {
  141. return new Promise(resolve => {
  142. this.$api.studyRecordMenuAllList({
  143. courseId:this.courseId,
  144. gradeId:this.gradeId,
  145. goodsId:this.goodsId
  146. }).then(res => {
  147. if(res.data.code == 200) {
  148. resolve(res.data.data)
  149. }
  150. })
  151. })
  152. },
  153. /**
  154. * 去做题
  155. */
  156. async toDo(id,goodsId =0,moduleId = 0, chapterId = 0,item,index) {
  157. // let learnNum = await this.goodsTodayStudySectionNum()
  158. // if(this.sectionMaxNum > 0) {
  159. // if(learnNum >= this.sectionMaxNum) {
  160. // uni.showToast({
  161. // icon:'none',
  162. // title:`每天最多学习${this.sectionMaxNum}节`
  163. // })
  164. // return;
  165. // }
  166. // }
  167. console.log(this.learningOrder,'this.learningOrder')
  168. if(this.learningOrder == 1) {
  169. if(this.canLearn) {
  170. let num = await this.bankRecordDoNum(item.typeId)
  171. //有次数限制
  172. if(item.answerNum - num > 0 && item.answerNum > 0) {
  173. // this.$set(this.list[index],'doNum',(item.doNum+1))
  174. console.log(this.list[index])
  175. uni.navigateTo({
  176. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  177. })
  178. //没有答题次数限制
  179. } else if(item.answerNum == 0) {
  180. uni.navigateTo({
  181. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  182. })
  183. } else {
  184. uni.showToast({
  185. icon:'none',
  186. title:'该试卷只能答题'+item.answerNum+'次'
  187. })
  188. return;
  189. }
  190. } else {
  191. uni.showToast({
  192. icon:'none',
  193. title:'请按顺序学完视频课程再进行练习和测试'
  194. })
  195. }
  196. } else if(this.learningOrder == 2 && !item.rebuild) {
  197. let canLearn = this.list[index-1].learning == 1;
  198. let rows = await this.studyRecordMenuAllList();
  199. let isStop = false;
  200. let newRows = [];
  201. for(let i = 0; i < rows.length; i++ ) {
  202. let moduleTrue = rows[i].moduleId == moduleId;
  203. let chapterTrue = rows[i].chapterId == chapterId;
  204. if(moduleTrue && chapterTrue) {
  205. isStop = true;
  206. if(rows[i].sectionType != 2) {
  207. newRows.push(rows[i])
  208. }
  209. } else {
  210. if(!isStop) {
  211. if(rows[i].sectionType != 2) {
  212. newRows.push(rows[i])
  213. }
  214. } else {
  215. break;
  216. }
  217. }
  218. }
  219. console.log(newRows)
  220. let isAllLearn = newRows.every(item => {
  221. return item.studyStatus == 1;
  222. })
  223. if(isAllLearn) { //之前的都学完了
  224. // if(canLearn) { //视频的上一节学完
  225. let num = await this.bankRecordDoNum(item.typeId)
  226. //有次数限制
  227. if(item.answerNum - num > 0 && item.answerNum > 0) {
  228. // this.$set(this.list[index],'doNum',(item.doNum+1))
  229. console.log(this.list[index])
  230. uni.navigateTo({
  231. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  232. })
  233. //没有答题次数限制
  234. } else if(item.answerNum == 0) {
  235. uni.navigateTo({
  236. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  237. })
  238. } else {
  239. uni.showToast({
  240. icon:'none',
  241. title:'该试卷只能答题'+item.answerNum+'次'
  242. })
  243. return;
  244. }
  245. } else {
  246. uni.showToast({
  247. icon:'none',
  248. title:'请学完视频课程再进行练习和测试'
  249. })
  250. }
  251. } else {
  252. let num = await this.bankRecordDoNum(item.typeId)
  253. //有次数限制
  254. if(item.answerNum - item.doNum > 0 && item.answerNum > 0) {
  255. // this.$set(this.list[index],'doNum',(item.doNum+1))
  256. console.log(this.list[index])
  257. uni.navigateTo({
  258. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  259. })
  260. //没有答题次数限制
  261. } else if(item.answerNum == 0) {
  262. uni.navigateTo({
  263. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  264. })
  265. } else {
  266. uni.showToast({
  267. icon:'none',
  268. title:'该试卷只能答题'+item.answerNum+'次'
  269. })
  270. return;
  271. }
  272. }
  273. },
  274. bankRecordDoNum(examId) {
  275. return new Promise(resolve => {
  276. this.$api.bankRecordDoNum({
  277. goodsId:this.goodsId,
  278. gradeId:this.gradeId,
  279. chapterId:this.menuItem.id,
  280. courseId:this.courseId,
  281. moduleId:0,
  282. examId:examId,
  283. }).then(res => {
  284. resolve(res.data.data)
  285. })
  286. })
  287. },
  288. openChapter(item){
  289. console.log(this.menuItem)
  290. this.down = !this.down
  291. if(!this.down&&this.list.length==0){
  292. console.log(item.id,69)
  293. if(this.isBuy){
  294. let moduleId = item.moduleId?item.moduleId:0
  295. if(this.isRebuild){
  296. this.getReSectionList(item.id,item.courseId,moduleId)
  297. }else{
  298. this.getBuySectionList(item.id,item.courseId,moduleId)
  299. // this.getMenuExamList(item.id,item.courseId,moduleId)
  300. }
  301. }else{
  302. this.getSectionList(item.id)
  303. }
  304. }
  305. },
  306. getMenuExamList(chapterId,courseId,moduleId) {
  307. let self = this
  308. this.$api.menuExamList({chapterId:chapterId,courseId:courseId,moduleId:moduleId}).then(res => {
  309. if(res.data.code==200){
  310. self.examList = res.data.rows
  311. }
  312. });
  313. },
  314. getSectionList(chapterId) {
  315. let self = this
  316. this.$api.sectionList(chapterId).then(res => {
  317. if(res.data.code==200){
  318. for(let i=0;i<res.data.data.length;i++){
  319. let item = res.data.data[i]
  320. item.id = item.sectionId
  321. item.menuType = 3;
  322. //判断是否试听
  323. item.tryListen = false
  324. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  325. item.tryListen = true
  326. }
  327. }
  328. let newArr = res.data.data.filter(item => {
  329. console.log(item)
  330. return item.type != 2;
  331. })
  332. this.canLearn = newArr.every(item => {
  333. console.log(item)
  334. if(item.learning == 1) {
  335. return true;
  336. } else {
  337. return false;
  338. }
  339. })
  340. self.list = res.data.data
  341. }
  342. });
  343. },
  344. getReSectionList(chapterId,courseId,moduleId) {
  345. let self = this
  346. this.$api.reSectionList({chapterId:chapterId,gradeId:this.gradeId,courseId:courseId,rebuild:1,moduleId:moduleId}).then(res => {
  347. if(res.data.code==200){
  348. for(let i=0;i<res.data.data.length;i++){
  349. let item = res.data.data[i]
  350. item.id = item.sectionId
  351. item.menuType = 3;
  352. //判断是否试听
  353. item.tryListen = false
  354. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  355. item.tryListen = true
  356. }
  357. }
  358. let newArr = res.data.data.filter(item => {
  359. console.log(item)
  360. return item.type != 2;
  361. })
  362. this.canLearn = newArr.every(item => {
  363. console.log(item)
  364. if(item.learning == 1) {
  365. return true;
  366. } else {
  367. return false;
  368. }
  369. })
  370. self.list = res.data.data
  371. }
  372. });
  373. },
  374. getBuySectionList(chapterId,courseId,moduleId) {
  375. let self = this
  376. this.$api.reSectionList({chapterId:chapterId,gradeId:this.gradeId,courseId:courseId,moduleId:moduleId}).then(res => {
  377. if(res.data.code==200){
  378. for(let i=0;i<res.data.data.length;i++){
  379. let item = res.data.data[i]
  380. item.id = item.sectionId
  381. item.menuType = 3;
  382. //判断是否试听
  383. item.tryListen = false
  384. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  385. item.tryListen = true
  386. }
  387. }
  388. let newArr = res.data.data.filter(item => {
  389. return item.type != 2;
  390. })
  391. this.canLearn = newArr.every(item => {
  392. console.log(item)
  393. if(item.learning == 1) {
  394. return true;
  395. } else {
  396. return false;
  397. }
  398. })
  399. self.list = res.data.data
  400. }
  401. });
  402. },
  403. },computed: { ...mapGetters(['goodsAuditionConfigIdList','chapterOpen']) },
  404. };
  405. </script>
  406. <style scoped>
  407. .tagRe{
  408. width: 80rpx;
  409. height: 28rpx;
  410. background: #FF3B30;
  411. border-radius: 8rpx;
  412. font-size: 20rpx;
  413. color: #FFFFFF;
  414. text-align: center;
  415. }
  416. .tagGreen{
  417. width: 80rpx;
  418. height: 28rpx;
  419. background: #34C759;
  420. border-radius: 8rpx;
  421. font-size: 20rpx;
  422. color: #FFFFFF;
  423. text-align: center;
  424. }
  425. .eTag{
  426. width: 56rpx;
  427. height: 28rpx;
  428. background: #007AFF;
  429. border-radius: 8rpx;
  430. color: #FFFFFF;
  431. font-size: 20rpx;
  432. text-align: center;
  433. line-height: 28rpx;
  434. }
  435. .examBox{
  436. display: flex;
  437. align-items: center;
  438. justify-content: space-between;
  439. }
  440. .exam{
  441. display: flex;
  442. align-items: center;
  443. margin: 20rpx 0;
  444. }
  445. .icon_up{
  446. width: 24rpx;
  447. height: 24rpx;
  448. }
  449. .title{
  450. font-size: 30rpx;
  451. font-family: PingFang SC;
  452. font-weight: bold;
  453. color: #666666;
  454. white-space:nowrap;
  455. overflow:hidden;
  456. text-overflow:ellipsis;
  457. margin-bottom:30rpx;
  458. }
  459. </style>