catalogue.vue 6.5 KB

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