import { getRatios } from '@/api/device'
import {
  getSchedules,
  deleteSchedule
} from '@/api/calendar'
import { State } from '@/constant'

export default {
  props: {
    type: {
      type: Number,
      default: 0
    },
    status: {
      type: Number,
      default: State.READY
    }
  },
  data () {
    return {
      active: `${this.status}`
    }
  },
  computed: {
    schema () {
      return {
        condition: {
          type: this.type,
          status: Number(this.active),
          ...this.getCondition()
        },
        list: getSchedules,
        filters: [
          { key: 'resolutionRatio', type: 'select', placeholder: '全部分辨率', simple: true, remote: getRatios },
          { key: 'name', type: 'search', placeholder: '名称' }
        ],
        cols: [
          { prop: 'name', label: '名称', 'min-width': 120 },
          { prop: 'resolutionRatio', label: '分辨率' },
          { prop: 'createTime', label: '创建时间', 'min-width': 90 },
          this.active === `${State.REJECTED}` ? { prop: 'remark', label: '驳回原因' } : null,
          { type: 'invoke', width: 160, render: this.invokes }
        ]
      }
    }
  },
  methods: {
    getCondition () {
      return this.$condition || { resolutionRatio: void 0, name: '' }
    },
    onView ({ id }) {
      this.$refs.scheduleDialog.show(id)
    },
    onDel (item) {
      deleteSchedule(item).then(() => {
        this.$refs.table.decrease(1)
      })
    }
  }
}
