catalogue.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. <!-- 当前上下册只针对数学 -->
  7. <view v-if="subjectId == 1" class="catalogue-nianji-title">{{ jieTexts ? jieTexts[0]: ''}}</view>
  8. <!-- 当前只针对新版英语 -->
  9. <view v-if="subjectId == 2 && typeId == 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]: ''}}
  17. </view>
  18. <view v-if="subjectId == 2 && typeId == 1 && index == shuxueShangxia" class="catalogue-nianji-title catalogue-mt">
  19. {{jieTexts ? jieTexts[1]: ''}}
  20. </view>
  21. <uni-collapse-item title-border="none" :border="false" :name="index+''" class="collapse-item-box"
  22. :class="{ 'collapse-active': activeCollapse === index+''}">
  23. <template v-slot:title>
  24. <view class="collapse-title">
  25. <view class="collapse-num-box">{{index+1}}</view>
  26. <!-- 章名 -->
  27. <text class="collapse-name">{{item.zhangName}}</text>
  28. <!-- 锁 -->
  29. <!-- <template v-if="AuthCode !== 'VIP'">
  30. <view class="collapse-lock" v-if="index!=0"></view>
  31. </template> -->
  32. </view>
  33. </template>
  34. <view class="collapse-content-box">
  35. <view v-for="(jie,cindex) in item.jieList" class="collapse-content-item"
  36. @click="handleJieClick(item,jie,index,cindex)">
  37. <text class="jie-index">{{`${index+1}.${cindex+1}`}}</text>
  38. <text class="text">{{jie.jieName}}</text>
  39. </view>
  40. </view>
  41. </uni-collapse-item>
  42. </template>
  43. </uni-collapse>
  44. <tip-small-dialog ref="confirmDialogRef" @confirm-btn="handleConfirmPay"
  45. :content="Message"></tip-small-dialog>
  46. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  47. </scroll-view>
  48. </uni-popup>
  49. </template>
  50. <script setup>
  51. import {
  52. useCatalogue
  53. } from './useCatalogue';
  54. import {
  55. ref,
  56. } from "vue";
  57. import {
  58. getUserIdentity
  59. } from "@/utils/common.js"
  60. import {
  61. MESSAGE_VISITER_TO_LOGIN,
  62. MESSAGE_BEFORE_PAY
  63. } from "@/utils/constant.js"
  64. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  65. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  66. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  67. import cacheManager from "@/utils/cacheManager.js";
  68. import {
  69. onShow,
  70. onLoad
  71. } from '@dcloudio/uni-app';
  72. const growthType = ref(null);
  73. const AuthCode = ref(null);
  74. const scrollTop = ref(0)
  75. const subjectId = ref(null)
  76. const shuxueShangxia = ref(0);
  77. const levelId = ref(null);
  78. const typeId = ref(null);
  79. onShow(() => AuthCode.value = getUserIdentity()); // 用户身份
  80. onLoad((options) => {
  81. if (cacheManager.get('auth')) {
  82. subjectId.value = cacheManager.get('auth').subjectId;
  83. typeId.value = cacheManager.get('auth').typeId;
  84. } else {
  85. subjectId.value = options.subjectId;
  86. typeId.value = options.typeId;
  87. }
  88. if (subjectId.value == 1) {
  89. if (cacheManager.get('auth')) {
  90. levelId.value = cacheManager.get('auth').levelId;
  91. } else {
  92. levelId.value = options.levelId;
  93. }
  94. }
  95. })
  96. const $emit = defineEmits(['change-zhang'])
  97. const {
  98. getCatalogue
  99. } = useCatalogue();
  100. const popupRef = ref(null); // 索引
  101. const confirmDialogRef = ref(null);
  102. const activeCollapse = ref('');
  103. const Message = MESSAGE_BEFORE_PAY;
  104. const youkeDialogRef = ref(null);
  105. const selectZhang = ref(null);
  106. const list = ref([])
  107. const jieTexts = ref([])
  108. function handleJieClick(item, jie, index, cindex) {
  109. selectZhang.value = item;
  110. $emit('change-zhang', Object.assign({}, item));
  111. handleClose();
  112. }
  113. function catalogueBjFun() {
  114. if (subjectId.value == 1 && typeId.value == 1) {
  115. // 数学 新
  116. return 'static/images/catalog/catalog-shuxue-bj.png'
  117. } else if (subjectId.value == 1 && typeId.value == 2) {
  118. // 英语 旧
  119. return 'static/images/catalog/catalog-shuxue-bj.png'
  120. } else if (subjectId.value == 2 && typeId.value == 2) {
  121. // 英语 旧
  122. return 'static/images/catalog/catalog-yingyu-bj.png'
  123. } else if (subjectId.value == 2 && typeId.value == 1) {
  124. // 英语 新
  125. return 'static/images/catalog/catalog-newyYingyu-bj.png'
  126. }
  127. }
  128. function ykConfirm() {
  129. uni.redirectTo({
  130. url: '/pages/login/index'
  131. });
  132. }
  133. /**
  134. * @summary 展示弹窗 暴露函数
  135. */
  136. async function showPopup(data) {
  137. handleShow(data);
  138. }
  139. function getFormatZhangListByArray(data) {
  140. const myList = data.reduce((acc, curr) => acc.concat(curr.zhangList || []), [])
  141. const jiedian = data[0].zhangList.length;
  142. return {
  143. myList,
  144. jiedian,
  145. jieText: data.map(item => item.lable)
  146. }
  147. }
  148. /**
  149. * @summary 展示目录弹窗
  150. */
  151. function handleShow(data) {
  152. console.log('33333',data)
  153. getCatalogue().then(([err, wlist]) => {
  154. console.log('wlist',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>