index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. }
  176. }
  177. function getZhangInfo(data) {
  178. let req = {
  179. nianji: selectZhang.value.nianji,
  180. cardId: selectZhang.value.cardId,
  181. zhangId: selectZhang.value.zhangId,
  182. }
  183. userZhangInfo(req).then(res => {
  184. cacheManager.set('zhangInfo', res.data)
  185. let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == selectZhang
  186. .value.zhangId);
  187. if (zhang != -1) {
  188. cacheManager.updateObject('auth', {
  189. currentZhang: zhang
  190. })
  191. } else {
  192. cacheManager.updateObject('auth', {
  193. currentZhang: 0
  194. })
  195. }
  196. cacheManager.set('daoPageCache',{isCache:true})
  197. nextTick(() => {
  198. translateData(res.data)
  199. zhangList.value = res.data.zhangList
  200. current.value = cacheManager.get('auth').currentZhang
  201. infoData.zhangId = res.data.zhangList[current.value].zhangId
  202. recordZhangJie()
  203. })
  204. })
  205. }
  206. function getCommonZhang(data) {
  207. let req = {
  208. nianji: data.nianji,
  209. cardId: data.cardId,
  210. zhangId: data.zhangId,
  211. }
  212. getCommonZhangInfo(req).then(res => {
  213. translateData(res.data)
  214. youkeZhangInfoData.value = res.data
  215. zhangList.value = res.data.zhangList
  216. current.value = 0
  217. })
  218. }
  219. function recordZhangJie() {
  220. let req = {
  221. nianji: selectZhang.value.nianji,
  222. userId: cacheManager.get('auth').userId,
  223. zhangId: infoData.zhangId,
  224. cardId: selectZhang.value.cardId,
  225. }
  226. userLocate(req).then(res => {
  227. })
  228. }
  229. function goPayPage() {
  230. uni.redirectTo({
  231. url: '/pages/pay/svip?cardId='+currentProduct.value
  232. })
  233. }
  234. function handleChangeZhang(data) {
  235. console.log(data);
  236. selectZhang.value = data;
  237. const authCode = getUserIdentity();
  238. if (authCode !== 'Visitor') {
  239. cacheManager.updateObject('auth', {
  240. zhangId: data.zhangId
  241. })
  242. }
  243. currentDuration.value = 0
  244. setTimeout(() => {
  245. current.value = data.number - 1
  246. nextTick(() => {
  247. currentDuration.value = 500
  248. })
  249. }, 100)
  250. // init()
  251. }
  252. function goKaoshi(data) {
  253. uni.redirectTo({
  254. // url: `/pages/unitTest/index?jieNumber=` + data.number
  255. url: `/pages/unitTest/index?jieId=` + data.jieId
  256. })
  257. }
  258. function goLookShipin(data) {
  259. if (!cacheManager.get('auth')) {
  260. console.log('zhangList.value[0].jieList[0]',zhangList.value[0].jieList);
  261. let youkeData = {
  262. cardId:cardId.value,
  263. nianji:nianji.value,
  264. zhangId:zhangId.value,
  265. jieList:zhangList.value[0].jieList,
  266. jieName:zhangList.value[0].jieList[0].jieName
  267. }
  268. uni.redirectTo({
  269. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  270. })
  271. } else {
  272. uni.redirectTo({
  273. url: '/pages/study/lookShipin?jieId=' + data.jieId
  274. })
  275. }
  276. }
  277. function translateData(data) {
  278. gradeTerm.value = termMapping[data.cardId] +' · '+ gradeMapping[data.nianji]
  279. }
  280. function listClick(data) {
  281. console.log('data', data);
  282. if (!cacheManager.get('auth') && data.firstFlag != 1) {
  283. youkeDialogRef.value.handleShow();
  284. return;
  285. }
  286. const authCode = getUserIdentity();
  287. console.log('authCode', authCode);
  288. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  289. goPayDialogRef.value.handleShow();
  290. return false
  291. }
  292. if (data.type == 2) {
  293. // 最后一项
  294. goKaoshi(data)
  295. } else {
  296. goLookShipin(data)
  297. }
  298. }
  299. function handleCheckCatalogue(item) {
  300. catalogueRef.value.showPopup(item);
  301. }
  302. function clickGradeTerm() {
  303. if(cacheManager.get('auth')){
  304. cacheManager.updateObject('auth', {
  305. currentZhang: 0
  306. })
  307. }
  308. uni.navigateTo({
  309. url: `/pages/selectGradesTerms/index`,
  310. })
  311. }
  312. // 游客弹窗---确定
  313. function ykConfirm() {
  314. uni.redirectTo({
  315. url: '/pages/login/index'
  316. });
  317. }
  318. function eggBtn() {
  319. console.log('点击:开启提分之旅');
  320. getProjectImg();
  321. cacheManager.updateObject('auth', {
  322. firstLogin: false
  323. })
  324. }
  325. </script>
  326. <style>
  327. </style>