catalogue.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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">{{ jieTexts ? jieTexts[0]: ''}}</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. {{jieTexts ? jieTexts[1]: ''}}</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. // 旧道,上下分册 LevelId
  68. const ShuxueObj = {
  69. 7: 6,
  70. 8: 6,
  71. 9: 11,
  72. 10: 11,
  73. 11: 11,
  74. 12: 12,
  75. }
  76. const growthType = ref(null);
  77. const AuthCode = ref(null);
  78. const scrollTop = ref(0)
  79. const subjectId = ref(null)
  80. const shuxueShangxia = ref(0);
  81. const levelId = ref(null);
  82. onShow(() => AuthCode.value = getUserIdentity()); // 用户身份
  83. onLoad((options) => {
  84. if (cacheManager.get('auth')) {
  85. subjectId.value = cacheManager.get('auth').subjectId;
  86. } else {
  87. subjectId.value = options.subjectId;
  88. }
  89. if (subjectId.value == 1) {
  90. if (cacheManager.get('auth')) {
  91. levelId.value = cacheManager.get('auth').levelId;
  92. } else {
  93. levelId.value = options.levelId;
  94. }
  95. // shuxueShangxia.value = ShuxueObj[levelId.value];
  96. }
  97. })
  98. const $emit = defineEmits(['change-zhang'])
  99. const {
  100. getCatalogue
  101. } = useCatalogue();
  102. const popupRef = ref(null); // 索引
  103. const confirmDialogRef = ref(null);
  104. const activeCollapse = ref('');
  105. const Message = MESSAGE_BEFORE_PAY;
  106. const youkeDialogRef = ref(null);
  107. const selectZhang = ref(null);
  108. const list = ref([])
  109. const jieTexts = ref([])
  110. function handleJieClick(item, jie, index, cindex) {
  111. selectZhang.value = item;
  112. // this.$emit('listSelectJieClick', item, jie, cindex);
  113. $emit('change-zhang', Object.assign({}, item));
  114. handleClose();
  115. }
  116. function catalogueBjFun() {
  117. if (subjectId.value == 1) {
  118. // 数学
  119. return 'static/images/catalog/catalog-shuxue-bj.png'
  120. } else if (subjectId.value == 2) {
  121. // 英语
  122. return 'static/images/catalog/catalog-yingyu-bj.png'
  123. }
  124. }
  125. function ykConfirm() {
  126. uni.redirectTo({
  127. url: '/pages/login/index'
  128. });
  129. }
  130. /**
  131. * @summary 展示弹窗 暴露函数
  132. */
  133. async function showPopup(data) {
  134. handleShow(data);
  135. }
  136. function getFormatZhangListByArray(data) {
  137. const myList = data.reduce((acc, curr) => acc.concat(curr.zhangList || []), [])
  138. const jiedian = data[0].zhangList.length;
  139. return {
  140. myList,
  141. jiedian,
  142. jieText: data.map(item => item.lable)
  143. }
  144. }
  145. /**
  146. * @summary 展示目录弹窗
  147. */
  148. function handleShow(data) {
  149. getCatalogue().then(([err, wlist]) => {
  150. if (err) {
  151. return;
  152. }
  153. const {myList,jiedian, jieText} = getFormatZhangListByArray(wlist)
  154. list.value = myList;
  155. if (list.value) {
  156. jieTexts.value = jieText;
  157. shuxueShangxia.value = jiedian;
  158. if (data) {
  159. let callback = null;
  160. const index = myList.findIndex(item => item.zhangId == data.zhangId);
  161. scrollTop.value = 0;
  162. activeCollapse.value = '';
  163. // 滚动高度
  164. callback = () => {
  165. console.log('uni.getTopWindowStyle()', uni.getSystemInfoSync().screenWidth)
  166. if (subjectId.value == 2) {
  167. // 英语
  168. activeCollapse.value = index + '';
  169. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index;
  170. } else {
  171. // 数学
  172. if (index < shuxueShangxia.value) {
  173. activeCollapse.value = index + '';
  174. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (uni
  175. .getSystemInfoSync().screenWidth / 750) * 50;
  176. } else {
  177. activeCollapse.value = index + '';
  178. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (uni
  179. .getSystemInfoSync().screenWidth / 750) * 50 * 2;
  180. }
  181. }
  182. }
  183. setTimeout(() => callback(), 50)
  184. }
  185. }
  186. popupRef.value.open('center');
  187. })
  188. }
  189. /**
  190. * @summary 关闭目录弹窗
  191. */
  192. function handleClose() {
  193. popupRef.value.close();
  194. }
  195. /**
  196. * @summary 选中
  197. * @param({zhangId:string}) data
  198. */
  199. function handleSelectZhang(data, index) {
  200. selectZhang.value = data;
  201. $emit('change-zhang', Object.assign({}, data));
  202. handleClose();
  203. }
  204. function handleConfirmPay() {
  205. const url =
  206. `/pages/pay/svip?subjectId=${subjectId.value}&formPage=studyWithCatalgue&selectZhangId=${selectZhang.value.zhangId}`
  207. uni.redirectTo({
  208. url
  209. })
  210. }
  211. defineExpose({
  212. showPopup
  213. })
  214. </script>