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

<script>
import { getPublishWorkflows } from '@/api/workflow'
import { State } from '@/constant'
import { transformCalendarRelease } from '@/views/screen/review/utils'

export default {
  name: 'WorkflowList',
  data () {
    return {
      schema: {
        condition: { status: State.SUBMITTED },
        list: getPublishWorkflows,
        transform: this.transform,
        cols: [
          { type: 'refresh' },
          { prop: 'priority', label: '优先级', width: 80, align: 'center' },
          { prop: 'priorityInfo', label: '', width: 80, align: 'center' },
          { prop: 'targetInfo', label: '内容', width: 80, align: 'center' },
          { prop: 'targetName', label: '', 'min-width': 100 },
          { prop: 'createBy', label: '申请人' },
          { prop: 'updateTime', label: '提交时间', 'min-width': 100 },
          { type: 'invoke', render: [
            { label: '审核', on: this.onReview }
          ] }
        ]
      }
    }
  },
  activated () {
    this.$refs.table.pageTo()
  },
  methods: {
    transform (item) {
      const { id, status, updateTime, calendarRelease } = item
      return {
        workflowId: id,
        status,
        updateTime,
        ...transformCalendarRelease(calendarRelease)
      }
    },
    onReview (item) {
      this.$router.push({
        name: 'workflow-detail',
        params: { id: item.workflowId }
      })
    }
  }
}
</script>
