catalogue.vue 7.2 KB

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