catalogue.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. <view class="ezy-catalogue-dialog">
  5. <uni-icons @click="handleClose" class="catalogue-close-btn"></uni-icons>
  6. <!-- 目录区域 -->
  7. <uni-collapse v-model="activeCollapse" class="ezy-catalogue-collapse" accordion>
  8. <uni-collapse-item title-border="none" :border="false" :name="index+''" v-for="(item,index) in list"
  9. class="collapse-item-box" :class="{ 'collapse-active': activeCollapse === index+''}">
  10. <template v-slot:title>
  11. <view @click.stop="handleSelectZhang(item,index)" class="collapse-title">
  12. <view class="collapse-num-box">{{index+1}}</view>
  13. <!-- 章名 -->
  14. <text class="collapse-name">{{item.zhangName}}</text>
  15. <!-- 锁 -->
  16. <template v-if="AuthCode !== 'VIP'">
  17. <view class="collapse-lock" v-if="index!=0"></view>
  18. </template>
  19. </view>
  20. </template>
  21. <view class="collapse-content-box">
  22. <view v-for="(jie,cindex) in item.jieList" class="collapse-content-item">
  23. <text class="jie-index">{{`${index+1}.${cindex+1}`}}</text>
  24. <text class="text">{{jie.jieName}}</text>
  25. </view>
  26. </view>
  27. </uni-collapse-item>
  28. </uni-collapse>
  29. <tip-small-dialog ref="confirmDialogRef" @confirm-btn="handleConfirmPay" :content="Message"></tip-small-dialog>
  30. </view>
  31. </uni-popup>
  32. </template>
  33. <script setup>
  34. import {
  35. useCatalogue
  36. } from './useCatalogue';
  37. import {
  38. ref
  39. } from "vue";
  40. import {
  41. toast
  42. } from "@/utils/common.js"
  43. import {getUserIdentity} from "@/utils/common.js"
  44. import {MESSAGE_VISITER_TO_LOGIN,MESSAGE_BEFORE_PAY} from "@/utils/constant.js"
  45. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  46. const $emit = defineEmits(['change-zhang'])
  47. const {
  48. nianji,
  49. xueke,
  50. getCatalogue,
  51. } = useCatalogue(props);
  52. const popupRef = ref(null); // 索引
  53. const confirmDialogRef = ref(null);
  54. const list = ref([]); // 章节
  55. const activeCollapse = ref('');
  56. const Message = MESSAGE_BEFORE_PAY;
  57. const AuthCode = getUserIdentity(); // 用户身份
  58. /**
  59. * @summary 展示弹窗 暴露函数
  60. */
  61. async function showPopup() {
  62. const [err, data] = await getCatalogue();
  63. if (err) {
  64. toast("章节目录数据获取失败");
  65. return;
  66. }
  67. refreshCatalogue(data);
  68. handleShow();
  69. }
  70. /**
  71. * @param([]) 章节赋值
  72. */
  73. function refreshCatalogue(data) {
  74. list.value = data;
  75. }
  76. /**
  77. * @summary 展示目录弹窗
  78. */
  79. function handleShow() {
  80. popupRef.value.open('center');
  81. }
  82. /**
  83. * @summary 关闭目录弹窗
  84. */
  85. function handleClose() {
  86. popupRef.value.close();
  87. }
  88. /**
  89. * @summary 选中
  90. * @param({zhangId:string}) data
  91. */
  92. function handleSelectZhang(data,index) {
  93. if(index !=0 && AuthCode == 'Visitor'){
  94. // 游客
  95. toast(MESSAGE_VISITER_TO_LOGIN)
  96. return;
  97. }
  98. if(index !=0 && AuthCode == 'Not-Vip'){
  99. // 非VIP
  100. popupRef.value.close();
  101. confirmDialogRef.value.handleShow();
  102. return;
  103. }
  104. $emit('change-zhang', Object.assign({}, data));
  105. handleClose();
  106. }
  107. function handleConfirmPay() {
  108. uni.redirectTo({ url: '/pages/pay/svip' })
  109. }
  110. defineExpose({
  111. showPopup
  112. })
  113. </script>