index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-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 tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  47. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  48. import dSwiper from '@/components/wSwiper/DSwiper.vue';
  49. import shuxueZhangjie from './product/shuxue.vue';
  50. import yingyuZhangjie from './product/yingyu.vue';
  51. import {
  52. useTabBarHistory
  53. } from '@/utils/emitEvents.js';
  54. import eggDialog from './eggDialog.vue'
  55. import {
  56. toast,
  57. getUserIdentity
  58. } from "@/utils/common";
  59. import cacheManager from "@/utils/cacheManager.js";
  60. const tipContent = '付费章节,是否前往开通付费?'; //当前产品
  61. const goPayDialogRef = ref(null);
  62. const youkeDialogRef = ref(null);
  63. const dSwiperRef = ref(null);
  64. const eggDialogRef = ref(null);
  65. const current = ref(0);
  66. const currentDuration = ref(500)
  67. const YouKeContent = '您当前的身份是游客,想要体验完整内容需注册成用户!';
  68. const zhangId = ref(null); //游客使用
  69. const nianji = ref(null); //游客使用
  70. const cardId = ref(null); //游客使用
  71. const tipFlag = ref(null) //游客使用
  72. const catalogueRef = ref(null);
  73. const youkeZhangInfoData = ref(null);
  74. const currentProduct = ref(null);
  75. const localAuth = ref(null);
  76. const levelId = ref(null);
  77. const typeId = ref(null);
  78. const zhangList = ref(null);
  79. const gradeTerm = ref(null);
  80. let infoData = reactive({
  81. jieList: [],
  82. haveFlag: '',
  83. nianji: '',
  84. number: '',
  85. cardId: '',
  86. zhangId: '',
  87. zhangName: '',
  88. numberStr: '',
  89. });
  90. const termMapping = {
  91. 1: ' 数学',
  92. 2: ' 英语'
  93. };
  94. const daoTipDialogRef = ref(null);
  95. const showDaoTip = ref(true);
  96. const productTipImg = ref('');
  97. onLoad((options) => {
  98. init(options);
  99. })
  100. function listSelectJieClick(item,data,index) {
  101. if( cacheManager.get('auth')){
  102. cacheManager.updateObject('auth', {
  103. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == item.zhangId),
  104. zhangId: item.zhangId
  105. })
  106. }
  107. listClick(data,item,index );
  108. }
  109. function getProjectImg(){
  110. if(currentProduct.value ==1){
  111. // 数学
  112. productTipImg.value = 'static/images/study/shuxue/shuxue-tip.gif';
  113. getBj('shuxue')
  114. }else if(currentProduct.value ==2){
  115. // 英语
  116. productTipImg.value = 'static/images/study/yingyu/yingyu-tip.gif'
  117. getBj('yingyu');
  118. }
  119. }
  120. function getBj(data){
  121. let bjType =cacheManager.get('dao-tip')[data];
  122. if(cacheManager.get('auth')){
  123. // 非游客
  124. if(bjType!=='has'){
  125. nextTick(() => {
  126. daoTipDialogRef.value.handleShow();
  127. })
  128. }
  129. }else{
  130. // 游客
  131. if(tipFlag.value==='0'){
  132. nextTick(() => {
  133. daoTipDialogRef.value.handleShow();
  134. })
  135. }
  136. }
  137. }
  138. function daoTipClose(){
  139. if(cacheManager.get('auth')){
  140. // 非游客 记缓存
  141. if(currentProduct.value ==1){
  142. // 数学
  143. cacheManager.updateObject('dao-tip',{shuxue:'has'})
  144. }else if(currentProduct.value ==2){
  145. // 英语
  146. cacheManager.updateObject('dao-tip',{yingyu:'has'})
  147. }
  148. }else{
  149. //游客
  150. tipFlag.value = '1';
  151. }
  152. }
  153. function onChangeTab(e) {
  154. console.log('e',e);
  155. console.log(e.detail.current);
  156. if( cacheManager.get('auth')){
  157. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[e.detail.current].zhangId
  158. cacheManager.updateObject('auth', {
  159. currentZhang: e.detail.current,
  160. zhangId: infoData.zhangId
  161. })
  162. }
  163. }
  164. function init(options) {
  165. // FIXME 待修改 部分字段写死
  166. if (cacheManager.get('auth')) {
  167. levelId.value = options.levelId
  168. typeId.value = options.typeId //1新2旧
  169. localAuth.value = cacheManager.get('auth');
  170. // currentProduct.value = cacheManager.get('auth').subjectId;
  171. currentProduct.value = 1;
  172. //let currentObject = this.cacheZhangInfo.jieList.find(item => item.jieId == this.jieId);
  173. console.log(localAuth.value);
  174. // 已登录
  175. if (localAuth.value.firstLogin) {
  176. nextTick(() => {
  177. eggDialogRef.value.eggShow();
  178. })
  179. }
  180. getZhangInfo()
  181. // if(!cacheManager.get('daoPageCache').isCache){
  182. // console.log('不实用换葱');
  183. // getZhangInfo()
  184. // }else{
  185. // console.log('shiyonghuancun');
  186. // translateData(cacheManager.get('auth'))
  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:7
  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: levelId.value,
  254. userId: cacheManager.get('auth').userId,
  255. zhangId: infoData.zhangId,
  256. subjectId: currentProduct.value
  257. }
  258. userLocate(req).then(res => {
  259. })
  260. }
  261. function goPayPage() {
  262. uni.redirectTo({
  263. url: '/pages/pay/svip?cardId='+currentProduct.value
  264. })
  265. }
  266. function handleChangeZhang(data) {
  267. console.log(data);
  268. const authCode = getUserIdentity();
  269. if (authCode !== 'Visitor') {
  270. cacheManager.updateObject('auth', {
  271. zhangId: data.zhangId,
  272. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == data.zhangId),
  273. })
  274. }
  275. currentDuration.value = 0
  276. setTimeout(() => {
  277. current.value = data.number - 1
  278. nextTick(() => {
  279. currentDuration.value = 500
  280. })
  281. }, 100)
  282. // init()
  283. }
  284. function goKaoshi(data) {
  285. uni.redirectTo({
  286. // url: `/pages/unitTest/index?jieNumber=` + data.number
  287. url: `/pages/unitTest/index?jieId=` + data.jieId
  288. })
  289. }
  290. function goLookShipin(data,index) {
  291. if (!cacheManager.get('auth')) {
  292. console.log('zhangList.value[0].jieList',zhangList.value[0].jieList);
  293. console.log('zhangList.value[0].jieList.index',zhangList.value[0].jieList[index]);
  294. let youkeData = {
  295. cardId:cardId.value,
  296. nianji:nianji.value,
  297. zhangId:zhangId.value,
  298. tipFlag:tipFlag.value,
  299. jieList:zhangList.value[0].jieList[index],
  300. jieName:zhangList.value[0].jieList[index].jieName
  301. }
  302. uni.redirectTo({
  303. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  304. })
  305. } else {
  306. uni.redirectTo({
  307. url: '/pages/study/lookShipin?jieId=' + data.jieId + '&levelId=' + 7 + '&typeId=' + 2 + '&subjectId=' + 1
  308. })
  309. }
  310. }
  311. function translateData(data) {
  312. // gradeTerm.value = termMapping[data.subjectId] +' · '+ data.levelName
  313. gradeTerm.value = data.levelName
  314. }
  315. function listClick(data,data2,index) {
  316. console.log('data',data);// 节内容
  317. console.log('data2',data2); //章内容
  318. if (!cacheManager.get('auth') ) {
  319. youkeDialogRef.value.handleShow();
  320. return;
  321. }
  322. const authCode = getUserIdentity();
  323. console.log('authCode', authCode);
  324. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  325. // debugger
  326. goPayDialogRef.value.handleShow();
  327. return false
  328. }
  329. return
  330. if (data.type == 2) {
  331. // 最后一项
  332. goKaoshi(data,index)
  333. } else {
  334. goLookShipin(data,index)
  335. }
  336. }
  337. function handleCheckCatalogue(item) {
  338. catalogueRef.value.showPopup(item);
  339. }
  340. function clickGradeTerm() {
  341. // if(cacheManager.get('auth')){
  342. // cacheManager.updateObject('auth', {
  343. // currentZhang: 0
  344. // })
  345. // }
  346. uni.navigateTo({
  347. url: `/pages/selectGradesTerms/index?tipFlag=${tipFlag.value}`,
  348. })
  349. }
  350. // 游客弹窗---确定
  351. function ykConfirm() {
  352. uni.redirectTo({
  353. url: '/pages/login/index'
  354. });
  355. }
  356. function eggBtn() {
  357. console.log('点击:开启提分之旅');
  358. getProjectImg();
  359. cacheManager.updateObject('auth', {
  360. firstLogin: false
  361. })
  362. }
  363. </script>
  364. <style>
  365. </style>