index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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 :levelId="levelId" :currentTabNumber="0" :subjectId="subjectId" :typeId="typeId" :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 tipFlag = ref(null) //游客使用
  78. const catalogueRef = ref(null);
  79. const youkeZhangInfoData = ref(null);
  80. const currentProduct = ref(null);
  81. const localAuth = ref(null);
  82. const levelId = ref(null);//游客使用
  83. const subjectId = ref(null);//游客使用
  84. const typeId = ref(null);
  85. const zhangList = ref(null);
  86. const gradeTerm = ref(null);
  87. let infoData = reactive({
  88. jieList: [],
  89. haveFlag: '',
  90. number: '',
  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 && typeId.value==2) {
  116. // 数学
  117. productTipImg.value = 'static/images/study/shuxue/shuxue-tip.gif';
  118. getBj('shuxue')
  119. } else if (currentProduct.value == 2 && typeId.value==2) {
  120. // 英语
  121. productTipImg.value = 'static/images/study/yingyu/yingyu-tip.gif'
  122. getBj('yingyu');
  123. }else if (currentProduct.value == 1 && typeId.value==1) {
  124. // 计算特训
  125. productTipImg.value = 'static/images/study/jstx/jstx-tip.gif'
  126. getBj('shuxueNew');
  127. }
  128. }
  129. function getBj(data) {
  130. let bjType = cacheManager.get('dao-tip')[data];
  131. if (cacheManager.get('auth')) {
  132. // 非游客
  133. if (bjType !== 'has') {
  134. nextTick(() => {
  135. daoTipDialogRef.value.handleShow();
  136. })
  137. }
  138. } else {
  139. // 游客
  140. if (tipFlag.value === '0') {
  141. nextTick(() => {
  142. daoTipDialogRef.value.handleShow();
  143. })
  144. }
  145. }
  146. }
  147. function daoTipClose() {
  148. if (cacheManager.get('auth')) {
  149. // 非游客 记缓存
  150. if (currentProduct.value == 1 && typeId.value==2) {
  151. // 数学
  152. cacheManager.updateObject('dao-tip', {
  153. shuxue: 'has'
  154. })
  155. } else if (currentProduct.value == 2 && typeId.value==2) {
  156. // 英语
  157. cacheManager.updateObject('dao-tip', {
  158. yingyu: 'has'
  159. })
  160. }else if (currentProduct.value == 1 && typeId.value==1) {
  161. // 英语
  162. cacheManager.updateObject('dao-tip', {
  163. shuxueNew: 'has'
  164. })
  165. }
  166. } else {
  167. //游客
  168. tipFlag.value = '1';
  169. }
  170. }
  171. function onChangeTab(e) {
  172. console.log('e', e);
  173. console.log(e.detail.current);
  174. if (cacheManager.get('auth')) {
  175. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[e.detail.current].zhangId
  176. cacheManager.updateObject('auth', {
  177. currentZhang: e.detail.current,
  178. zhangId: infoData.zhangId
  179. })
  180. }
  181. }
  182. function init(options) {
  183. if (cacheManager.get('auth')) {
  184. localAuth.value = cacheManager.get('auth');
  185. currentProduct.value = localAuth.value.subjectId;
  186. typeId.value = localAuth.value.typeId;
  187. console.log(localAuth.value);
  188. // 已登录
  189. if (localAuth.value.firstLogin) {
  190. nextTick(() => {
  191. eggDialogRef.value.eggShow();
  192. })
  193. }
  194. if (!cacheManager.get('daoPageCache').isCache) {
  195. console.log('不实用换葱');
  196. getZhangInfo()
  197. } else {
  198. console.log('shiyonghuancun');
  199. translateData(cacheManager.get('zhangInfo'))
  200. zhangList.value = cacheManager.get('zhangInfo').zhangList
  201. current.value = cacheManager.get('auth').currentZhang
  202. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[current.value].zhangId
  203. recordZhangJie()
  204. }
  205. // 已登录付费未支付选择返回 -> 恢复弹窗
  206. if (options.studyWithCatalgue) {
  207. // 展开弹窗
  208. nextTick(() => {
  209. catalogueRef.value.showPopup({
  210. zhangId: infoData.zhangId
  211. });
  212. })
  213. }
  214. } else {
  215. subjectId.value = options.subjectId
  216. typeId.value = options.typeId
  217. levelId.value = options.levelId
  218. tipFlag.value = options.tipFlag;
  219. currentProduct.value = options.subjectId
  220. // 未登录 游客
  221. getCommonZhang(options)
  222. getProjectImg()
  223. }
  224. }
  225. function getZhangInfo(data) {
  226. let req = {
  227. levelId: localAuth.value.levelId
  228. }
  229. userZhangInfo(req).then(res => {
  230. cacheManager.set('zhangInfo', res.data)
  231. let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == localAuth
  232. .value.zhangId);
  233. console.log('zhang', zhang);
  234. if (zhang != -1) {
  235. cacheManager.updateObject('auth', {
  236. currentZhang: zhang
  237. })
  238. } else {
  239. cacheManager.updateObject('auth', {
  240. currentZhang: 0
  241. })
  242. }
  243. cacheManager.set('daoPageCache', {
  244. isCache: true
  245. })
  246. nextTick(() => {
  247. translateData(res.data)
  248. zhangList.value = res.data.zhangList
  249. current.value = cacheManager.get('auth').currentZhang
  250. infoData.zhangId = res.data.zhangList[current.value].zhangId
  251. recordZhangJie()
  252. })
  253. })
  254. }
  255. function getCommonZhang(data) {
  256. let req = {
  257. levelId: data.levelId,
  258. }
  259. getCommonZhangInfo(req).then(res => {
  260. translateData(res.data)
  261. youkeZhangInfoData.value = res.data
  262. zhangList.value = res.data.zhangList
  263. current.value = 0
  264. })
  265. }
  266. function recordZhangJie() {
  267. let req = {
  268. levelId: localAuth.value.levelId,
  269. userId: localAuth.value.userId,
  270. zhangId: infoData.zhangId,
  271. subjectId: currentProduct.value
  272. }
  273. userLocate(req).then(res => {
  274. })
  275. }
  276. function goPayPage() {
  277. let zhangInfoLocal = cacheManager.get('zhangInfo')
  278. if (!zhangInfoLocal.cardId) {
  279. toast("cardId 丢失请重新选择学科LevelId");
  280. return false
  281. }
  282. uni.redirectTo({
  283. url: '/pages/mall/mallPage?cardId=' + zhangInfoLocal.cardId + '&from=daoPage' + '&subjectId=' +
  284. zhangInfoLocal.subjectId
  285. })
  286. }
  287. function handleChangeZhang(data) {
  288. console.log(data);
  289. const authCode = getUserIdentity();
  290. if (authCode !== 'Visitor') {
  291. cacheManager.updateObject('auth', {
  292. zhangId: data.zhangId,
  293. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == data.zhangId),
  294. })
  295. }
  296. currentDuration.value = 0
  297. setTimeout(() => {
  298. current.value = data.number - 1
  299. nextTick(() => {
  300. currentDuration.value = 500
  301. })
  302. }, 100)
  303. // init()
  304. }
  305. function goKaoshi(data) {
  306. uni.redirectTo({
  307. // url: `/pages/unitTest/index?jieNumber=` + data.number
  308. url: `/pages/unitTest/index?jieId=` + data.jieId
  309. })
  310. }
  311. function goLookShipin(data, index) {
  312. if (!cacheManager.get('auth')) {
  313. console.log('zhangList.value[0].jieList', zhangList.value[0].jieList);
  314. console.log('zhangList.value[0].jieList.index', zhangList.value[0].jieList[index]);
  315. let youkeData = {
  316. levelId: levelId.value,
  317. typeId: typeId.value,
  318. subjectId: subjectId.value,
  319. tipFlag: tipFlag.value,
  320. jieList: zhangList.value[0].jieList[index],
  321. jieName: zhangList.value[0].jieList[index].jieName
  322. }
  323. uni.redirectTo({
  324. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  325. })
  326. } else {
  327. if (typeId.value == 1) {
  328. // 1新 2旧
  329. if(!data.videoId){
  330. toast("videoId 丢失!");
  331. return false
  332. }
  333. uni.redirectTo({
  334. url: '/pages/study/lookShipinNew?jieId=' + data.jieId
  335. })
  336. } else {
  337. if(!data.videoId){
  338. toast("videoId 丢失!");
  339. return false
  340. }
  341. uni.redirectTo({
  342. url: '/pages/study/lookShipin?jieId=' + data.jieId
  343. })
  344. }
  345. }
  346. }
  347. function translateData(data) {
  348. // gradeTerm.value = termMapping[data.subjectId] +' · '+ data.levelName
  349. gradeTerm.value = data.levelName
  350. }
  351. function listClick(data, data2, index) {
  352. console.log('data', data); // 节内容
  353. console.log('data2', data2); //章内容
  354. if (!cacheManager.get('auth')) {
  355. youkeDialogRef.value.handleShow();
  356. return;
  357. }
  358. const authCode = getUserIdentity();
  359. console.log('authCode', authCode);
  360. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  361. // debugger
  362. goPayDialogRef.value.handleShow();
  363. return false
  364. }
  365. if (data.type == 2) {
  366. // 最后一项
  367. goKaoshi(data, index)
  368. } else {
  369. goLookShipin(data, index)
  370. }
  371. }
  372. function handleCheckCatalogue(item) {
  373. catalogueRef.value.showPopup(item);
  374. }
  375. function clickGradeTerm() {
  376. // if(cacheManager.get('auth')){
  377. // cacheManager.updateObject('auth', {
  378. // currentZhang: 0
  379. // })
  380. // }
  381. uni.navigateTo({
  382. url: `/pages/selectGradesTerms/index?tipFlag=${tipFlag.value}&from=daoPage&productId=${levelId.value}&xuekeId=${subjectId.value}`
  383. })
  384. }
  385. // 游客弹窗---确定
  386. function ykConfirm() {
  387. uni.redirectTo({
  388. url: '/pages/login/index'
  389. });
  390. }
  391. function eggBtn() {
  392. console.log('点击:开启提分之旅');
  393. getProjectImg();
  394. cacheManager.updateObject('auth', {
  395. firstLogin: false
  396. })
  397. }
  398. </script>
  399. <style>
  400. </style>