index.vue 9.6 KB

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