index.vue 10 KB

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