courseTree.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view class="menuBox">
  3. <template>
  4. <view v-for="(item, index) in menuList" :key="index">
  5. <!--模块 -->
  6. <view v-if="item.type == 1">
  7. <courseModule :sectionMaxNum="sectionMaxNum" :needOpen="sectionItem.moduleId == item.menuId"
  8. :preItem="menuList[index - 1]" :isBuy="isBuy" :menuItem="item" :levelId="item.menuId"
  9. :goodsType="goodsType" :isRebuild="isRebuild"></courseModule>
  10. </view>
  11. <!--章 -->
  12. <view v-if="item.type == 2">
  13. <courseChapter :sectionMaxNum="sectionMaxNum" :needOpen="
  14. !sectionItem.moduleId && sectionItem.chapterId == item.menuId
  15. " :preItem="menuList[index - 1]" :isBuy="isBuy" :menuItem="item" :levelId="'0-' + item.menuId"
  16. :goodsType="goodsType" :isRebuild="isRebuild"></courseChapter>
  17. </view>
  18. <!--节 -->
  19. <view v-if="item.type == 3">
  20. <courseSection ref="MoudleSection" :sectionMaxNum="sectionMaxNum" :preItem="menuList[index - 1]"
  21. :isBuy="isBuy" :menuItem="item" :levelId="'0-0-' + item.menuId" :goodsType="goodsType"
  22. :testType="3" :isRebuild="isRebuild" @playEnd="getMenuList"></courseSection>
  23. </view>
  24. </view>
  25. </template>
  26. </view>
  27. </template>
  28. <script>
  29. import courseModule from "@/components/course/courseModule.vue";
  30. import courseChapter from "@/components/course/courseChapter.vue";
  31. import courseSection from "@/components/course/courseSection.vue";
  32. export default {
  33. name: "SaasMiniprogramCourseTree",
  34. inject: ["paramsFn"],
  35. props: {
  36. isBuy: {
  37. //是否是已购买商品
  38. type: Boolean,
  39. default: true,
  40. },
  41. isRebuild: {
  42. //是否重修目录
  43. type: Boolean,
  44. default: false,
  45. },
  46. sectionMaxNum: {
  47. default: undefined,
  48. },
  49. // 商品类型 1视频2题库 3补考 4前培 5虚拟赠送题库 6直播
  50. goodsType: {
  51. type: [Number, String],
  52. default: 1,
  53. },
  54. // 兼容props传参
  55. propParam: {
  56. type: Object,
  57. default: () => {
  58. return {};
  59. },
  60. },
  61. },
  62. data() {
  63. return {
  64. menuList: [],
  65. };
  66. },
  67. mounted() {},
  68. methods: {
  69. getMenuList() {
  70. const fn = this.isBuy ? "reMenuList" : "menuList";
  71. this.$api[fn](
  72. this.isBuy ?
  73. {
  74. ...this.params,
  75. rebuild: +this.isRebuild,
  76. } :
  77. {
  78. courseId: this.courseId
  79. }
  80. ).then((res) => {
  81. if (res.data.code == 200) {
  82. for (let i = 0; i < res.data.rows.length; i++) {
  83. let item = res.data.rows[i];
  84. // 显示重修目录
  85. if (item.rebuild) {
  86. this.$emit("isHaverebuild");
  87. }
  88. item.down = true;
  89. item.id = item.menuId;
  90. item.name = item.menuName;
  91. item.menuType = item.type;
  92. }
  93. this.menuList = res.data.rows;
  94. console.log(this.menuList, 'menuList')
  95. }
  96. });
  97. },
  98. },
  99. provide() {
  100. return {
  101. paramsFn: this.propParamFn
  102. };
  103. },
  104. computed: {
  105. isProps() {
  106. return !this.$method.isEmptyObject(this.propParam);
  107. },
  108. propParamFn() {
  109. return (key) => {
  110. return {
  111. ...this.paramsFn(key),
  112. ...this.propParam
  113. };
  114. };
  115. },
  116. params() {
  117. return this.propParamFn(["orderGoodsId", "gradeId", "courseId"]);
  118. },
  119. sectionItem() {
  120. if (this.isBuy) {
  121. return this.propParamFn(["sectionItem"])['sectionItem'];
  122. } else {
  123. return this.propParamFn(["sectionItem"]);
  124. }
  125. },
  126. courseId() {
  127. return this.params.courseId;
  128. },
  129. },
  130. watch: {
  131. courseId: {
  132. handler(val) {
  133. this.menuList = [];
  134. this.getMenuList();
  135. },
  136. immediate: true,
  137. deep: true,
  138. },
  139. },
  140. components: {
  141. courseModule,
  142. courseChapter,
  143. courseSection,
  144. },
  145. };
  146. </script>
  147. <style lang="scss" scoped>
  148. .top {
  149. &__header {
  150. position: relative;
  151. width: 100%;
  152. height: 150rpx;
  153. padding: 24rpx 150rpx 24rpx 24rpx;
  154. .img {
  155. position: absolute;
  156. left: 0;
  157. top: 0;
  158. width: 100%;
  159. }
  160. .note {
  161. position: relative;
  162. z-index: 10;
  163. font-size: 24rpx;
  164. font-family: PingFang SC;
  165. font-weight: bold;
  166. color: #efdbff;
  167. }
  168. .title {
  169. position: relative;
  170. z-index: 10;
  171. font-size: 26rpx;
  172. font-family: PingFang SC;
  173. font-weight: bold;
  174. color: #ffffff;
  175. }
  176. }
  177. }
  178. .menuBox {
  179. width: 100%;
  180. background: #ffffff;
  181. border-radius: 16rpx;
  182. padding: 0rpx 20rpx;
  183. margin-bottom: 20rpx;
  184. }
  185. </style>