index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <swiper :circular="false" style="height: 100vh;" @change="onChangeTab" :duration="currentDuration"
  3. :current="current">
  4. <swiper-item v-for="(item,index) in zhangList" :key="index">
  5. <view class="item flex-col flex-center">
  6. <shuxueZhangjie v-if="currentProduct ==1" @clickGradeTerm="clickGradeTerm"
  7. @handleCheckCatalogue="handleCheckCatalogue" @listClick="listClick" :gradeTerm='gradeTerm'
  8. :options="item">
  9. </shuxueZhangjie>
  10. <yingyuZhangjie v-if="currentProduct ==2" @clickGradeTerm="clickGradeTerm"
  11. @handleCheckCatalogue="handleCheckCatalogue" @listClick="listClick" :options="item">
  12. </yingyuZhangjie>
  13. </view>
  14. </swiper-item>
  15. </swiper>
  16. <!-- 蛋 -->
  17. <egg-dialog ref="eggDialogRef" @eggBtn="eggBtn"></egg-dialog>
  18. <catalogue ref="catalogueRef" :list=zhangList @change-zhang="handleChangeZhang"></catalogue>
  19. <CustomTabBar :cardId="cardId" :nianji="nianji" :zhangId="zhangId"></CustomTabBar>
  20. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPayPage" :content="tipContent"></tip-small-dialog>
  21. <tip-middle-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :content="YouKeContent"></tip-middle-dialog>
  22. </template>
  23. <script setup>
  24. import {
  25. userZhangInfo,
  26. userLocate,
  27. userZhangForntInfo,
  28. userZhangNextInfo,
  29. getCommonZhangInfo
  30. } from "@/api/learnPlan.js"
  31. import {
  32. reactive,
  33. ref,
  34. nextTick,
  35. getCurrentInstance,
  36. onMounted
  37. } from "vue";
  38. import {
  39. onLoad
  40. } from '@dcloudio/uni-app';
  41. import catalogue from "@/components/catalogue/catalogue.vue";
  42. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  43. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  44. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  45. import dSwiper from '@/components/wSwiper/DSwiper.vue';
  46. import shuxueZhangjie from './product/shuxue.vue';
  47. import yingyuZhangjie from './product/yingyu.vue';
  48. import {
  49. useTabBarHistory
  50. } from '@/utils/emitEvents.js';
  51. import eggDialog from './eggDialog.vue'
  52. import {
  53. toast,
  54. getUserIdentity
  55. } from "@/utils/common";
  56. import cacheManager from "@/utils/cacheManager.js";
  57. const tipContent = '付费章节,是否前往开通付费?'; //当前产品
  58. const goPayDialogRef = ref(null);
  59. const youkeDialogRef = ref(null);
  60. const dSwiperRef = ref(null);
  61. const eggDialogRef = ref(null);
  62. const current = ref(0);
  63. const currentDuration = ref(500)
  64. const YouKeContent = '您当前是游客身份,登录后才能浏览内容,现在去登录?';
  65. const zhangId = ref(null); //游客使用
  66. const nianji = ref(null); //游客使用
  67. const cardId = ref(null); //游客使用
  68. const catalogueRef = ref(null);
  69. const currentProduct = ref(null);
  70. const selectZhang = ref(null);
  71. const zhangList = ref(null);
  72. const gradeTerm = ref(null);
  73. let infoData = reactive({
  74. jieList: [],
  75. haveFlag: '',
  76. nianji: '',
  77. number: '',
  78. cardId: '',
  79. zhangId: '',
  80. zhangName: '',
  81. numberStr: '',
  82. });
  83. const gradeMapping = {
  84. 1: '一年级',
  85. 2: '二年级',
  86. 3: '三年级',
  87. 4: '四年级',
  88. 5: '五年级',
  89. 6: '六年级'
  90. };
  91. const termMapping = {
  92. 1: ' 数学',
  93. 2: ' 英语'
  94. };
  95. onLoad((options) => {
  96. init(options)
  97. })
  98. function onChangeTab(e) {
  99. console.log(e.detail.current);
  100. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[e.detail.current].zhangId
  101. cacheManager.updateObject('auth', {
  102. currentZhang: e.detail.current,
  103. zhangId:infoData.zhangId
  104. })
  105. //current.value = e.detail.current;
  106. }
  107. function init(options) {
  108. if (cacheManager.get('auth')) {
  109. //会员 取auth
  110. selectZhang.value = cacheManager.get('auth');
  111. currentProduct.value = cacheManager.get('auth').cardId;
  112. //let currentObject = this.cacheZhangInfo.jieList.find(item => item.jieId == this.jieId);
  113. console.log(selectZhang.value);
  114. // 已登录
  115. if (selectZhang.value.firstLogin) {
  116. nextTick(() => {
  117. eggDialogRef.value.eggShow();
  118. })
  119. }
  120. getZhangInfo()
  121. } else {
  122. zhangId.value = options.zhangId
  123. nianji.value = options.nianji
  124. cardId.value = options.cardId
  125. currentProduct.value = options.cardId
  126. // 未登录 游客
  127. getCommonZhang(options)
  128. }
  129. }
  130. function getZhangInfo(data) {
  131. let req = {
  132. nianji: selectZhang.value.nianji,
  133. cardId: selectZhang.value.cardId,
  134. zhangId: selectZhang.value.zhangId,
  135. }
  136. userZhangInfo(req).then(res => {
  137. cacheManager.set('zhangInfo', res.data)
  138. let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == selectZhang.value.zhangId);
  139. if (zhang != -1) {
  140. cacheManager.updateObject('auth', {
  141. currentZhang: zhang
  142. })
  143. } else {
  144. cacheManager.updateObject('auth', {
  145. currentZhang: 0
  146. })
  147. }
  148. nextTick(() => {
  149. translateData(res.data)
  150. zhangList.value = res.data.zhangList
  151. current.value = cacheManager.get('auth').currentZhang
  152. infoData.zhangId = res.data.zhangList[current.value].zhangId
  153. recordZhangJie()
  154. })
  155. })
  156. }
  157. function getCommonZhang(data) {
  158. let req = {
  159. nianji: data.nianji,
  160. cardId: data.cardId,
  161. zhangId: data.zhangId,
  162. }
  163. getCommonZhangInfo(req).then(res => {
  164. infoData.jieList = res.data.jieList
  165. infoData.haveFlag = res.data.haveFlag
  166. infoData.nianji = res.data.nianji
  167. infoData.number = res.data.number
  168. infoData.numberStr = res.data.numberStr
  169. infoData.cardId = res.data.cardId
  170. infoData.zhangId = res.data.zhangId
  171. infoData.zhangName = res.data.zhangName
  172. //getNewData()
  173. })
  174. }
  175. function getNewData() {
  176. selectZhang.value.zhangId = cacheManager.get('zhangInfo').zhangId;
  177. selectZhang.value.cardId = cacheManager.get('zhangInfo').cardId;
  178. selectZhang.value.nianji = cacheManager.get('zhangInfo').nianji;
  179. cacheManager.updateObject('auth', {
  180. zhangId: selectZhang.value.zhangId,
  181. cardId: selectZhang.value.cardId,
  182. nianji: selectZhang.value.nianji,
  183. })
  184. }
  185. function recordZhangJie() {
  186. let req = {
  187. nianji: selectZhang.value.nianji,
  188. userId: cacheManager.get('auth').userId,
  189. zhangId: infoData.zhangId,
  190. cardId: selectZhang.value.cardId,
  191. }
  192. userLocate(req).then(res => {
  193. })
  194. }
  195. function goPayPage() {
  196. }
  197. function handleChangeZhang(data) {
  198. console.log(data);
  199. selectZhang.value = data;
  200. const authCode = getUserIdentity();
  201. if (authCode !== 'Visitor') {
  202. cacheManager.updateObject('auth', {
  203. zhangId: data.zhangId
  204. })
  205. }
  206. currentDuration.value = 0
  207. setTimeout(() => {
  208. current.value = data.number - 1
  209. nextTick(() => {
  210. currentDuration.value = 500
  211. })
  212. }, 100)
  213. // init()
  214. }
  215. function goKaoshi(data) {
  216. uni.redirectTo({
  217. // url: `/pages/unitTest/index?jieNumber=` + data.number
  218. url: `/pages/unitTest/index?jieId=` + data.jieId
  219. })
  220. }
  221. function goLookShipin(data) {
  222. if (!cacheManager.get('auth')) {
  223. infoData.cardId = cardId.value
  224. infoData.nianji = nianji.value
  225. infoData.zhangId = zhangId.value
  226. uni.redirectTo({
  227. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(infoData)
  228. })
  229. return;
  230. } else {
  231. uni.redirectTo({
  232. url: '/pages/study/lookShipin?jieId=' + data.jieId + '&zhangId=' + infoData.zhangId
  233. })
  234. }
  235. }
  236. function translateData(data) {
  237. gradeTerm.value = gradeMapping[data.nianji] + termMapping[data.cardId]
  238. }
  239. function listClick(data) {
  240. console.log('data', data);
  241. if (!cacheManager.get('auth') && data.firstFlag != 1) {
  242. youkeDialogRef.value.handleShow();
  243. return;
  244. }
  245. const authCode = getUserIdentity();
  246. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  247. goPayDialogRef.value.handleShow();
  248. return false
  249. }
  250. if (data.type == 2) {
  251. // 最后一项
  252. goKaoshi(data)
  253. } else {
  254. goLookShipin(data)
  255. }
  256. }
  257. function handleCheckCatalogue() {
  258. catalogueRef.value.showPopup();
  259. }
  260. function clickGradeTerm() {
  261. cacheManager.updateObject('auth', {
  262. currentZhang: 0
  263. })
  264. uni.navigateTo({
  265. url: `/pages/selectGradesTerms/index`,
  266. })
  267. }
  268. // 游客弹窗---确定
  269. function ykConfirm() {
  270. uni.redirectTo({
  271. url: '/pages/login/index'
  272. });
  273. }
  274. function eggBtn() {
  275. console.log('点击:开启提分之旅');
  276. cacheManager.updateObject('auth', {
  277. firstLogin: false
  278. })
  279. }
  280. </script>
  281. <style>
  282. </style>