selectVersion.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class="grades-terms-page">
  3. <view class="icon-title-navBar-box">
  4. <!-- 返回按钮↓ -->
  5. <view class="nav-bar-icon" @click="handleBack"></view>
  6. </view>
  7. <view class="grade-item-box">
  8. <view :key="item.id" @click="handleTopBottom(item)" v-for="item in data.allList"
  9. :class="['grade-item',{active: item.id == data.shangxiaId}]">{{item.lable}}</view>
  10. </view>
  11. <scroll-view scroll-y="true" class="subject-body" :scroll-into-view="data.scrollTop">
  12. <view class="subject-content-box">
  13. <!-- 产品 -->
  14. <view v-for="item in list" :key="item.id" :id="`s_${item.id}`" @click="handleSelectVersion(item)"
  15. :class="[
  16. 'subject-item',
  17. item.typeId === 1 && 'subject-jstx-item',
  18. {
  19. 'active': item.id == data.shangxiaVersionId
  20. }
  21. ]">
  22. <img :src="item.cover" class="subject-item-img" />
  23. <view class="subject-item-text"><text>{{item.lable}}</text></view>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. <view class="grade-line"></view>
  28. <button class="grade-confirm-btn" @click="handleConfirm"></button>
  29. </view>
  30. </template>
  31. <script setup>
  32. import {
  33. reactive,
  34. toRefs,
  35. toRef,
  36. computed,
  37. nextTick,
  38. ref,
  39. } from "vue";
  40. import * as httpApi from "@/api/selectGradesTerms.js";
  41. import {
  42. getUserIdentity,
  43. findRootNode,
  44. findTreeNode
  45. } from "@/utils/common.js"
  46. import cacheManager from "@/utils/cacheManager.js"
  47. import {
  48. getCommonTree,
  49. getIndexTree
  50. } from "../../api/selectGradesTerms";
  51. import {
  52. onLoad
  53. } from "@dcloudio/uni-app";
  54. const data = reactive({
  55. scrollTop: '',
  56. allList: [],
  57. levelId: null,
  58. typeId: null,
  59. subjectId: null,
  60. tipFlag: null,
  61. shangxiaId: 1, // 上下册
  62. shangxiaVersionId: null, // 当前版本
  63. })
  64. const list = computed(() => {
  65. if (!data.allList.length) {
  66. return []
  67. }
  68. const d_id = data.shangxiaId;
  69. return data.allList.find(item => item.id == d_id).children
  70. })
  71. onLoad(({
  72. levelId,
  73. subjectId,
  74. shangxiaId, // 上下册Id
  75. shangxiaVersionId, // 上下册版本Id
  76. typeId,
  77. tipFlag
  78. }) => {
  79. const userCode = getUserIdentity();
  80. if (userCode !== 'Visitor') {
  81. initUserProducts();
  82. } else {
  83. data.levelId = levelId;
  84. data.subjectId = subjectId || 1;
  85. data.shangxiaId = shangxiaId || 1; // 默认选中上册
  86. data.shangxiaVersionId = shangxiaVersionId; // 默认选中上册
  87. data.typeId = typeId;
  88. data.activeTipFlag = tipFlag || '0';
  89. initVisitProducts();
  90. }
  91. });
  92. function handleBack() {
  93. const userCode = getUserIdentity();
  94. if (userCode !== 'Visitor') {
  95. if (!data.activeProduct) {
  96. return;
  97. }
  98. const auth = cacheManager.get('auth');
  99. uni.redirectTo({
  100. url: `/pages/selectGradesTerms/index`
  101. })
  102. } else {
  103. uni.redirectTo({
  104. url: `/pages/selectGradesTerms/index?productId=${data.levelId}&xuekeId=${data.subjectId}&tipFlag=${data.tipFlag}`
  105. })
  106. }
  107. }
  108. function handleTopBottom(item) {
  109. data.shangxiaId = item.id;
  110. data.shangxiaVersionId = null;
  111. }
  112. function handleSelectVersion(item) {
  113. data.shangxiaVersionId = item.id
  114. }
  115. function handleConfirm() {
  116. if (!data.shangxiaId) {
  117. uni.showToast({
  118. title: "请选择上下册",
  119. duration: 2000,
  120. icon: 'error'
  121. });
  122. return;
  123. }
  124. if (!data.shangxiaVersionId) {
  125. uni.showToast({
  126. title: "请选择版本",
  127. duration: 2000,
  128. icon: 'error'
  129. });
  130. return;
  131. }
  132. goDAOToStudy();
  133. }
  134. // 跳转 岛 学习
  135. function goDAOToStudy() {
  136. const userCode = getUserIdentity();
  137. if (userCode !== 'Visitor') {
  138. const auth = cacheManager.get('auth');
  139. cacheManager.updateObject('auth', {
  140. // 修改上下册+版本字段
  141. })
  142. // 通知岛重新调用接口
  143. cacheManager.remove('daoPageCache')
  144. uni.redirectTo({
  145. url: `/pages/study/index`
  146. })
  147. } else {
  148. // 新英语岛
  149. uni.redirectTo({
  150. url: `/pages/study/index?levelId=${data.levelId}&typeId=${data.typeId}&subjectId=${data.subjectId}&tipFlag=${data.activeTipFlag}`
  151. })
  152. }
  153. }
  154. function initUserProducts() {
  155. httpApi.getUserZhangList({
  156. levelId: data.levelId
  157. }).then(res => {
  158. data.allList = res.data || [];
  159. const {
  160. levelId,
  161. } = cacheManager.get('auth');
  162. if (levelId) {
  163. // LevelId 翻找根节点学科,执行选中高亮操作
  164. const obj1 = findRootNode(data.allList, shangxiaId, 'shangxiaId');
  165. const obj2 = findTreeNode(data.allList, shangxiaId, 'children', 'shangxiaId');
  166. data.shangxiaVersionId = obj2.id;
  167. data.shangxiaId = obj1.id;
  168. } else {
  169. data.shangxiaVersionId = null;
  170. data.shangxiaId = 1
  171. }
  172. nextTick(() => {
  173. // 滚动到某个元素显示
  174. data.scrollTop = `s_${data.shangxiaVersionId}`
  175. })
  176. })
  177. }
  178. function initVisitProducts() {
  179. httpApi.getCommonZhangList({
  180. levelId: data.levelId
  181. }).then(res => {
  182. data.allList = res.data || [];
  183. })
  184. }
  185. </script>
  186. <style>
  187. </style>