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 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. $emit('change-zhang', Object.assign({}, item));
  112. handleClose();
  113. }
  114. function catalogueBjFun() {
  115. if (subjectId.value == 1 && typeId.value == 1) {
  116. // 数学 新
  117. return 'static/images/catalog/catalog-shuxue-bj.png'
  118. } else if (subjectId.value == 1 && typeId.value == 2) {
  119. // 英语 旧
  120. return 'static/images/catalog/catalog-shuxue-bj.png'
  121. } else if (subjectId.value == 2 && typeId.value == 2) {
  122. // 英语 旧
  123. return 'static/images/catalog/catalog-yingyu-bj.png'
  124. } else if (subjectId.value == 2 && typeId.value == 1) {
  125. // 英语 新
  126. return 'static/images/catalog/catalog-newyYingyu-bj.png'
  127. }
  128. }
  129. function ykConfirm() {
  130. uni.redirectTo({
  131. url: '/pages/login/index'
  132. });
  133. }
  134. /**
  135. * @summary 展示弹窗 暴露函数
  136. */
  137. async function showPopup(data) {
  138. handleShow(data);
  139. }
  140. function getFormatZhangListByArray(data) {
  141. const myList = data.reduce((acc, curr) => acc.concat(curr.zhangList || []), [])
  142. const jiedian = data[0].zhangList.length;
  143. return {
  144. myList,
  145. jiedian,
  146. jieText: data.map(item => item.lable)
  147. }
  148. }
  149. /**
  150. * @summary 展示目录弹窗
  151. */
  152. function handleShow(data) {
  153. console.log('33333',data)
  154. getCatalogue().then(([err, wlist]) => {
  155. console.log('wlist',wlist)
  156. if (err) {
  157. return;
  158. }
  159. const {
  160. myList,
  161. jiedian,
  162. jieText
  163. } = getFormatZhangListByArray(wlist)
  164. list.value = myList;
  165. if (list.value) {
  166. jieTexts.value = jieText;
  167. shuxueShangxia.value = jiedian;
  168. if (data) {
  169. let callback = null;
  170. const index = myList.findIndex(item => item.zhangId == data.zhangId);
  171. scrollTop.value = 0;
  172. activeCollapse.value = '';
  173. // 滚动高度
  174. callback = () => {
  175. console.log('uni.getTopWindowStyle()', uni.getSystemInfoSync().screenWidth)
  176. if (subjectId.value == 2) {
  177. // 英语
  178. activeCollapse.value = index + '';
  179. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index;
  180. } else {
  181. // 数学
  182. if (index < shuxueShangxia.value) {
  183. activeCollapse.value = index + '';
  184. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (
  185. uni
  186. .getSystemInfoSync().screenWidth / 750) * 50;
  187. } else {
  188. activeCollapse.value = index + '';
  189. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (
  190. uni
  191. .getSystemInfoSync().screenWidth / 750) * 50 * 2;
  192. }
  193. }
  194. }
  195. setTimeout(() => callback(), 50)
  196. }
  197. }
  198. popupRef.value.open('center');
  199. })
  200. }
  201. /**
  202. * @summary 关闭目录弹窗
  203. */
  204. function handleClose() {
  205. popupRef.value.close();
  206. }
  207. /**
  208. * @summary 选中
  209. * @param({zhangId:string}) data
  210. */
  211. function handleSelectZhang(data, index) {
  212. selectZhang.value = data;
  213. $emit('change-zhang', Object.assign({}, data));
  214. handleClose();
  215. }
  216. function handleConfirmPay() {
  217. /*const url =
  218. `/pages/pay/svip?subjectId=${subjectId.value}&formPage=studyWithCatalgue&selectZhangId=${selectZhang.value.zhangId}`
  219. uni.redirectTo({
  220. url
  221. })*/
  222. }
  223. defineExpose({
  224. showPopup
  225. })
  226. </script>