index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view class="ezy-xuexi-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">学习</text>
  6. </view>
  7. <view class="ezy-page-body xuexi-page-body">
  8. <view class="change-dy-box">
  9. <view class="arrow-icon left-icon" :class="{ 'disabled': fontDanyuanId == 0 }" @click="prev"> </view>
  10. <!-- 显示内容 -->
  11. <view class="change-dy-content">
  12. <view>{{ danyuanInfo.danyuanName }}</view>
  13. <view>{{ danyuanInfo.danyuanIntro }}</view>
  14. </view>
  15. <view class="arrow-icon right-icon" @click="next" :class="{ 'disabled': nextDanyuanId == 0 }"> </view>
  16. </view>
  17. <view class="xx-scroll-body">
  18. <view class="xx-jd-box">
  19. <view class="xx-progress-btn-box">
  20. <view class="xx-progress-box">
  21. <view>当前学习进度</view>
  22. <progress :percent="curProcess" class="xx-progress" stroke-width="10"
  23. backgroundColor="#3c7dfd" activeColor="#ffd11c" />
  24. </view>
  25. <view class="jxxx-btn" @click="handlePlay(curJieObject,'jixu')"></view>
  26. </view>
  27. <view class="jd-item-box">
  28. <view class="jd-item-btn" @click="handleClickDanyuan">
  29. <icon class="dydg-icon"></icon>单元大纲
  30. </view>
  31. <view class="jd-item-btn" @click="handleClickMulu">
  32. <icon class="dyml-icon"></icon>单元目录
  33. </view>
  34. </view>
  35. </view>
  36. <view class="xx-item-list">
  37. <view class="xx-item-box" v-for="section in dagangList" :key="section.jieId">
  38. <view class="xx-item-status"
  39. :class="section.wanchengFlag == 1 ? 'completed-status' : 'uncompleted-status'"> </view>
  40. <img :src="section.cover" />
  41. <view class="xx-text-box">
  42. <view>{{ section.jieName }}</view>
  43. <view>{{ section.jieIntro }}</view>
  44. </view>
  45. <view @click="handlePlay(section,'play')" class="xx-item-btn"></view>
  46. </view>
  47. </view>
  48. <!-- 底部占位 -->
  49. <view v-if="currentIndex != dagangList.length - 1" class="xx-next-btn" @click="next">
  50. 学习下一单元</view>
  51. <!-- <view class="xx-xw-text">课程已学完</view> -->
  52. </view>
  53. </view>
  54. <!-- <scroll-view scroll-y class="scroll-view" :scroll-top="scrollTop" @scroll="onScroll"> </scroll-view> -->
  55. <danyuanInfoVue ref="dyRef" v-if="isShow" @close="isShow= false"></danyuanInfoVue>
  56. <danyuanMuluVue ref="dyMlRef" @select="handleSelectDanyuan"></danyuanMuluVue>
  57. <CustomTabBar :currentTabNumber="1"></CustomTabBar>
  58. </view>
  59. </template>
  60. <script>
  61. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  62. import cacheManager from "@/utils/cacheManager.js";
  63. import {
  64. shuxueChanpinDanyuanInfo
  65. } from "@/api/chanpinneirong.js"
  66. import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
  67. import danyuanMuluVue from '@/pages/xinshuxue/components/danyuanMulu.vue';
  68. import { toast } from '../../utils/common';
  69. export default {
  70. data() {
  71. return {
  72. dagangList: [],
  73. currentUnitName: "",
  74. isShow: true,
  75. currentIndex: 0,
  76. danyuanInfo: {},
  77. banbenId: '',
  78. danyuanId: '',
  79. chanpinId: '',
  80. fontDanyuanId: '',
  81. nextDanyuanId: '',
  82. dengjiId: '',
  83. customType: '',
  84. curProcess: '',
  85. curWanchengStatus: false, //false是可以点击 true是不可以点击
  86. cacheManagerLocal: null,
  87. curJieObject:null
  88. }
  89. },
  90. components: {
  91. CustomTabBar,
  92. danyuanInfoVue,
  93. danyuanMuluVue
  94. },
  95. onShow() {
  96. console.log('学习页面显示,尝试恢复滚动位置')
  97. },
  98. onHide() {
  99. console.log('学习页面隐藏,保存滚动位置')
  100. },
  101. onLoad(options) {
  102. console.log('options', options);
  103. this.customType = options.customType
  104. if (this.customType) {
  105. this.chanpinId = options.chanpinId
  106. this.danyuanId = options.danyuanId
  107. this.banbenId = options.banbenId
  108. this.dengjiId = options.dengjiId
  109. this.loadDataFromApi()
  110. } else {
  111. console.log('使用缓存');
  112. this.chanpinId = cacheManager.get('auth').chanpinId
  113. this.danyuanId = cacheManager.get('auth').danyuanId
  114. this.banbenId = cacheManager.get('auth').banbenId
  115. //用于返回
  116. this.dengjiId = cacheManager.get('auth').dengjiId
  117. this.cacheManagerLocal = cacheManager.get('xuexi-shuxue')
  118. // 使用缓存
  119. this.danyuanInfo = this.cacheManagerLocal
  120. this.curProcess = this.cacheManagerLocal.curProcess
  121. this.fontDanyuanId = this.cacheManagerLocal.fontDanyuanId
  122. this.nextDanyuanId = this.cacheManagerLocal.nextDanyuanId
  123. this.dagangList = this.cacheManagerLocal.dagangList || []
  124. }
  125. },
  126. methods: {
  127. // 继续学习按钮是否可以点击
  128. jisuanWanchengStatus(dagangList) {
  129. // 查找第一个未完成的项目
  130. const firstUncompleted = dagangList.find(item => item.wanchengFlag === 0);
  131. if (firstUncompleted) {
  132. return {
  133. allCompleted: false,
  134. firstUncompleted: firstUncompleted
  135. };
  136. } else {
  137. return {
  138. allCompleted: true,
  139. firstUncompleted: null
  140. };
  141. }
  142. },
  143. handleSelectDanyuan(item) {
  144. console.log('切换单元', item)
  145. this.danyuanId = item.danyuanId
  146. this.loadDataFromApi()
  147. },
  148. handleClickMulu() {
  149. this.$refs.dyMlRef.showPopup(this.banbenId)
  150. },
  151. handleBack() {
  152. uni.navigateTo({
  153. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  154. })
  155. },
  156. loadDataFromApi() {
  157. const req = {
  158. banbenId: this.banbenId,
  159. danyuanId: this.danyuanId
  160. }
  161. shuxueChanpinDanyuanInfo(req).then(res => {
  162. this.danyuanInfo = res.data
  163. this.curProcess = res.data.curProcess
  164. this.fontDanyuanId = res.data.fontDanyuanId
  165. this.nextDanyuanId = res.data.nextDanyuanId
  166. this.dagangList = res.data.dagangList || []
  167. const result = this.jisuanWanchengStatus(this.dagangList);
  168. if (result.allCompleted) {
  169. console.log('全部完成');
  170. this.curWanchengStatus = true
  171. this.curJieObject = null
  172. } else {
  173. this.curWanchengStatus = false
  174. this.curJieObject = result.firstUncompleted
  175. // 当前单元下 第一个未完成的jie 内容
  176. console.log('未完成项目:', result.firstUncompleted);
  177. }
  178. console.log('this.curWanchengStatus', this.curWanchengStatus);
  179. cacheManager.set('xuexi-shuxue', res.data)
  180. cacheManager.updateObject('auth', {
  181. chanpinId: this.chanpinId,
  182. banbenId: this.banbenId,
  183. danyuanId: this.danyuanId,
  184. dengjiId: this.dengjiId
  185. })
  186. })
  187. },
  188. prev() {
  189. if (this.fontDanyuanId != 0) {
  190. this.danyuanId = this.fontDanyuanId
  191. this.loadDataFromApi()
  192. }
  193. },
  194. next() {
  195. if (this.nextDanyuanId != 0) {
  196. this.danyuanId = this.nextDanyuanId
  197. this.loadDataFromApi()
  198. }
  199. },
  200. handlePlay(da, code) {
  201. let jieId = null;
  202. if (code == 'jixu') {
  203. if(this.curWanchengStatus){
  204. toast("当前单元节内容全部学习完毕,请切换下一单元!")
  205. return
  206. }
  207. if (da.type == 1) {
  208. jieId = da.jieId;
  209. uni.navigateTo({
  210. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  211. })
  212. } else {
  213. jieId = da.jieId;
  214. uni.navigateTo({
  215. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  216. })
  217. }
  218. } else {
  219. jieId = da.jieId;
  220. if (da.type == 1) {
  221. uni.navigateTo({
  222. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  223. })
  224. } else {
  225. uni.navigateTo({
  226. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  227. })
  228. }
  229. }
  230. },
  231. handleClickDanyuan() {
  232. this.isShow = true;
  233. setTimeout(() => {
  234. this.$refs.dyRef.handleShow(this.danyuanId)
  235. }, 100)
  236. },
  237. // 滚动事件处理
  238. onScroll(e) {
  239. const scrollTop = e.detail.scrollTop;
  240. // 更新滚动位置
  241. this.scrollTop = scrollTop;
  242. }
  243. }
  244. }
  245. </script>