courseTree.vue 4.6 KB

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