catalogue.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. <view class="ezy-catalogue-dialog" :style="{backgroundImage: 'url(' + catalogueBjFun() + ')'}">
  5. <uni-icons @click="handleClose" class="catalogue-close-btn"></uni-icons>
  6. <scroll-view :scroll-y="true" :scroll-top="scrollTop" >
  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. </view>
  50. </uni-popup>
  51. </template>
  52. <script setup>
  53. import {
  54. useCatalogue
  55. } from './useCatalogue';
  56. import {
  57. ref,
  58. } from "vue";
  59. import {
  60. getUserIdentity
  61. } from "@/utils/common.js"
  62. import {
  63. MESSAGE_VISITER_TO_LOGIN,
  64. MESSAGE_BEFORE_PAY
  65. } from "@/utils/constant.js"
  66. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  67. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  68. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  69. import cacheManager from "@/utils/cacheManager.js";
  70. import {
  71. onShow,
  72. onLoad
  73. } from '@dcloudio/uni-app';
  74. const growthType = ref(null);
  75. const AuthCode = ref(null);
  76. const scrollTop = ref(0)
  77. const subjectId = ref(null)
  78. const shuxueShangxia = ref(0);
  79. const levelId = ref(null);
  80. const typeId = ref(null);
  81. onShow(() => AuthCode.value = getUserIdentity()); // 用户身份
  82. onLoad((options) => {
  83. if (cacheManager.get('auth')) {
  84. subjectId.value = cacheManager.get('auth').subjectId;
  85. typeId.value = cacheManager.get('auth').typeId;
  86. } else {
  87. subjectId.value = options.subjectId;
  88. typeId.value = options.typeId;
  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. }
  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. $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. console.log('33333',data)
  155. getCatalogue().then(([err, wlist]) => {
  156. console.log('wlist',wlist)
  157. if (err) {
  158. return;
  159. }
  160. const {
  161. myList,
  162. jiedian,
  163. jieText
  164. } = getFormatZhangListByArray(wlist)
  165. list.value = myList;
  166. if (list.value) {
  167. jieTexts.value = jieText;
  168. shuxueShangxia.value = jiedian;
  169. if (data) {
  170. let callback = null;
  171. const index = myList.findIndex(item => item.zhangId == data.zhangId);
  172. scrollTop.value = 0;
  173. activeCollapse.value = '';
  174. // 滚动高度
  175. callback = () => {
  176. console.log('uni.getTopWindowStyle()', uni.getSystemInfoSync().screenWidth)
  177. if (subjectId.value == 2) {
  178. // 英语
  179. activeCollapse.value = index + '';
  180. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index;
  181. } else {
  182. // 数学
  183. if (index < shuxueShangxia.value) {
  184. activeCollapse.value = index + '';
  185. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (
  186. uni
  187. .getSystemInfoSync().screenWidth / 750) * 50;
  188. } else {
  189. activeCollapse.value = index + '';
  190. scrollTop.value = (uni.getSystemInfoSync().screenWidth / 750) * 50 * index + (
  191. uni
  192. .getSystemInfoSync().screenWidth / 750) * 50 * 2;
  193. }
  194. }
  195. }
  196. setTimeout(() => callback(), 50)
  197. }
  198. }
  199. popupRef.value.open('center');
  200. })
  201. }
  202. /**
  203. * @summary 关闭目录弹窗
  204. */
  205. function handleClose() {
  206. popupRef.value.close();
  207. }
  208. /**
  209. * @summary 选中
  210. * @param({zhangId:string}) data
  211. */
  212. function handleSelectZhang(data, index) {
  213. selectZhang.value = data;
  214. $emit('change-zhang', Object.assign({}, data));
  215. handleClose();
  216. }
  217. function handleConfirmPay() {
  218. /*const url =
  219. `/pages/pay/svip?subjectId=${subjectId.value}&formPage=studyWithCatalgue&selectZhangId=${selectZhang.value.zhangId}`
  220. uni.redirectTo({
  221. url
  222. })*/
  223. }
  224. defineExpose({
  225. showPopup
  226. })
  227. </script>