<template>
  <fvTable ref="tableIns" :tableConfig="tableConfig" style="margin-top: 15px"></fvTable>
</template>

<script setup lang="jsx">
const router = useRouter()
const tableIns = ref()
const tableConfig = reactive({
  columns: [
    {
      prop: 'index',
      type: 'index',
      label: '序号',
      align: 'center',
      width:60,
      index: index => {
        return (tableIns.value.getQuery().pageNum - 1) * tableIns.value.getQuery().pageSize + index + 1
      }
    },
    {
      prop: 'targetName',
      label: '名称',
      align: 'center'
    },
    {
      prop: 'initiatorName',
      label: '发起人',
      align: 'center'
    },
    {
      prop: 'targetState',
      label: '流程类型',
      align: 'center',
      showOverflowTooltip: false,
      currentRender: ({row, index}) => {
        if (row.targetState !== null || row.targetState !== undefined) {
          return (<Tag dictType={'todo_type'} value={row.targetState}/>)
        } else {
          return '--'
        }
      }
    },
    {
      prop: 'taskName',
      label: '当前节点',
      align: 'center'
    },
    {
      prop: 'submitTime',
      label: '提交时间',
      align: 'center'
    },
    {
      prop: 'oper',
      label: '操作',
      align: 'center',
      fixed: 'right',
      width: 150,
      showOverflowTooltip: false,
      currentRender: ({row, index}) => {
        let btn = []
          btn.push({label: '查看', func: () => handleView(row), type: 'primary'})
        return (
            <div style={{width: '100%'}}>
              {
                btn.map(item => (
                    <el-button
                        type={item.type}
                        onClick={() => item.func()}
                        link
                    >
                      {item.label}
                    </el-button>
                ))
              }
            </div>
        )
      }
    }
  ],
  api: '/workflow/mosr/process/task',
})

const handleView = (row) => {
  if (row.targetState == '00' && row.targetId) {
    router.push({
      name: 'Requirement/detail',
      query: {
        id: row.targetId,
        source: 'home'
      }
    })
  }
  // else if (row.targetState == '10' && row.targetId) {
  //   router.push({
  //     name: 'Summary/detail',
  //     query: {
  //       projectId: row.targetId,
  //       state: row.state,
  //       source: 'home'
  //     }
  //   })
  // }
  else if (row.targetState == '10'||row.targetState == '20' || row.targetState == '40' || row.targetState == '50') {
    router.push({
      name: 'Implementation/detail',
      query: {
        projectId: row.targetId,
        state: row.state,
        step: row.targetState,
        source: 'home'
      }
    })
  } else if (row.targetState == '70' && row.targetId) {
    router.push({
      name: 'Fund/detail',
      query: {
        id: row.targetId,
        state: row.state,
        source: 'home'
      }
    })
  } else if (row.targetState == '80' && row.targetId) {
    router.push({
      name: 'Share/detail',
      query: {
        id: row.targetId,
        state: row.state,
        source: 'home'
      }
    })
  } else if (row.targetState == '90' && row.targetId) {
    router.push({
      name: 'Phase/detail',
      query: {
        projectId: row.targetId,
        source: 'home'
      }
    })
  }
}
</script>

<style scoped>

</style>
