index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <script>
  2. import { getSchedule } from '@/api/calendar'
  3. import ScheduleCalendar from './ScheduleCalendar'
  4. import ScheduleSwiper from './ScheduleSwiper'
  5. export default {
  6. name: 'Schedule',
  7. components: {
  8. ScheduleCalendar,
  9. ScheduleSwiper
  10. },
  11. props: {
  12. schedule: {
  13. type: String,
  14. default: null
  15. }
  16. },
  17. data () {
  18. return {
  19. options: null
  20. }
  21. },
  22. watch: {
  23. schedule: {
  24. handler () {
  25. this.getSchedule()
  26. },
  27. immediate: true
  28. }
  29. },
  30. methods: {
  31. getSchedule () {
  32. const options = {
  33. loading: true,
  34. error: false,
  35. detail: null
  36. }
  37. this.options = options
  38. getSchedule(this.schedule).then(
  39. schedule => {
  40. options.detail = schedule
  41. },
  42. () => {
  43. options.error = true
  44. }
  45. ).finally(() => {
  46. options.loading = false
  47. })
  48. }
  49. },
  50. render (h) {
  51. if (this.options.loading) {
  52. return h('div', {
  53. directives: [
  54. {
  55. name: 'loading',
  56. value: true
  57. }
  58. ]
  59. })
  60. }
  61. if (this.options.error) {
  62. return h('Warning', {
  63. props: {
  64. error: true
  65. },
  66. on: {
  67. click: this.getSchedule
  68. }
  69. })
  70. }
  71. const { detail } = this.options
  72. return h([null, 'ScheduleSwiper', 'ScheduleCalendar'][detail.type - 1], {
  73. props: {
  74. detail,
  75. ...this.$attrs
  76. },
  77. on: this.$listeners
  78. })
  79. }
  80. }
  81. </script>