index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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" :tipFlag="tipFlag"></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 tipFlag = ref(null) //游客使用
  69. const catalogueRef = ref(null);
  70. const youkeZhangInfoData = ref(null);
  71. const currentProduct = ref(null);
  72. const selectZhang = ref(null);
  73. const zhangList = ref(null);
  74. const gradeTerm = ref(null);
  75. let infoData = reactive({
  76. jieList: [],
  77. haveFlag: '',
  78. nianji: '',
  79. number: '',
  80. cardId: '',
  81. zhangId: '',
  82. zhangName: '',
  83. numberStr: '',
  84. });
  85. const gradeMapping = {
  86. 1: 'L1',
  87. 2: 'L2',
  88. 3: 'L3',
  89. 4: 'L4',
  90. 5: 'L5',
  91. 6: 'L6'
  92. };
  93. const termMapping = {
  94. 1: ' 数学',
  95. 2: ' 英语'
  96. };
  97. const daoTipDialogRef = ref(null);
  98. const showDaoTip = ref(true);
  99. const productTipImg = ref('');
  100. onLoad((options) => {
  101. init(options);
  102. })
  103. function getProjectImg(){
  104. if(currentProduct.value ==1){
  105. // 数学
  106. productTipImg.value = 'static/images/study/shuxue/shuxue-tip.gif';
  107. getBj('shuxue')
  108. }else if(currentProduct.value ==2){
  109. // 英语
  110. productTipImg.value = 'static/images/study/yingyu/yingyu-tip.gif'
  111. getBj('yingyu');
  112. }
  113. }
  114. function getBj(data){
  115. let bjType =cacheManager.get('dao-tip')[data];
  116. if(cacheManager.get('auth')){
  117. // 非游客
  118. if(bjType!=='has'){
  119. nextTick(() => {
  120. daoTipDialogRef.value.handleShow();
  121. })
  122. }
  123. }else{
  124. // 游客
  125. if(tipFlag.value==='0'){
  126. nextTick(() => {
  127. daoTipDialogRef.value.handleShow();
  128. })
  129. }
  130. }
  131. }
  132. function daoTipClose(){
  133. if(cacheManager.get('auth')){
  134. // 非游客 记缓存
  135. if(currentProduct.value ==1){
  136. // 数学
  137. cacheManager.updateObject('dao-tip',{shuxue:'has'})
  138. }else if(currentProduct.value ==2){
  139. // 英语
  140. cacheManager.updateObject('dao-tip',{yingyu:'has'})
  141. }
  142. }else{
  143. //游客
  144. tipFlag.value = '1';
  145. }
  146. }
  147. function onChangeTab(e) {
  148. console.log('e',e);
  149. console.log(e.detail.current);
  150. if( cacheManager.get('auth')){
  151. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[e.detail.current].zhangId
  152. cacheManager.updateObject('auth', {
  153. currentZhang: e.detail.current,
  154. zhangId: infoData.zhangId
  155. })
  156. }
  157. }
  158. function init(options) {
  159. if (cacheManager.get('auth')) {
  160. //会员 取auth
  161. selectZhang.value = cacheManager.get('auth');
  162. currentProduct.value = cacheManager.get('auth').cardId;
  163. //let currentObject = this.cacheZhangInfo.jieList.find(item => item.jieId == this.jieId);
  164. console.log(selectZhang.value);
  165. // 已登录
  166. if (selectZhang.value.firstLogin) {
  167. nextTick(() => {
  168. eggDialogRef.value.eggShow();
  169. })
  170. }
  171. // cacheManager.set('daoPageCache',{isCache:true})
  172. if(!cacheManager.get('daoPageCache').isCache){
  173. getZhangInfo()
  174. }else{
  175. console.log('shiyonghuancun');
  176. translateData(cacheManager.get('auth'))
  177. zhangList.value = cacheManager.get('zhangInfo').zhangList
  178. current.value = cacheManager.get('auth').currentZhang
  179. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[current.value].zhangId
  180. recordZhangJie()
  181. }
  182. } else {
  183. zhangId.value = options.zhangId
  184. nianji.value = options.nianji
  185. cardId.value = options.cardId
  186. tipFlag.value = options.tipFlag;
  187. currentProduct.value = options.cardId
  188. // 未登录 游客
  189. getCommonZhang(options)
  190. getProjectImg()
  191. }
  192. }
  193. function getZhangInfo(data) {
  194. let req = {
  195. nianji: selectZhang.value.nianji,
  196. cardId: selectZhang.value.cardId,
  197. zhangId: selectZhang.value.zhangId,
  198. }
  199. userZhangInfo(req).then(res => {
  200. cacheManager.set('zhangInfo', res.data)
  201. let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == selectZhang
  202. .value.zhangId);
  203. if (zhang != -1) {
  204. cacheManager.updateObject('auth', {
  205. currentZhang: zhang
  206. })
  207. } else {
  208. cacheManager.updateObject('auth', {
  209. currentZhang: 0
  210. })
  211. }
  212. cacheManager.set('daoPageCache',{isCache:true})
  213. nextTick(() => {
  214. translateData(res.data)
  215. zhangList.value = res.data.zhangList
  216. current.value = cacheManager.get('auth').currentZhang
  217. infoData.zhangId = res.data.zhangList[current.value].zhangId
  218. recordZhangJie()
  219. })
  220. })
  221. }
  222. function getCommonZhang(data) {
  223. let req = {
  224. nianji: data.nianji,
  225. cardId: data.cardId,
  226. zhangId: data.zhangId,
  227. }
  228. getCommonZhangInfo(req).then(res => {
  229. translateData(res.data)
  230. youkeZhangInfoData.value = res.data
  231. zhangList.value = res.data.zhangList
  232. current.value = 0
  233. })
  234. }
  235. function recordZhangJie() {
  236. let req = {
  237. nianji: selectZhang.value.nianji,
  238. userId: cacheManager.get('auth').userId,
  239. zhangId: infoData.zhangId,
  240. cardId: selectZhang.value.cardId,
  241. }
  242. userLocate(req).then(res => {
  243. })
  244. }
  245. function goPayPage() {
  246. uni.redirectTo({
  247. url: '/pages/pay/svip?cardId='+currentProduct.value
  248. })
  249. }
  250. function handleChangeZhang(data) {
  251. console.log(data);
  252. selectZhang.value = data;
  253. const authCode = getUserIdentity();
  254. if (authCode !== 'Visitor') {
  255. cacheManager.updateObject('auth', {
  256. zhangId: data.zhangId
  257. })
  258. }
  259. currentDuration.value = 0
  260. setTimeout(() => {
  261. current.value = data.number - 1
  262. nextTick(() => {
  263. currentDuration.value = 500
  264. })
  265. }, 100)
  266. // init()
  267. }
  268. function goKaoshi(data) {
  269. uni.redirectTo({
  270. // url: `/pages/unitTest/index?jieNumber=` + data.number
  271. url: `/pages/unitTest/index?jieId=` + data.jieId
  272. })
  273. }
  274. function goLookShipin(data) {
  275. if (!cacheManager.get('auth')) {
  276. console.log('zhangList.value[0].jieList[0]',zhangList.value[0].jieList);
  277. let youkeData = {
  278. cardId:cardId.value,
  279. nianji:nianji.value,
  280. zhangId:zhangId.value,
  281. tipFlag:tipFlag.value,
  282. jieList:zhangList.value[0].jieList,
  283. jieName:zhangList.value[0].jieList[0].jieName
  284. }
  285. uni.redirectTo({
  286. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  287. })
  288. } else {
  289. uni.redirectTo({
  290. url: '/pages/study/lookShipin?jieId=' + data.jieId
  291. })
  292. }
  293. }
  294. function translateData(data) {
  295. gradeTerm.value = termMapping[data.cardId] +' · '+ gradeMapping[data.nianji]
  296. }
  297. function listClick(data) {
  298. console.log('data', data);
  299. if (!cacheManager.get('auth') && data.firstFlag != 1) {
  300. youkeDialogRef.value.handleShow();
  301. return;
  302. }
  303. const authCode = getUserIdentity();
  304. console.log('authCode', authCode);
  305. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  306. goPayDialogRef.value.handleShow();
  307. return false
  308. }
  309. if (data.type == 2) {
  310. // 最后一项
  311. goKaoshi(data)
  312. } else {
  313. goLookShipin(data)
  314. }
  315. }
  316. function handleCheckCatalogue(item) {
  317. catalogueRef.value.showPopup(item);
  318. }
  319. function clickGradeTerm() {
  320. if(cacheManager.get('auth')){
  321. cacheManager.updateObject('auth', {
  322. currentZhang: 0
  323. })
  324. }
  325. uni.navigateTo({
  326. url: `/pages/selectGradesTerms/index?tipFlag=${tipFlag.value}`,
  327. })
  328. }
  329. // 游客弹窗---确定
  330. function ykConfirm() {
  331. uni.redirectTo({
  332. url: '/pages/login/index'
  333. });
  334. }
  335. function eggBtn() {
  336. console.log('点击:开启提分之旅');
  337. getProjectImg();
  338. cacheManager.updateObject('auth', {
  339. firstLogin: false
  340. })
  341. }
  342. </script>
  343. <style>
  344. </style>