catalogue.vue 6.8 KB

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