selectVersion.vue 4.7 KB

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