index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <swiper :circular="false" @change="onChangeTab" :duration="currentDuration"
  3. :current="current" class="ezy-study-swiper" :class="'ezy-study-swiper'+ currentProduct" >
  4. <swiper-item v-for="(item,index) in zhangList" :key="index">
  5. <shuxueZhangjie v-if="currentProduct ==1" @clickGradeTerm="clickGradeTerm"
  6. @handleCheckCatalogue="handleCheckCatalogue(item)" @listClick="listClick" :gradeTerm='gradeTerm'
  7. :options="item">
  8. </shuxueZhangjie>
  9. <yingyuZhangjie v-if="currentProduct ==2" @clickGradeTerm="clickGradeTerm"
  10. @handleCheckCatalogue="handleCheckCatalogue(item)" @listClick="listClick" :gradeTerm='gradeTerm' :options="item">
  11. </yingyuZhangjie>
  12. </swiper-item>
  13. </swiper>
  14. <!-- 蛋 -->
  15. <egg-dialog ref="eggDialogRef" @eggBtn="eggBtn"></egg-dialog>
  16. <catalogue ref="catalogueRef" :list=zhangList @change-zhang="handleChangeZhang"></catalogue>
  17. <CustomTabBar :cardId="cardId" :currentTabNumber="0" :nianji="nianji" :zhangId="zhangId"></CustomTabBar>
  18. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPayPage" :content="tipContent"></tip-small-dialog>
  19. <tip-middle-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :content="YouKeContent"></tip-middle-dialog>
  20. </template>
  21. <script setup>
  22. import {
  23. userZhangInfo,
  24. userLocate,
  25. userZhangForntInfo,
  26. userZhangNextInfo,
  27. getCommonZhangInfo
  28. } from "@/api/learnPlan.js"
  29. import {
  30. reactive,
  31. ref,
  32. nextTick,
  33. getCurrentInstance,
  34. onMounted
  35. } from "vue";
  36. import {
  37. onLoad
  38. } from '@dcloudio/uni-app';
  39. import catalogue from "@/components/catalogue/catalogue.vue";
  40. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  41. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  42. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  43. import dSwiper from '@/components/wSwiper/DSwiper.vue';
  44. import shuxueZhangjie from './product/shuxue.vue';
  45. import yingyuZhangjie from './product/yingyu.vue';
  46. import {
  47. useTabBarHistory
  48. } from '@/utils/emitEvents.js';
  49. import eggDialog from './eggDialog.vue'
  50. import {
  51. toast,
  52. getUserIdentity
  53. } from "@/utils/common";
  54. import cacheManager from "@/utils/cacheManager.js";
  55. const tipContent = '付费章节,是否前往开通付费?'; //当前产品
  56. const goPayDialogRef = ref(null);
  57. const youkeDialogRef = ref(null);
  58. const dSwiperRef = ref(null);
  59. const eggDialogRef = ref(null);
  60. const current = ref(0);
  61. const currentDuration = ref(500)
  62. const YouKeContent = '您当前是游客身份,登录后才能浏览内容,现在去登录?';
  63. const zhangId = ref(null); //游客使用
  64. const nianji = ref(null); //游客使用
  65. const cardId = ref(null); //游客使用
  66. const catalogueRef = ref(null);
  67. const youkeZhangInfoData = ref(null);
  68. const currentProduct = ref(null);
  69. const selectZhang = ref(null);
  70. const zhangList = ref(null);
  71. const gradeTerm = ref(null);
  72. let infoData = reactive({
  73. jieList: [],
  74. haveFlag: '',
  75. nianji: '',
  76. number: '',
  77. cardId: '',
  78. zhangId: '',
  79. zhangName: '',
  80. numberStr: '',
  81. });
  82. const gradeMapping = {
  83. 1: 'L1',
  84. 2: 'L2',
  85. 3: 'L3',
  86. 4: 'L4',
  87. 5: 'L5',
  88. 6: 'L6'
  89. };
  90. const termMapping = {
  91. 1: ' 数学',
  92. 2: ' 英语'
  93. };
  94. onLoad((options) => {
  95. init(options)
  96. })
  97. function onChangeTab(e) {
  98. console.log('e',e);
  99. console.log(e.detail.current);
  100. if( cacheManager.get('auth')){
  101. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[e.detail.current].zhangId
  102. cacheManager.updateObject('auth', {
  103. currentZhang: e.detail.current,
  104. zhangId: infoData.zhangId
  105. })
  106. }
  107. //current.value = e.detail.current;
  108. }
  109. function init(options) {
  110. if (cacheManager.get('auth')) {
  111. //会员 取auth
  112. selectZhang.value = cacheManager.get('auth');
  113. currentProduct.value = cacheManager.get('auth').cardId;
  114. //let currentObject = this.cacheZhangInfo.jieList.find(item => item.jieId == this.jieId);
  115. console.log(selectZhang.value);
  116. // 已登录
  117. if (selectZhang.value.firstLogin) {
  118. nextTick(() => {
  119. eggDialogRef.value.eggShow();
  120. })
  121. }
  122. getZhangInfo()
  123. } else {
  124. zhangId.value = options.zhangId
  125. nianji.value = options.nianji
  126. cardId.value = options.cardId
  127. currentProduct.value = options.cardId
  128. // 未登录 游客
  129. getCommonZhang(options)
  130. }
  131. }
  132. function getZhangInfo(data) {
  133. let req = {
  134. nianji: selectZhang.value.nianji,
  135. cardId: selectZhang.value.cardId,
  136. zhangId: selectZhang.value.zhangId,
  137. }
  138. userZhangInfo(req).then(res => {
  139. cacheManager.set('zhangInfo', res.data)
  140. let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == selectZhang
  141. .value.zhangId);
  142. if (zhang != -1) {
  143. cacheManager.updateObject('auth', {
  144. currentZhang: zhang
  145. })
  146. } else {
  147. cacheManager.updateObject('auth', {
  148. currentZhang: 0
  149. })
  150. }
  151. nextTick(() => {
  152. translateData(res.data)
  153. zhangList.value = res.data.zhangList
  154. current.value = cacheManager.get('auth').currentZhang
  155. infoData.zhangId = res.data.zhangList[current.value].zhangId
  156. recordZhangJie()
  157. })
  158. })
  159. }
  160. function getCommonZhang(data) {
  161. let req = {
  162. nianji: data.nianji,
  163. cardId: data.cardId,
  164. zhangId: data.zhangId,
  165. }
  166. getCommonZhangInfo(req).then(res => {
  167. translateData(res.data)
  168. youkeZhangInfoData.value = res.data
  169. zhangList.value = res.data.zhangList
  170. current.value = 0
  171. // infoData.haveFlag = res.data.haveFlag
  172. // infoData.nianji = res.data.nianji
  173. // infoData.number = res.data.number
  174. // infoData.numberStr = res.data.numberStr
  175. // infoData.cardId = res.data.cardId
  176. // infoData.zhangId = res.data.zhangId
  177. // infoData.zhangName = res.data.zhangName
  178. //getNewData()
  179. })
  180. }
  181. function getNewData() {
  182. selectZhang.value.zhangId = cacheManager.get('zhangInfo').zhangId;
  183. selectZhang.value.cardId = cacheManager.get('zhangInfo').cardId;
  184. selectZhang.value.nianji = cacheManager.get('zhangInfo').nianji;
  185. cacheManager.updateObject('auth', {
  186. zhangId: selectZhang.value.zhangId,
  187. cardId: selectZhang.value.cardId,
  188. nianji: selectZhang.value.nianji,
  189. })
  190. }
  191. function recordZhangJie() {
  192. let req = {
  193. nianji: selectZhang.value.nianji,
  194. userId: cacheManager.get('auth').userId,
  195. zhangId: infoData.zhangId,
  196. cardId: selectZhang.value.cardId,
  197. }
  198. userLocate(req).then(res => {
  199. })
  200. }
  201. function goPayPage() {
  202. uni.redirectTo({
  203. url: '/pages/pay/svip?cardId='+currentProduct.value
  204. })
  205. }
  206. function handleChangeZhang(data) {
  207. console.log(data);
  208. selectZhang.value = data;
  209. const authCode = getUserIdentity();
  210. if (authCode !== 'Visitor') {
  211. cacheManager.updateObject('auth', {
  212. zhangId: data.zhangId
  213. })
  214. }
  215. currentDuration.value = 0
  216. setTimeout(() => {
  217. current.value = data.number - 1
  218. nextTick(() => {
  219. currentDuration.value = 500
  220. })
  221. }, 100)
  222. // init()
  223. }
  224. function goKaoshi(data) {
  225. uni.redirectTo({
  226. // url: `/pages/unitTest/index?jieNumber=` + data.number
  227. url: `/pages/unitTest/index?jieId=` + data.jieId
  228. })
  229. }
  230. function goLookShipin(data) {
  231. if (!cacheManager.get('auth')) {
  232. console.log('zhangList.value[0].jieList[0]',zhangList.value[0].jieList);
  233. let youkeData = {
  234. cardId:cardId.value,
  235. nianji:nianji.value,
  236. zhangId:zhangId.value,
  237. jieList:zhangList.value[0].jieList,
  238. jieName:zhangList.value[0].jieList[0].jieName
  239. }
  240. uni.redirectTo({
  241. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  242. })
  243. } else {
  244. uni.redirectTo({
  245. url: '/pages/study/lookShipin?jieId=' + data.jieId
  246. })
  247. }
  248. }
  249. function translateData(data) {
  250. gradeTerm.value = termMapping[data.cardId] +' · '+ gradeMapping[data.nianji]
  251. }
  252. function listClick(data) {
  253. console.log('data', data);
  254. if (!cacheManager.get('auth') && data.firstFlag != 1) {
  255. youkeDialogRef.value.handleShow();
  256. return;
  257. }
  258. const authCode = getUserIdentity();
  259. console.log('authCode', authCode);
  260. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  261. goPayDialogRef.value.handleShow();
  262. return false
  263. }
  264. if (data.type == 2) {
  265. // 最后一项
  266. goKaoshi(data)
  267. } else {
  268. goLookShipin(data)
  269. }
  270. }
  271. function handleCheckCatalogue(item) {
  272. catalogueRef.value.showPopup(item);
  273. }
  274. function clickGradeTerm() {
  275. if(cacheManager.get('auth')){
  276. cacheManager.updateObject('auth', {
  277. currentZhang: 0
  278. })
  279. }
  280. uni.navigateTo({
  281. url: `/pages/selectGradesTerms/index`,
  282. })
  283. }
  284. // 游客弹窗---确定
  285. function ykConfirm() {
  286. uni.redirectTo({
  287. url: '/pages/login/index'
  288. });
  289. }
  290. function eggBtn() {
  291. console.log('点击:开启提分之旅');
  292. cacheManager.updateObject('auth', {
  293. firstLogin: false
  294. })
  295. }
  296. </script>
  297. <style>
  298. </style>