<template>
  <baseTitle title="基础信息"></baseTitle>
  <fvForm :schema="schema" @getInstance="(e)=>baseForm = e"></fvForm>
  <fvSearchForm :searchConfig="searchConfig" @search="search"></fvSearchForm>
  <fvTable ref="tableIns" :tableConfig="tableConfig">
    <template #empty>
      <el-empty description="暂无数据"/>
    </template>
  </fvTable>
</template>

<script setup lang="jsx">
import fvSelect from '@/fvcomponents/fvSelect/index.vue'
import {computed, ref} from "vue";
import {getBaseInfoApi} from "@/components/steps/api";
import {getResearchUser} from "@/api/expense-manage";

const route = useRoute()
const schema = computed(() => {
  return [
    {
      label: '征集名称',
      prop: 'requirementName',
      colProps: {
        span: 12
      }
    },
    {
      label: '所属公司',
      prop: 'affiliatedCompany',
      colProps: {
        span: 12
      }
    },
    {
      label: '项目名称',
      prop: 'projectName',
      colProps: {
        span: 12
      }
    },
    {
      label: '征集类型',
      prop: 'collectType',
      colProps: {
        span: 12
      }
    },

  ]
})
const baseForm = ref()
const searchConfig = reactive([
  {
    label: '关键词',
    prop: 'requirementName',
    component: 'el-input',
    props: {
      placeholder: '请输入关键词查询',
      clearable: true,
      filterable: true,
      checkStrictly: true
    }
  },
  {
    label: '项目人员',
    prop: 'projectCost',
    component: shallowRef(fvSelect),
    props: {
      placeholder: '请选择项目人员查询',
      clearable: true,
      filterable: true,
      checkStrictly: true,
      cacheKey: ''
    }
  },
  {
    label: '时间',
    prop: 'datetime',
    component: 'el-date-picker',
    props: {
      placeholder: '请选择时间',
      clearable: true,
    }
  }
])
const tableIns = ref()
const tableConfig = reactive({
  columns: [
    {
      prop: 'name',
      type: 'index',
      label: '序号',
      align: 'center',
      width:'80'
    },
    {
      prop: 'time',
      label: '时间',
      align: 'center'
    },
    {
      prop: 'researchPersonnel',
      label: '研发人员',
      align: 'center',
      currentRender:({row})=>{
        return <span>{getResearchName(row.researchPersonnel)}</span>
      }
    },
    {
      prop: 'wagesPayable',
      label: '应发工资',
      align: 'center'
    },
    {
      prop: 'performance',
      label: '绩效',
      align: 'center'
    },
    {
      prop: 'reserveFund',
      label: '公积金',
      align: 'center'
    },
    {
      prop: 'socialSecurity',
      label: '社保',
      align: 'center'
    },
    {
      prop: 'annuity',
      label: '年金',
      align: 'center'
    },
    {
      prop: 'workday',
      label: '工作日(天)',
      align: 'center'
    },
    {
      prop: 'researchDuration',
      label: '研发工时(天)',
      align: 'center'
    },
    {
      prop: 'subtotal',
      label: '小计',
      align: 'center'
    }
  ],
  api: '/workflow/mosr/project/implementation/allocation/info',
  params: {
    projectId: route.query.id
  }
})
const researchOptions = ref([])
const getResearchOptions = async () => {
  const res = await getResearchUser()
  researchOptions.value = res.data
}
const getResearchName=(id)=>{
  if(!id)return;
  let label=''
  researchOptions.value.forEach(item=>{
    if(item.value==id){
      label=item.label
    }
  })
  return label
}
const getBaseInfo = async () => {
  try {
    const {code, data} = await getBaseInfoApi(route.query.id)
    baseForm.value.setValues(data)
  } catch {
  }
}

getResearchOptions()
getBaseInfo()
</script>

<style scoped>

</style>
