courseChapter.vue 9.1 KB

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