| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <script>
- import { mapGetters } from 'vuex'
- import { getSchedule } from '@/api/calendar'
- import ScheduleCalendar from './ScheduleCalendar'
- import ScheduleSwiper from './ScheduleSwiper'
- export default {
- name: 'Schedule',
- components: {
- ScheduleCalendar,
- ScheduleSwiper
- },
- props: {
- schedule: {
- type: String,
- required: true
- },
- editable: {
- type: [Boolean, String],
- default: false
- }
- },
- data () {
- return {
- options: null
- }
- },
- computed: {
- ...mapGetters(['isSuperAdmin', 'tenant', 'userId'])
- },
- watch: {
- schedule: {
- handler () {
- this.getSchedule()
- },
- immediate: true
- }
- },
- methods: {
- getSchedule () {
- const options = {
- loading: true,
- error: false,
- detail: null
- }
- this.options = options
- getSchedule(this.schedule).then(
- schedule => {
- if (schedule) {
- const { rejectIds } = schedule
- if (this.editable && rejectIds?.length) {
- this.ask(schedule, options)
- } else {
- options.detail = schedule
- options.loading = false
- }
- } else {
- options.loading = false
- }
- },
- () => {
- options.error = true
- options.loading = false
- }
- )
- },
- ask (schedule, options) {
- this.$confirm(
- '节目若已完成修改可选择保留',
- '存在被驳回的节目',
- {
- type: 'info',
- showClose: false,
- confirmButtonText: '保留',
- cancelButtonText: '移除',
- closeOnClickModal: false,
- closeOnPressEscape: false
- }
- ).catch(action => {
- if (action === 'cancel') {
- const { type } = schedule
- ;[val => val, this.removeRejectedFromSwiper, this.removeRejectedFromCalendar][type - 1](schedule)
- }
- }).finally(() => {
- options.detail = schedule
- options.loading = false
- })
- },
- removeRejectedFromCalendar (schedule) {
- const { events, rejectIds } = schedule
- let length = events.length
- for (let i = 0; i < length; i++) {
- if (rejectIds.includes(events[i].target.id)) {
- events.splice(i, 1)
- i -= 1
- length -= 1
- }
- }
- },
- removeRejectedFromSwiper (schedule) {
- const { events, rejectIds } = schedule
- let length = events.length
- for (let i = 0; i < length; i++) {
- if (rejectIds.includes(events[i].programId)) {
- events.splice(i, 1)
- i -= 1
- length -= 1
- }
- }
- }
- },
- render (h) {
- if (this.options.loading) {
- return h('div', {
- directives: [
- {
- name: 'loading',
- value: true
- }
- ]
- })
- }
- if (this.options.error) {
- return h('Warning', {
- props: {
- error: true
- },
- on: {
- click: this.getSchedule
- }
- })
- }
- const { detail } = this.options
- if (!detail) {
- return h('el-result', {
- props: {
- icon: 'warning',
- subTitle: '数据不存在'
- }
- })
- }
- if (!this.isSuperAdmin && detail.tenant !== this.tenant) {
- return h('el-result', {
- props: {
- icon: 'warning',
- subTitle: '无权限'
- }
- })
- }
- return h([null, 'ScheduleSwiper', 'ScheduleCalendar'][detail.type - 1], {
- props: {
- detail,
- editable: this.editable && (this.isSuperAdmin || detail.createBy === this.userId),
- ...this.$attrs
- },
- on: this.$listeners
- })
- }
- }
- </script>
|