index.vue 12 KB

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