<template>
  <wrapper
    fill
    margin
    padding
    background
  >
    <schema-table
      ref="table"
      :schema="schema"
    />
  </wrapper>
</template>

<script>
import { WorkflowStateInfo } from '@/constant'
import { getAuditWorkflows } from '@/api/workflow'

export default {
  name: 'WorkflowList',
  data () {
    return {
      schema: {
        listeners: {
          'row-click': this.onAudit
        },
        props: {
          'row-class-name': 'u-pointer'
        },
        list: getAuditWorkflows,
        cols: [
          { type: 'refresh' },
          { label: '当前节点', render: ({ currentSeveralReviewed }) => WorkflowStateInfo[currentSeveralReviewed], width: 100, align: 'center' },
          { prop: 'flowDesc', label: '优先级', width: 100, align: 'center' },
          { prop: 'flowName', label: '上播内容' },
          { prop: 'createUser', label: '申请人', width: 160, align: 'center' },
          { prop: 'createTime', label: '提交时间', width: 160, align: 'center' },
          { type: 'invoke', render: [
            { label: '审核', on: this.onAudit }
          ] }
        ]
      }
    }
  },
  activated () {
    this.$refs.table.pageTo()
  },
  methods: {
    onAudit ({ id }) {
      this.$router.push({
        name: 'workflow-audit',
        params: { id }
      })
    }
  }
}
</script>
