courseChapter.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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-if="!down">
  9. <view v-for="(itemM,indexM) in list" :key="indexM">
  10. <view v-if="itemM.type!=2">
  11. <courseSection :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 } from 'vuex';
  37. import courseSection from '@/components/course/courseSection.vue';
  38. export default {
  39. name: 'courseChapter',
  40. props: {
  41. learningOrder:{ //是否设置学习顺序 0 设置 1不设置
  42. type:Number,
  43. default:1
  44. },
  45. menuItem: {
  46. type: Object,
  47. default: {}
  48. },
  49. isBuy: {
  50. type: Boolean,
  51. default: false
  52. },
  53. levelId: {
  54. type: String,
  55. default: ""
  56. },
  57. goodsId: {
  58. type: Number,
  59. default: 0
  60. },
  61. courseId: {
  62. type: Number,
  63. default: 0
  64. },
  65. isRebuild: {
  66. type: Boolean,
  67. default: false
  68. },
  69. gradeId: {
  70. type: Number,
  71. default: 0
  72. }
  73. },
  74. components: {
  75. courseSection
  76. },
  77. data() {
  78. return {
  79. down:true,
  80. list:[],
  81. examList:{},
  82. canLearn:false, //是否全部视频看完才可以练习、测试
  83. };
  84. },
  85. onLoad() {},
  86. created() {
  87. },
  88. mounted() {
  89. },
  90. onPageShow() {
  91. if(this.isBuy) {
  92. this.refreshList({isRebuild:this.isRebuild});
  93. }
  94. },
  95. methods: {
  96. refreshList(isRebuild) {
  97. console.log(9999)
  98. let moduleId = this.menuItem.moduleId?this.menuItem.moduleId:0
  99. if(this.isRebuild){
  100. this.getReSectionList(this.menuItem.id,this.menuItem.courseId,moduleId)
  101. }else{
  102. this.getBuySectionList(this.menuItem.id,this.menuItem.courseId,moduleId)
  103. // this.getMenuExamList(item.id,item.courseId,moduleId)
  104. }
  105. this.$emit('playEnd',{isRebuild:isRebuild.isRebuild})
  106. console.log(10000)
  107. // let moduleId = this.menuItem.moduleId?this.menuItem.moduleId:0
  108. // this.getBuySectionList(this.menuItem.id,this.menuItem.courseId,moduleId)
  109. },
  110. findNextSection(index){
  111. for(let i=index+1;i<this.list.length;i++){
  112. return this.list[i];
  113. }
  114. return {}
  115. },
  116. /**
  117. * 去做题
  118. */
  119. async toDo(id,goodsId =0,moduleId = 0, chapterId = 0,item,index) {
  120. console.log(this.learningOrder)
  121. if(this.learningOrder == 0) {
  122. if(this.canLearn) {
  123. let num = await this.bankRecordDoNum(item.typeId)
  124. //有次数限制
  125. if(item.answerNum - num > 0 && item.answerNum > 0) {
  126. // this.$set(this.list[index],'doNum',(item.doNum+1))
  127. console.log(this.list[index])
  128. uni.navigateTo({
  129. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  130. })
  131. //没有答题次数限制
  132. } else if(item.answerNum == 0) {
  133. uni.navigateTo({
  134. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  135. })
  136. } else {
  137. uni.showToast({
  138. icon:'none',
  139. title:'该试卷只能答题'+item.answerNum+'次'
  140. })
  141. return;
  142. }
  143. } else {
  144. uni.showToast({
  145. icon:'none',
  146. title:'请学完视频课程再进行练习和测试'
  147. })
  148. }
  149. } else {
  150. let num = await this.bankRecordDoNum(item.typeId)
  151. //有次数限制
  152. if(item.answerNum - item.doNum > 0 && item.answerNum > 0) {
  153. // this.$set(this.list[index],'doNum',(item.doNum+1))
  154. console.log(this.list[index])
  155. uni.navigateTo({
  156. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  157. })
  158. //没有答题次数限制
  159. } else if(item.answerNum == 0) {
  160. uni.navigateTo({
  161. url:'/pages2/class/questionBank?courseId='+this.courseId+'&gradeId='+this.gradeId+'&isFromVideo=1&id='+id+'&goodsid='+goodsId+'&moduleId='+moduleId+'&chapterId='+chapterId+''
  162. })
  163. } else {
  164. uni.showToast({
  165. icon:'none',
  166. title:'该试卷只能答题'+item.answerNum+'次'
  167. })
  168. return;
  169. }
  170. }
  171. },
  172. bankRecordDoNum(examId) {
  173. return new Promise(resolve => {
  174. this.$api.bankRecordDoNum({
  175. goodsId:this.goodsId,
  176. gradeId:this.gradeId,
  177. chapterId:this.menuItem.id,
  178. courseId:this.courseId,
  179. moduleId:0,
  180. examId:examId,
  181. }).then(res => {
  182. resolve(res.data.data)
  183. })
  184. })
  185. },
  186. openChapter(item){
  187. console.log(this.menuItem)
  188. this.down = !this.down
  189. if(!this.down&&this.list.length==0){
  190. console.log(item.id,69)
  191. if(this.isBuy){
  192. let moduleId = item.moduleId?item.moduleId:0
  193. if(this.isRebuild){
  194. this.getReSectionList(item.id,item.courseId,moduleId)
  195. }else{
  196. this.getBuySectionList(item.id,item.courseId,moduleId)
  197. // this.getMenuExamList(item.id,item.courseId,moduleId)
  198. }
  199. }else{
  200. this.getSectionList(item.id)
  201. }
  202. }
  203. },
  204. getMenuExamList(chapterId,courseId,moduleId) {
  205. let self = this
  206. this.$api.menuExamList({chapterId:chapterId,courseId:courseId,moduleId:moduleId}).then(res => {
  207. if(res.data.code==200){
  208. self.examList = res.data.rows
  209. }
  210. });
  211. },
  212. getSectionList(chapterId) {
  213. let self = this
  214. this.$api.sectionList(chapterId).then(res => {
  215. if(res.data.code==200){
  216. for(let i=0;i<res.data.data.length;i++){
  217. let item = res.data.data[i]
  218. item.id = item.sectionId
  219. //判断是否试听
  220. item.tryListen = false
  221. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  222. item.tryListen = true
  223. }
  224. }
  225. let newArr = res.data.data.filter(item => {
  226. console.log(item)
  227. return item.type != 2;
  228. })
  229. this.canLearn = newArr.every(item => {
  230. console.log(item)
  231. if(item.learning == 1) {
  232. return true;
  233. } else {
  234. return false;
  235. }
  236. })
  237. self.list = res.data.data
  238. }
  239. });
  240. },
  241. getReSectionList(chapterId,courseId,moduleId) {
  242. let self = this
  243. this.$api.reSectionList({chapterId:chapterId,gradeId:this.gradeId,courseId:courseId,rebuild:1,moduleId:moduleId}).then(res => {
  244. if(res.data.code==200){
  245. for(let i=0;i<res.data.data.length;i++){
  246. let item = res.data.data[i]
  247. item.id = item.sectionId
  248. //判断是否试听
  249. item.tryListen = false
  250. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  251. item.tryListen = true
  252. }
  253. }
  254. let newArr = res.data.data.filter(item => {
  255. console.log(item)
  256. return item.type != 2;
  257. })
  258. this.canLearn = newArr.every(item => {
  259. console.log(item)
  260. if(item.learning == 1) {
  261. return true;
  262. } else {
  263. return false;
  264. }
  265. })
  266. self.list = res.data.data
  267. }
  268. });
  269. },
  270. getBuySectionList(chapterId,courseId,moduleId) {
  271. let self = this
  272. this.$api.reSectionList({chapterId:chapterId,gradeId:this.gradeId,courseId:courseId,moduleId:moduleId}).then(res => {
  273. if(res.data.code==200){
  274. for(let i=0;i<res.data.data.length;i++){
  275. let item = res.data.data[i]
  276. item.id = item.sectionId
  277. //判断是否试听
  278. item.tryListen = false
  279. if(self.goodsAuditionConfigIdList.indexOf(item.id)!==-1){
  280. item.tryListen = true
  281. }
  282. }
  283. let newArr = res.data.data.filter(item => {
  284. return item.type != 2;
  285. })
  286. this.canLearn = newArr.every(item => {
  287. console.log(item)
  288. if(item.learning == 1) {
  289. return true;
  290. } else {
  291. return false;
  292. }
  293. })
  294. self.list = res.data.data
  295. }
  296. });
  297. },
  298. },computed: { ...mapGetters(['goodsAuditionConfigIdList']) },
  299. };
  300. </script>
  301. <style scoped>
  302. .tagRe{
  303. width: 80rpx;
  304. height: 28rpx;
  305. background: #FF3B30;
  306. border-radius: 8rpx;
  307. font-size: 20rpx;
  308. color: #FFFFFF;
  309. text-align: center;
  310. }
  311. .tagGreen{
  312. width: 80rpx;
  313. height: 28rpx;
  314. background: #34C759;
  315. border-radius: 8rpx;
  316. font-size: 20rpx;
  317. color: #FFFFFF;
  318. text-align: center;
  319. }
  320. .eTag{
  321. width: 56rpx;
  322. height: 28rpx;
  323. background: #007AFF;
  324. border-radius: 8rpx;
  325. color: #FFFFFF;
  326. font-size: 20rpx;
  327. text-align: center;
  328. line-height: 28rpx;
  329. }
  330. .examBox{
  331. display: flex;
  332. align-items: center;
  333. justify-content: space-between;
  334. }
  335. .exam{
  336. display: flex;
  337. align-items: center;
  338. margin: 20rpx 0;
  339. }
  340. .icon_up{
  341. width: 24rpx;
  342. height: 24rpx;
  343. }
  344. .title{
  345. font-size: 30rpx;
  346. font-family: PingFang SC;
  347. font-weight: bold;
  348. color: #666666;
  349. white-space:nowrap;
  350. overflow:hidden;
  351. text-overflow:ellipsis;
  352. margin-bottom:30rpx;
  353. }
  354. </style>