<template>
  <fvSearchForm :searchConfig="searchConfig" @search="search"></fvSearchForm>
  <fvTable ref="tableIns" :tableConfig="tableConfig" @headBtnClick="headBtnClick">
    <template #empty>
      <el-empty description="暂无数据"/>
    </template>
  </fvTable>
</template>


<script setup lang="jsx">
import fvSelect from '@/fvcomponents/fvSelect/index.vue'

const router = useRouter()
const searchConfig = reactive([
  {
    label: '专项资金名称',
    prop: 'name',
    component: 'el-input',
    props: {
      clearable: true,
      placeholder: '请输入专项资金名称查询'
    }
  },
  {
    label: '状态',
    prop: 'state',
    component: shallowRef(fvSelect),
    props: {
      placeholder: '请选择状态',
      clearable: true,
      cacheKey: 'special_fund'
    }
  },
  {
    label: '资金金额',
    prop: 'fundAmount',
    component: 'el-input',
    props: {
      clearable: true,
      placeholder: '请输入资金金额查询'
    }
  }, {
    label: '剩余金额',
    prop: 'residualAmount',
    component: 'el-input',
    props: {
      clearable: true,
      placeholder: '请输入剩余金额查询'
    }
  }, {
    label: '项目数量',
    prop: 'projectNumber',
    component: 'el-input',
    props: {
      clearable: true,
      placeholder: '请输入项目数量查询'
    }
  }
])
const tableConfig = reactive({
  columns: [
    {
      prop: 'name',
      label: '专项资金名称',
      align: 'center'
    },
    {
      prop: 'fundAmount',
      label: '资金金额',
      align: 'center'
    },
    {
      prop: 'residualAmount',
      label: '剩余金额',
      align: 'center'
    },
    {
      prop: 'projectNumber',
      label: '项目数量',
      align: 'center'
    },
    {
      prop: 'state',
      label: '状态',
      align: 'center',
      showOverflowTooltip: false,
      currentRender: ({row, index}) => {
        if (row.state == undefined) {
          return '--'
        } else {
          return (<Tag dictType={'special_fund'} value={row.state}/>)
        }
      }
    },
    {
      prop: 'oper',
      label: '操作',
      align: 'center',
      showOverflowTooltip: false,
      currentRender: ({row, index}) => {
        let btn = []
        // let buttons = new Set(Array.from(row.buttons))
        // if (buttons.has("details")) {
        btn.push({label: '详情', prem: ['mosr:collect:info'], func: () => handleDetail(row), type: 'primary'})
        // }
        // if (buttons.has("edit")) {
        btn.push({label: '编辑', prem: ['mosr:collect:resubmit'], func: () => handleEdit(row), type: 'primary'})
        // }
        // if (buttons.has("delete")) {
        //   btn.push({label: '删除',prem: ['mosr:requirement:del'], func: () => handleDelete(row), type: 'primary'})
        // }
        return (
            <div style={{width: '100%'}}>
              {
                btn.map(item => (
                    <el-button
                        type={item.type}
                        // v-perm={item.prem}
                        onClick={() => item.func()}
                        link
                    >
                      {item.label}
                    </el-button>
                ))
              }
            </div>
        )
      }
    }
  ],
  api: '/workflow/mosr/special/fund',
  params: {},
  btns: [
    {name: '新增', key: 'add', color: '#DED0B2', auth: ''},
    {name: '导出', key: '_export', color: '#DED0B2', auth: ''},
  ]
})
const tableIns = ref()
const search = (val) => {
  tableConfig.params = {...val}
  tableIns.value.refresh()
}
const handleDetail = (row) => {
  router.push({
    name: 'Fund/detail',
    query: {
      id: row.id
    }
  })
}
const handleAdd = () => {
  router.push({
    name: 'Fund/add',
    query: {}
  })
}
const handleEdit = (row) => {
  router.push({
    name: 'Fund/edit',
    query: {
      id: row.id
    }
  })
}
const headBtnClick = (key) => {
  switch (key) {
    case 'add':
      handleAdd()
      break;
    case 'export':
      handleExport()
      break;
  }
}
</script>

<style scoped>

</style>
