catalogue.vue 7.0 KB

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