catalogue.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  3. mask-background-color="rgba(255, 255, 255, 0.6);" :is-shadow="false">
  4. <scroll-view :scroll-y="true" :scroll-top="scrollTop" class="ezy-catalogue-dialog"
  5. :style="{backgroundImage: 'url(' + catalogueBjFun() + ')'}">
  6. <uni-icons @click="handleClose" class="catalogue-close-btn"></uni-icons>
  7. <!-- 当前上下册只针对数学 -->
  8. <view v-if="subjectId == 1" class="catalogue-levelId-title">L{{levelId}}上</view>
  9. <!-- 目录区域 -->
  10. <uni-collapse v-model="activeCollapse" class="ezy-catalogue-collapse"
  11. :class="{ 'ezy-catalogue-collapse-vip': AuthCode === 'VIP'}" accordion>
  12. <template v-for="(item,index) in list">
  13. <!-- 当前上下册只针对数学 -->
  14. <view v-if="subjectId == 1 && index == shuxueShangxia" class="catalogue-levelId-title catalogue-mt">
  15. L{{levelId}}下</view>
  16. <uni-collapse-item title-border="none" :border="false" :name="index+''" class="collapse-item-box"
  17. :class="{ 'collapse-active': activeCollapse === index+''}">
  18. <template v-slot:title>
  19. <view @click.stop="handleSelectZhang(item,index)" class="collapse-title">
  20. <view class="collapse-num-box">{{index+1}}</view>
  21. <!-- 章名 -->
  22. <text class="collapse-name">{{item.zhangName}}</text>
  23. <!-- 锁 -->
  24. <template v-if="AuthCode !== 'VIP'">
  25. <view class="collapse-lock" v-if="index!=0"></view>
  26. </template>
  27. </view>
  28. </template>
  29. <view class="collapse-content-box">
  30. <view v-for="(jie,cindex) in item.jieList" class="collapse-content-item"
  31. @click="handleJieClick(item,jie,index,cindex)">
  32. <text class="jie-index">{{`${index+1}.${cindex+1}`}}</text>
  33. <text class="text">{{jie.jieName}}</text>
  34. </view>
  35. </view>
  36. </uni-collapse-item>
  37. </template>
  38. </uni-collapse>
  39. <tip-small-dialog ref="confirmDialogRef" @confirm-btn="handleConfirmPay"
  40. :content="Message"></tip-small-dialog>
  41. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  42. </scroll-view>
  43. </uni-popup>
  44. </template>
  45. <script setup>
  46. import {
  47. useCatalogue
  48. } from './useCatalogue';
  49. import {
  50. ref,
  51. } from "vue";
  52. import {
  53. getUserIdentity
  54. } from "@/utils/common.js"
  55. import {
  56. MESSAGE_VISITER_TO_LOGIN,
  57. MESSAGE_BEFORE_PAY
  58. } from "@/utils/constant.js"
  59. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  60. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  61. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  62. import cacheManager from "@/utils/cacheManager.js";
  63. import {
  64. onShow,
  65. onLoad
  66. } from '@dcloudio/uni-app';
  67. const ShuxueObj = {
  68. 1: 6,
  69. 2: 6,
  70. 3: 11,
  71. 4: 11,
  72. 5: 11,
  73. 6: 12,
  74. }
  75. const growthType = ref(null);
  76. const AuthCode = ref(null);
  77. const scrollTop = ref(0)
  78. const subjectId = ref(null)
  79. const shuxueShangxia = ref(0);
  80. const levelId = ref(null);
  81. onShow(() => AuthCode.value = getUserIdentity()); // 用户身份
  82. onLoad((options) => {
  83. if (cacheManager.get('auth')) {
  84. subjectId.value = cacheManager.get('auth').subjectId;
  85. } else {
  86. subjectId.value = options.subjectId;
  87. }
  88. if (subjectId.value == 1) {
  89. if (cacheManager.get('auth')) {
  90. levelId.value = cacheManager.get('auth').levelId;
  91. } else {
  92. levelId.value = options.levelId;
  93. }
  94. shuxueShangxia.value = ShuxueObj[levelId.value];
  95. }
  96. })
  97. const $emit = defineEmits(['change-zhang'])
  98. const {
  99. getCatalogue
  100. } = useCatalogue();
  101. const popupRef = ref(null); // 索引
  102. const confirmDialogRef = ref(null);
  103. const activeCollapse = ref('');
  104. const Message = MESSAGE_BEFORE_PAY;
  105. const youkeDialogRef = ref(null);
  106. const selectZhang = ref(null);
  107. const props = defineProps({
  108. list: {
  109. type: Array,
  110. }
  111. })
  112. function handleJieClick(item, jie, index, cindex) {
  113. selectZhang.value = item;
  114. if (index == 0) {
  115. // 全员可访问 第一章 第一节
  116. this.$emit('listSelectJieClick', item, jie, cindex);
  117. return;
  118. }
  119. if (AuthCode.value == 'Visitor') {
  120. // 游客
  121. youkeDialogRef.value.handleShow();
  122. return;
  123. }
  124. if (AuthCode.value == 'Not-Vip') {
  125. // 非VIP
  126. confirmDialogRef.value.handleShow();
  127. return;
  128. }
  129. // Vip
  130. this.$emit('listSelectJieClick', item, jie, cindex);
  131. }
  132. function catalogueBjFun() {
  133. if (subjectId.value == 1) {
  134. // 数学
  135. return 'static/images/catalog/catalog-shuxue-bj.png'
  136. } else if (subjectId.value == 2) {
  137. // 英语
  138. return 'static/images/catalog/catalog-yingyu-bj.png'
  139. }
  140. }
  141. function ykConfirm() {
  142. uni.redirectTo({
  143. url: '/pages/login/index'
  144. });
  145. }
  146. /**
  147. * @summary 展示弹窗 暴露函数
  148. */
  149. async function showPopup(data) {
  150. let callback = null;
  151. if (data) {
  152. const index = props.list.findIndex(item => item.zhangId == data.zhangId);
  153. scrollTop.value = 0;
  154. activeCollapse.value = '';
  155. // 滚动高度
  156. callback = () => {
  157. console.log('uni.getTopWindowStyle()', uni.getSystemInfoSync().screenWidth)
  158. if (subjectId.value == 2) {
  159. // 英语
  160. activeCollapse.value = index + '';
  161. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index;
  162. } else {
  163. // 数学
  164. if (index < shuxueShangxia.value) {
  165. activeCollapse.value = index + '';
  166. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (uni
  167. .getSystemInfoSync().screenWidth / 750) * 50;
  168. } else {
  169. activeCollapse.value = index + '';
  170. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (uni
  171. .getSystemInfoSync().screenWidth / 750) * 50 * 2;
  172. }
  173. }
  174. }
  175. }
  176. handleShow(callback);
  177. }
  178. /**
  179. * @summary 展示目录弹窗
  180. */
  181. function handleShow(callback) {
  182. popupRef.value.open('center');
  183. if (callback) {
  184. }
  185. setTimeout(() => callback(), 50)
  186. }
  187. /**
  188. * @summary 关闭目录弹窗
  189. */
  190. function handleClose() {
  191. popupRef.value.close();
  192. }
  193. /**
  194. * @summary 选中
  195. * @param({zhangId:string}) data
  196. */
  197. function handleSelectZhang(data, index) {
  198. selectZhang.value = data;
  199. if (index != 0 && AuthCode.value == 'Visitor') {
  200. // 游客
  201. youkeDialogRef.value.handleShow();
  202. return;
  203. }
  204. if (index != 0 && AuthCode.value == 'Not-Vip') {
  205. // 非VIP
  206. confirmDialogRef.value.handleShow();
  207. return;
  208. }
  209. $emit('change-zhang', Object.assign({}, data));
  210. handleClose();
  211. }
  212. function handleConfirmPay() {
  213. const url =
  214. `/pages/pay/svip?subjectId=${subjectId.value}&formPage=studyWithCatalgue&selectZhangId=${selectZhang.value.zhangId}`
  215. uni.redirectTo({
  216. url
  217. })
  218. }
  219. defineExpose({
  220. showPopup
  221. })
  222. </script>