<template>
  <schema-table
    ref="table"
    :schema="schema"
  />
</template>

<script>
import {
  getPrograms,
  resolveProgram
} from '@/api/program'
import { State } from '@/constant'
import mixin from './mixin'

export default {
  name: 'ReviewProgram',
  mixins: [mixin],
  data () {
    return {
      schema: {
        condition: { status: State.REVIEW },
        list: getPrograms,
        transform: this.transform,
        cols: [
          { prop: 'name', label: '节目名称', 'min-width': 100 },
          { prop: 'resolutionRatio', label: '分辨率' },
          { prop: 'createBy', label: '申请人' },
          { prop: 'createTime', label: '提交时间' },
          { type: 'invoke', width: 160, render: [
            { label: '查看', on: this.onView },
            { label: '通过', on: this.onResolve },
            { label: '驳回', on: this.onReject }
          ] }
        ]
      }
    }
  },
  methods: {
    resolve: resolveProgram,
    transform (program) {
      program.createBy = program.userName || program.createBy
      return program
    },
    onView ({ id }) {
      window.open(this.$router.resolve({
        name: 'program',
        params: { id }
      }).href, '_blank')
    }
  }
}
</script>
