index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <script>
  2. import { mapGetters } from 'vuex'
  3. import { getSchedule } from '@/api/calendar'
  4. import ScheduleCalendar from './ScheduleCalendar'
  5. import ScheduleSwiper from './ScheduleSwiper'
  6. export default {
  7. name: 'Schedule',
  8. components: {
  9. ScheduleCalendar,
  10. ScheduleSwiper
  11. },
  12. props: {
  13. schedule: {
  14. type: String,
  15. required: true
  16. },
  17. editable: {
  18. type: [Boolean, String],
  19. default: false
  20. }
  21. },
  22. data () {
  23. return {
  24. options: null
  25. }
  26. },
  27. computed: {
  28. ...mapGetters(['isSuperAdmin', 'tenant', 'userId'])
  29. },
  30. watch: {
  31. schedule: {
  32. handler () {
  33. this.getSchedule()
  34. },
  35. immediate: true
  36. }
  37. },
  38. methods: {
  39. getSchedule () {
  40. const options = {
  41. loading: true,
  42. error: false,
  43. detail: null
  44. }
  45. this.options = options
  46. getSchedule(this.schedule).then(
  47. schedule => {
  48. if (schedule) {
  49. const { rejectIds } = schedule
  50. if (this.editable && rejectIds?.length) {
  51. this.ask(schedule, options)
  52. } else {
  53. options.detail = schedule
  54. options.loading = false
  55. }
  56. } else {
  57. options.loading = false
  58. }
  59. },
  60. () => {
  61. options.error = true
  62. options.loading = false
  63. }
  64. )
  65. },
  66. ask (schedule, options) {
  67. this.$confirm(
  68. '节目若已完成修改可选择保留',
  69. '存在被驳回的节目',
  70. {
  71. type: 'info',
  72. showClose: false,
  73. confirmButtonText: '保留',
  74. cancelButtonText: '移除',
  75. closeOnClickModal: false,
  76. closeOnPressEscape: false
  77. }
  78. ).catch(action => {
  79. if (action === 'cancel') {
  80. const { type } = schedule
  81. ;[val => val, this.removeRejectedFromSwiper, this.removeRejectedFromCalendar][type - 1](schedule)
  82. }
  83. }).finally(() => {
  84. options.detail = schedule
  85. options.loading = false
  86. })
  87. },
  88. removeRejectedFromCalendar (schedule) {
  89. const { events, rejectIds } = schedule
  90. let length = events.length
  91. for (let i = 0; i < length; i++) {
  92. if (rejectIds.includes(events[i].target.id)) {
  93. events.splice(i, 1)
  94. i -= 1
  95. length -= 1
  96. }
  97. }
  98. },
  99. removeRejectedFromSwiper (schedule) {
  100. const { events, rejectIds } = schedule
  101. let length = events.length
  102. for (let i = 0; i < length; i++) {
  103. if (rejectIds.includes(events[i].programId)) {
  104. events.splice(i, 1)
  105. i -= 1
  106. length -= 1
  107. }
  108. }
  109. }
  110. },
  111. render (h) {
  112. if (this.options.loading) {
  113. return h('div', {
  114. directives: [
  115. {
  116. name: 'loading',
  117. value: true
  118. }
  119. ]
  120. })
  121. }
  122. if (this.options.error) {
  123. return h('Warning', {
  124. props: {
  125. error: true
  126. },
  127. on: {
  128. click: this.getSchedule
  129. }
  130. })
  131. }
  132. const { detail } = this.options
  133. if (!detail) {
  134. return h('el-result', {
  135. props: {
  136. icon: 'warning',
  137. subTitle: '数据不存在'
  138. }
  139. })
  140. }
  141. if (!this.isSuperAdmin && detail.tenant !== this.tenant) {
  142. return h('el-result', {
  143. props: {
  144. icon: 'warning',
  145. subTitle: '无权限'
  146. }
  147. })
  148. }
  149. return h([null, 'ScheduleSwiper', 'ScheduleCalendar'][detail.type - 1], {
  150. props: {
  151. detail,
  152. editable: this.editable && (this.isSuperAdmin || detail.createBy === this.userId),
  153. ...this.$attrs
  154. },
  155. on: this.$listeners
  156. })
  157. }
  158. }
  159. </script>