<template>
  <fvSearchForm :searchConfig="searchConfig" @search="search"></fvSearchForm>
  <fvTable ref="tableIns" :tableConfig="tableConfig" @headBtnClick="headBtnClick"></fvTable>
</template>

<script setup lang="jsx">
import fvSelect from '@/fvcomponents/fvSelect/index.vue'
import Tag from '@/components/Tag.vue'
import {getDemandInfo} from "@/api/project-demand";

const router = useRouter()
const searchConfig = reactive([
  {
    label: '征集类型',
    prop: 'collectType',
    component: 'el-input',
    props: {
      placeholder: '请输入名称查询',
      clearable: true
    }
  },
  {
    label: '需求名称',
    prop: 'requirementName',
    component: 'el-input',
    props: {
      placeholder: '请输入名称查询',
      clearable: true
    }
  }
])
const tableIns = ref()
const auths = {
  edit: ['admin:role:edit'],
  add: ['admin:role:add'],
  export: ['admin:role:export'],
}

const tableConfig = reactive({
  columns: [
    {
      type: 'selection',
      prop: 'selection'
    },
    {
      prop: 'requirementName',
      label: '需求名称',
      align: 'center'
    },
    {
      prop: 'collectType',
      label: '征集类型',
      align: 'center'
    },
    {
      prop: 'approveName',
      label: '审批人',
      align: 'center'
    },
    {
      prop: 'deadline',
      label: '截止时间',
      align: 'center'
    },
    {
      prop: 'taskNode',
      label: '当前节点',
      align: 'center'
    },
    {
      prop: 'state',
      label: '状态',
      align: 'center',
      width:200,
      showOverflowTooltip: false,
      currentRender: ({row, index}) => (<point-tag dictType={'process_state'} value={row.state}/>)
    },
    {
      prop: 'oper',
      label: '操作',
      align: 'center',
      showOverflowTooltip: false,
      currentRender: ({row, index}) => {
        return (
            <div>
              <el-button type="primary" link onClick={() => handleDetail(row)}>详情
              </el-button>
              <el-button type="primary" link onClick={() => handleEdit(row)}>编辑</el-button>
              <el-button type="primary" link onClick={() => handleReport(row)}>上报</el-button>
            </div>
        )
      }
    }
  ],
  api: '/workflow/mosr/requirement',
  btns: [
    {name: '新增', key: 'add', auth: auths.add, color: '#DED0B2'},
    {name: '导出', key: 'add', auth: auths.add, type: ''},
  ],
  params: {}
})

const search = (val) => {
  tableConfig.params = {...val}
  tableIns.value.refresh()
}
const handleAdd = () => {
  router.push({
    path: '/projectdemand/demandadd',
    query: {
      isAdd: 1
    }
  })
}
const handleEdit = (row) => {
  router.push({
    path: '/projectdemand/demandedit',
    query: {
      id: row.roleId
    }
  })
}
const handleDetail = (row) => {
  router.push({
    path: '/projectdemand/demanddetail',
    query: {
      id: row.roleId
    }
  })
}
const headBtnClick = (key) => {
  switch (key) {
    case 'add':
      handleAdd()
      break;
    case 'edit':
      handleEdit()
      break;
    case 'detail':
      handleDetail()
      break;
  }
}
</script>

<style lang="scss" scoped>

</style>
