index.vue 12 KB

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