index.vue 11 KB

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