handoutsBox.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view>
  3. <template
  4. v-if="courseHandoutsData.fileList && courseHandoutsData.fileList.length"
  5. >
  6. <u-search
  7. placeholder="搜索讲义名称"
  8. bg-color="#ffffff"
  9. margin="0 0 20rpx"
  10. v-model="keyword"
  11. @custom="search"
  12. @search="search"
  13. ></u-search>
  14. <view class="handouts-box" v-for="item in searchList" :key="item.fileId">
  15. <handouts-tree :canDownload="courseHandoutsData.canDownload" :fileInfo="item"></handouts-tree>
  16. </view>
  17. </template>
  18. <view v-else style="text-align: center">暂无讲义</view>
  19. </view>
  20. </template>
  21. <script>
  22. import handoutsTree from "@/components/course/handoutsTree.vue";
  23. export default {
  24. name: "HandoutsBox",
  25. props: {
  26. handoutsId: {
  27. type: Number,
  28. },
  29. },
  30. data() {
  31. return {
  32. keyword: "",
  33. searchList: [],
  34. courseHandoutsData: [],
  35. };
  36. },
  37. mounted() {
  38. this.courseHandouts();
  39. },
  40. methods: {
  41. search(val) {
  42. if (!val) {
  43. this.searchList = this.backClone();
  44. return;
  45. }
  46. this.searchList = this.filterList(this.backClone(), []);
  47. },
  48. filterList(list, res) {
  49. list.forEach((ele) => {
  50. if (ele.type == 1 && ele.urlName.includes(this.keyword)) {
  51. res.push(ele);
  52. }
  53. if (ele.children && ele.children.length) {
  54. this.filterList(ele.children, res);
  55. }
  56. });
  57. return res;
  58. },
  59. backClone() {
  60. return JSON.parse(JSON.stringify(this.courseHandoutsData.fileList));
  61. },
  62. courseHandouts() {
  63. this.$api.courseHandouts(this.handoutsId).then((res) => {
  64. this.courseHandoutsData = res.data.data;
  65. this.searchList = this.backClone();
  66. console.log(this.courseHandoutsData,666)
  67. });
  68. },
  69. },
  70. components: {
  71. handoutsTree,
  72. },
  73. };
  74. </script>
  75. <style lang="scss" scoped>
  76. .handouts-box {
  77. border-radius: 20rpx;
  78. background: #ffffff;
  79. margin-bottom: 20rpx;
  80. }
  81. </style>