catalogue.vue 6.4 KB

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