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&&typeId==2" @clickGradeTerm="clickGradeTerm"
  7. @handleCheckCatalogue="handleCheckCatalogue(item)" @listClick="listClick" :gradeTerm='gradeTerm'
  8. :options="item">
  9. </shuxueZhangjie>
  10. <yingyuZhangjie v-if="currentProduct ==2&&typeId==2" @clickGradeTerm="clickGradeTerm"
  11. @handleCheckCatalogue="handleCheckCatalogue(item)" @listClick="listClick" :gradeTerm='gradeTerm' :options="item">
  12. </yingyuZhangjie>
  13. <shuxueNewZhangjie v-if="currentProduct ==1&&typeId==1" @clickGradeTerm="clickGradeTerm"
  14. @handleCheckCatalogue="handleCheckCatalogue(item)" @listClick="listClick" :gradeTerm='gradeTerm'
  15. :options="item">
  16. </shuxueNewZhangjie>
  17. </swiper-item>
  18. </swiper>
  19. <!-- 蛋 -->
  20. <egg-dialog ref="eggDialogRef" @eggBtn="eggBtn"></egg-dialog>
  21. <catalogue ref="catalogueRef" :list=zhangList @change-zhang="handleChangeZhang" @listSelectJieClick="listSelectJieClick"></catalogue>
  22. <CustomTabBar :cardId="cardId" :currentTabNumber="0" :nianji="nianji" :zhangId="zhangId" :tipFlag="tipFlag"></CustomTabBar>
  23. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPayPage" :content="tipContent"></tip-small-dialog>
  24. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  25. <dao-tip-dialog ref="daoTipDialogRef" v-if="showDaoTip" :productTip="productTipImg" @dao-tip-close="daoTipClose"></dao-tip-dialog>
  26. </view>
  27. </template>
  28. <script setup>
  29. import daoTipDialog from './daoTipDialog.vue';
  30. import {
  31. userZhangInfo,
  32. userLocate,
  33. userZhangForntInfo,
  34. userZhangNextInfo,
  35. getCommonZhangInfo
  36. } from "@/api/learnPlan.js"
  37. import {
  38. reactive,
  39. ref,
  40. nextTick,
  41. getCurrentInstance,
  42. onMounted
  43. } from "vue";
  44. import {
  45. onLoad
  46. } from '@dcloudio/uni-app';
  47. import catalogue from "@/components/catalogue/catalogue.vue";
  48. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  49. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  50. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  51. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  52. import dSwiper from '@/components/wSwiper/DSwiper.vue';
  53. import shuxueZhangjie from './product/shuxue.vue';
  54. import shuxueNewZhangjie from './product/shuxueNew.vue';
  55. import yingyuZhangjie from './product/yingyu.vue';
  56. import {
  57. useTabBarHistory
  58. } from '@/utils/emitEvents.js';
  59. import eggDialog from './eggDialog.vue'
  60. import {
  61. toast,
  62. getUserIdentity
  63. } from "@/utils/common";
  64. import cacheManager from "@/utils/cacheManager.js";
  65. const tipContent = '是否前往开通付费?'; //当前产品
  66. const goPayDialogRef = ref(null);
  67. const youkeDialogRef = ref(null);
  68. const dSwiperRef = ref(null);
  69. const eggDialogRef = ref(null);
  70. const current = ref(0);
  71. const currentDuration = ref(500)
  72. const YouKeContent = '您当前的身份是游客,想要体验完整内容需注册成用户!';
  73. const zhangId = ref(null); //游客使用
  74. const nianji = ref(null); //游客使用
  75. const cardId = ref(null); //游客使用
  76. const tipFlag = ref(null) //游客使用
  77. const catalogueRef = ref(null);
  78. const youkeZhangInfoData = ref(null);
  79. const currentProduct = ref(null);
  80. const localAuth = ref(null);
  81. const levelId = ref(null);
  82. const typeId = ref(null);
  83. const zhangList = ref(null);
  84. const gradeTerm = ref(null);
  85. let infoData = reactive({
  86. jieList: [],
  87. haveFlag: '',
  88. nianji: '',
  89. number: '',
  90. cardId: '',
  91. zhangId: '',
  92. zhangName: '',
  93. numberStr: '',
  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')){
  107. cacheManager.updateObject('auth', {
  108. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == item.zhangId),
  109. zhangId: item.zhangId
  110. })
  111. }
  112. listClick(data,item,index );
  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. localAuth.value = cacheManager.get('auth');
  172. currentProduct.value = localAuth.value.subjectId;
  173. typeId.value = localAuth.value.typeId;
  174. console.log(localAuth.value);
  175. // 已登录
  176. if (localAuth.value.firstLogin) {
  177. nextTick(() => {
  178. eggDialogRef.value.eggShow();
  179. })
  180. }
  181. if(!cacheManager.get('daoPageCache').isCache){
  182. console.log('不实用换葱');
  183. getZhangInfo()
  184. }else{
  185. console.log('shiyonghuancun');
  186. translateData(cacheManager.get('zhangInfo'))
  187. zhangList.value = cacheManager.get('zhangInfo').zhangList
  188. current.value = cacheManager.get('auth').currentZhang
  189. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[current.value].zhangId
  190. recordZhangJie()
  191. }
  192. // 已登录付费未支付选择返回 -> 恢复弹窗
  193. if (options.studyWithCatalgue) {
  194. // 展开弹窗
  195. nextTick(() => {
  196. catalogueRef.value.showPopup({zhangId: infoData.zhangId});
  197. })
  198. }
  199. } else {
  200. zhangId.value = options.zhangId
  201. nianji.value = options.nianji
  202. cardId.value = options.cardId
  203. tipFlag.value = options.tipFlag;
  204. currentProduct.value = options.cardId
  205. // 未登录 游客
  206. getCommonZhang(options)
  207. getProjectImg()
  208. }
  209. }
  210. function getZhangInfo(data) {
  211. let req = {
  212. levelId:localAuth.value.levelId
  213. }
  214. userZhangInfo(req).then(res => {
  215. cacheManager.set('zhangInfo', res.data)
  216. let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == localAuth
  217. .value.zhangId);
  218. console.log('zhang',zhang);
  219. if (zhang != -1) {
  220. cacheManager.updateObject('auth', {
  221. currentZhang: zhang
  222. })
  223. } else {
  224. cacheManager.updateObject('auth', {
  225. currentZhang: 0
  226. })
  227. }
  228. cacheManager.set('daoPageCache',{isCache:true})
  229. nextTick(() => {
  230. translateData(res.data)
  231. zhangList.value = res.data.zhangList
  232. current.value = cacheManager.get('auth').currentZhang
  233. infoData.zhangId = res.data.zhangList[current.value].zhangId
  234. recordZhangJie()
  235. })
  236. })
  237. }
  238. function getCommonZhang(data) {
  239. let req = {
  240. nianji: data.nianji,
  241. cardId: data.cardId,
  242. zhangId: data.zhangId,
  243. }
  244. getCommonZhangInfo(req).then(res => {
  245. translateData(res.data)
  246. youkeZhangInfoData.value = res.data
  247. zhangList.value = res.data.zhangList
  248. current.value = 0
  249. })
  250. }
  251. function recordZhangJie() {
  252. let req = {
  253. levelId: localAuth.value.levelId,
  254. userId: localAuth.value.userId,
  255. zhangId: infoData.zhangId,
  256. subjectId: currentProduct.value
  257. }
  258. userLocate(req).then(res => {
  259. })
  260. }
  261. function goPayPage() {
  262. let zhangInfoLocal = cacheManager.get('zhangInfo')
  263. if(!zhangInfoLocal.cardId){
  264. toast("cardId 丢失请重新选择学科LevelId");
  265. return false
  266. }
  267. uni.redirectTo({
  268. url: '/pages/mall/mallPage?cardId='+zhangInfoLocal.cardId+'&from=daoPage'+'&subjectId='+zhangInfoLocal.subjectId
  269. })
  270. }
  271. function handleChangeZhang(data) {
  272. console.log(data);
  273. const authCode = getUserIdentity();
  274. if (authCode !== 'Visitor') {
  275. cacheManager.updateObject('auth', {
  276. zhangId: data.zhangId,
  277. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == data.zhangId),
  278. })
  279. }
  280. currentDuration.value = 0
  281. setTimeout(() => {
  282. current.value = data.number - 1
  283. nextTick(() => {
  284. currentDuration.value = 500
  285. })
  286. }, 100)
  287. // init()
  288. }
  289. function goKaoshi(data) {
  290. uni.redirectTo({
  291. // url: `/pages/unitTest/index?jieNumber=` + data.number
  292. url: `/pages/unitTest/index?jieId=` + data.jieId
  293. })
  294. }
  295. function goLookShipin(data,index) {
  296. if (!cacheManager.get('auth')) {
  297. console.log('zhangList.value[0].jieList',zhangList.value[0].jieList);
  298. console.log('zhangList.value[0].jieList.index',zhangList.value[0].jieList[index]);
  299. let youkeData = {
  300. cardId:cardId.value,
  301. nianji:nianji.value,
  302. zhangId:zhangId.value,
  303. tipFlag:tipFlag.value,
  304. jieList:zhangList.value[0].jieList[index],
  305. jieName:zhangList.value[0].jieList[index].jieName
  306. }
  307. uni.redirectTo({
  308. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  309. })
  310. } else {
  311. uni.redirectTo({
  312. url: '/pages/study/lookShipin?jieId=' + data.jieId
  313. })
  314. }
  315. }
  316. function translateData(data) {
  317. // gradeTerm.value = termMapping[data.subjectId] +' · '+ data.levelName
  318. gradeTerm.value = data.levelName
  319. }
  320. function listClick(data,data2,index) {
  321. console.log('data',data);// 节内容
  322. console.log('data2',data2); //章内容
  323. if (!cacheManager.get('auth') ) {
  324. youkeDialogRef.value.handleShow();
  325. return;
  326. }
  327. const authCode = getUserIdentity();
  328. console.log('authCode', authCode);
  329. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  330. // debugger
  331. goPayDialogRef.value.handleShow();
  332. return false
  333. }
  334. if (data.type == 2) {
  335. // 最后一项
  336. goKaoshi(data,index)
  337. } else {
  338. goLookShipin(data,index)
  339. }
  340. }
  341. function handleCheckCatalogue(item) {
  342. catalogueRef.value.showPopup(item);
  343. }
  344. function clickGradeTerm() {
  345. // if(cacheManager.get('auth')){
  346. // cacheManager.updateObject('auth', {
  347. // currentZhang: 0
  348. // })
  349. // }
  350. uni.navigateTo({
  351. url: `/pages/selectGradesTerms/index?tipFlag=${tipFlag.value}`,
  352. })
  353. }
  354. // 游客弹窗---确定
  355. function ykConfirm() {
  356. uni.redirectTo({
  357. url: '/pages/login/index'
  358. });
  359. }
  360. function eggBtn() {
  361. console.log('点击:开启提分之旅');
  362. getProjectImg();
  363. cacheManager.updateObject('auth', {
  364. firstLogin: false
  365. })
  366. }
  367. </script>
  368. <style>
  369. </style>