page-learn.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div>
  3. <van-tabs :active="active" @click="rootChange" line-width="10px">
  4. <!-- 根目录 -->
  5. <van-tab
  6. v-for="(item, index) in learnRootList"
  7. :key="index"
  8. :title="item.name"
  9. >
  10. <PageLearnChild v-if="index !== 0" :learnChildList="learnChildList">
  11. </PageLearnChild>
  12. <PageLearnRecommend v-if="index === 0" :swiperList="swiperList">
  13. </PageLearnRecommend>
  14. </van-tab>
  15. </van-tabs>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. name: "page-learn",
  21. components: {
  22. PageLearnChild: resolve => {
  23. require(["./page-learn-child"], resolve);
  24. },
  25. PageLearnRecommend: resolve => {
  26. require(["./page-learn-recommend"], resolve);
  27. }
  28. },
  29. data() {
  30. return {
  31. active: 0,
  32. learnRootList: [],
  33. choosedRootIndex: 0,
  34. learnChildList: [],
  35. swiperList: []
  36. };
  37. },
  38. computed: {},
  39. created() {
  40. this.getSwiperListDataFun();
  41. this.getLearnRootList();
  42. },
  43. mounted() {},
  44. methods: {
  45. // 查询轮播图数据列表
  46. getSwiperListDataFun() {
  47. this.swiperList = [
  48. { url: require("@/assets/image/swipe/01.jpg") },
  49. { url: require("@/assets/image/swipe/02.jpg") },
  50. { url: require("@/assets/image/swipe/03.jpg") },
  51. { url: require("@/assets/image/swipe/02.jpg") }
  52. ];
  53. },
  54. // 查询学习根目录
  55. getLearnRootList() {
  56. this.$_http
  57. .get(this.$_API.JTXT_GET_CATEGORIES)
  58. .then(res => {
  59. // 第一个添加推荐
  60. this.learnRootList = [{ id: "0", name: "推荐", parentId: null }];
  61. this.learnRootList = [...this.learnRootList, ...res.data];
  62. // 查询子目录
  63. this.getChildList();
  64. })
  65. .catch(() => {
  66. this.$store.commit("toggleLoading", false);
  67. });
  68. },
  69. // 查询子目录
  70. getChildList() {
  71. if (this.choosedRootIndex === 0) {
  72. return;
  73. }
  74. let path = {
  75. categoryId: this.learnRootList[this.choosedRootIndex].id
  76. };
  77. this.$_http
  78. .get(this.$pathParams(this.$_API.JTXT_GET_CATEGORIES_CATEGROYID, path))
  79. .then(res => {
  80. res.data.shift();
  81. this.learnChildList = res.data;
  82. })
  83. .catch(() => {
  84. this.$store.commit("toggleLoading", false);
  85. });
  86. },
  87. // 切换根目录
  88. rootChange(index, title) {
  89. this.choosedRootIndex = index;
  90. this.getChildList();
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss" scoped>
  96. @import "~@/styles/mixin";
  97. .contentBody {
  98. background-color: #fff;
  99. }
  100. </style>