index.vue 11 KB

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