index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class="ezy-study-page">
  3. {{currentProduct}}
  4. <shuxueZhangjie v-if="currentProduct ==1" @clickGradeTerm="clickGradeTerm" @onLeft="onLeft" @onRight="onRight"
  5. @handleCheckCatalogue="handleCheckCatalogue" @listClick="listClick" :options="infoData">
  6. </shuxueZhangjie>
  7. <yingyuZhangjie v-if="currentProduct ==2" @clickGradeTerm="clickGradeTerm" @onLeft="onLeft" @onRight="onRight"
  8. @handleCheckCatalogue="handleCheckCatalogue" @listClick="listClick" :options="infoData">
  9. </yingyuZhangjie>
  10. <!-- 蛋 -->
  11. <egg-dialog ref="eggDialogRef" @eggBtn="eggBtn"></egg-dialog>
  12. <catalogue ref="catalogueRef" @change-zhang="handleChangeZhang"></catalogue>
  13. <CustomTabBar :cardId="cardId" :nianji="nianji" :zhangId="zhangId"></CustomTabBar>
  14. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPayPage" :content="tipContent"></tip-small-dialog>
  15. </view>
  16. </template>
  17. <script setup>
  18. import {
  19. userZhangInfo,
  20. userLocate,
  21. userZhangForntInfo,
  22. userZhangNextInfo,
  23. getCommonZhangInfo
  24. } from "@/api/learnPlan.js"
  25. import {
  26. reactive,
  27. ref,
  28. getCurrentInstance,
  29. onMounted
  30. } from "vue";
  31. import {
  32. onLoad
  33. } from '@dcloudio/uni-app';
  34. import catalogue from "@/components/catalogue/catalogue.vue";
  35. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  36. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  37. import shuxueZhangjie from './product/shuxue.vue';
  38. import yingyuZhangjie from './product/yingyu.vue';
  39. import {
  40. useTabBarHistory
  41. } from '@/utils/emitEvents.js';
  42. import eggDialog from './eggDialog.vue'
  43. import {
  44. toast,getUserIdentity
  45. } from "@/utils/common";
  46. import cacheManager from "@/utils/cacheManager.js";
  47. const tipContent = '付费章节,是否前往开通付费?'; //当前产品
  48. const goPayDialogRef = ref(null);
  49. const eggDialogRef = ref(null);
  50. const zhangId = ref(null); //游客使用
  51. const nianji = ref(null);//游客使用
  52. const cardId = ref(null);//游客使用
  53. const catalogueRef = ref(null);
  54. const currentProduct = ref(null);
  55. const selectZhang = ref(null);
  56. let infoData = reactive({
  57. jieList: [],
  58. haveFlag: '',
  59. nianji: '',
  60. number: '',
  61. cardId: '',
  62. zhangId: '',
  63. zhangName: '',
  64. numberStr: '',
  65. });
  66. onLoad((options) => {
  67. init(options)
  68. })
  69. function init(options){
  70. if (cacheManager.get('auth')) {
  71. currentProduct.value = cacheManager.get('auth').cardId;
  72. //会员 取auth
  73. selectZhang.value = cacheManager.get('auth');
  74. console.log(selectZhang.value);
  75. // 已登录
  76. // 选择年级进入调用此接口
  77. //options.flag == 'selectGrades'
  78. getZhangInfo()
  79. // 蛋
  80. // eggDialogRef.value.eggShow();
  81. } else {
  82. zhangId.value = options.zhangId
  83. nianji.value = options.nianji
  84. cardId.value = options.cardId
  85. currentProduct.value = options.cardId
  86. // 未登录 游客
  87. getCommonZhang(options)
  88. }
  89. }
  90. function getZhangInfo(data) {
  91. let req = {
  92. nianji: selectZhang.value.nianji,
  93. cardId: selectZhang.value.cardId,
  94. zhangId: selectZhang.value.zhangId,
  95. }
  96. userZhangInfo(req).then(res => {
  97. cacheManager.set('zhangInfo', res.data)
  98. infoData.jieList = res.data.jieList
  99. infoData.haveFlag = res.data.haveFlag
  100. infoData.nianji = res.data.nianji
  101. infoData.number = res.data.number
  102. infoData.numberStr = res.data.numberStr
  103. infoData.cardId = res.data.cardId
  104. infoData.zhangId = res.data.zhangId
  105. infoData.zhangName = res.data.zhangName
  106. recordZhangJie()
  107. getNewData()
  108. // if (cacheManager.get('zhangInfo')) {
  109. // cacheManager.remove('zhangInfo')
  110. // cacheManager.set('zhangInfo', res.data)
  111. // } else {
  112. // cacheManager.set('zhangInfo', res.data)
  113. // }
  114. })
  115. }
  116. function getCommonZhang(data) {
  117. let req = {
  118. nianji: data.nianji,
  119. cardId: data.cardId,
  120. zhangId:data.zhangId,
  121. }
  122. getCommonZhangInfo(req).then(res => {
  123. infoData.jieList = res.data.jieList
  124. infoData.haveFlag = res.data.haveFlag
  125. infoData.nianji = res.data.nianji
  126. infoData.number = res.data.number
  127. infoData.numberStr = res.data.numberStr
  128. infoData.cardId = res.data.cardId
  129. infoData.zhangId = res.data.zhangId
  130. infoData.zhangName = res.data.zhangName
  131. //getNewData()
  132. })
  133. }
  134. function onLeft(event) {
  135. console.log('用户左滑了');
  136. let req = {
  137. nianji: selectZhang.value.nianji,
  138. zhangId: selectZhang.value.zhangId,
  139. cardId: selectZhang.value.cardId,
  140. }
  141. userZhangForntInfo(req).then(res => {
  142. cacheManager.set('zhangInfo', res.data)
  143. infoData.jieList = res.data.jieList
  144. infoData.haveFlag = res.data.haveFlag
  145. infoData.nianji = res.data.nianji
  146. infoData.number = res.data.number
  147. infoData.numberStr = res.data.numberStr
  148. infoData.cardId = res.data.cardId
  149. infoData.zhangId = res.data.zhangId
  150. infoData.zhangName = res.data.zhangName
  151. recordZhangJie()
  152. getNewData()
  153. })
  154. }
  155. function onRight(event) {
  156. console.log('用户又滑了');
  157. let req = {
  158. nianji: selectZhang.value.nianji,
  159. zhangId: selectZhang.value.zhangId,
  160. cardId: selectZhang.value.cardId,
  161. }
  162. userZhangNextInfo(req).then(res => {
  163. cacheManager.set('zhangInfo', res.data)
  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. recordZhangJie()
  173. getNewData()
  174. })
  175. }
  176. function getNewData() {
  177. selectZhang.value.zhangId = cacheManager.get('zhangInfo').zhangId;
  178. selectZhang.value.cardId = cacheManager.get('zhangInfo').cardId;
  179. selectZhang.value.nianji = cacheManager.get('zhangInfo').nianji;
  180. cacheManager.updateObject('auth', {
  181. zhangId: selectZhang.value.zhangId,
  182. cardId: selectZhang.value.cardId,
  183. nianji: selectZhang.value.nianji,
  184. })
  185. }
  186. function recordZhangJie() {
  187. let req = {
  188. nianji: selectZhang.value.nianji,
  189. userId: cacheManager.get('auth').userId,
  190. zhangId: infoData.zhangId,
  191. cardId: selectZhang.value.cardId,
  192. }
  193. userLocate(req).then(res => {
  194. })
  195. }
  196. function goPayPage(){
  197. }
  198. function handleChangeZhang(data) {
  199. selectZhang.value = data;
  200. const authCode = getUserIdentity();
  201. if (authCode !== 'Visitor') {
  202. cacheManager.updateObject('auth', {
  203. zhangId: data.zhangId
  204. })
  205. }
  206. init()
  207. }
  208. function goKaoshi(data) {
  209. uni.redirectTo({
  210. url: `/pages/unitTest/index?jieNumber=`+data.number
  211. })
  212. }
  213. function goLookShipin(data) {
  214. uni.redirectTo({
  215. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  216. url: '/pages/study/lookShipin?jieNumber='+data.number
  217. })
  218. }
  219. function listClick(data, index) {
  220. if (!cacheManager.get('auth')) {
  221. toast("当前为游客模式请登录!")
  222. uni.redirectTo({
  223. url: '/pages/login/index'
  224. })
  225. return;
  226. }
  227. const authCode = getUserIdentity();
  228. if (!(authCode=='VIP' || data.number == 1)) {
  229. goPayDialogRef.value.handleShow();
  230. return false
  231. }
  232. if (data.number == infoData.jieList.length &&data.jieName=='单元测试') {
  233. // 最后一项
  234. goKaoshi(data)
  235. } else {
  236. goLookShipin(data)
  237. }
  238. }
  239. function handleCheckCatalogue() {
  240. catalogueRef.value.showPopup();
  241. }
  242. function clickGradeTerm() {
  243. uni.navigateTo({
  244. url: `/pages/selectGradesTerms/index`,
  245. })
  246. }
  247. function eggBtn() {
  248. console.log('点击:开启提分之旅');
  249. }
  250. </script>
  251. <style>
  252. </style>