Files
mosr-web/src/views/expense-management/share-detail/index.vue
dj a26088a756 feat(expense-management): 优化项目名称远程搜索功能
- 在项目需求概览页面添加主项目列表缓存到本地存储
-重构费用管理模块中项目名称远程搜索方法,提高代码复用性
- 优化主项目和子项目名称的加载和搜索逻辑
2025-08-04 10:02:50 +08:00

285 lines
7.0 KiB
Vue

<template>
<fvSearchForm :searchConfig="searchConfig" @search="search" style="margin-left: 16px"></fvSearchForm>
<!-- <el-button color="#DED0B2" style="float: left;margin: 0 10px 10px 0" @click="exportTable">导出</el-button>-->
<fvTable ref="tableIns" :tableConfig="tableConfig" @headBtnClick="headBtnClick" style="margin-top: 15px" @selectionChange="selectionChange">
<template #empty>
<el-empty description="暂无数据"/>
</template>
</fvTable>
</template>
<script setup lang="jsx">
import fvSelect from '@/fvcomponents/fvSelect/index.vue'
import { getSubCompOpt } from '@/api/user/user.js';
import {reactive, ref} from "vue";
import {shareDetailExport, shareExportExcel} from "@/api/expense-manage";
import {ElMessage} from "element-plus";
import {
getCostMasterProjectNameOption, getCostSubprojectNameOption,
getMasterProjectNameOption,
getSubprojectNameOption
} from "@/api/project-demand/summary/index.js";
const router = useRouter()
const route = useRoute()
const searchConfig = ref([
{
label: '主项目',
prop: 'masterProjectName',
component: shallowRef(fvSelect),
props: {
placeholder: '请输入主项目',
clearable: true,
filterable: true,
options: [],
remote: true,
remoteMethod:async (val)=>{
console.log('val',val)
if(val){
await getMasterProjectName( val)
}
}
},
},
{
label: '子项目',
prop: 'subProjectName',
component: shallowRef(fvSelect),
props: {
placeholder: '请输入子项目',
clearable: true,
filterable: true,
options: [],
remote: true,
remoteMethod:async (val)=>{
if(val){
await getSubprojectName(val)
}
}
},
},
// {
// label: '支付月份',
// prop: 'apportionmentMonth',
// component: 'el-date-picker',
// props: {
// placeholder: '请选择支付月份',
// clearable: true,
// type:'month',
// format: 'YYYY-MM',
// valueFormat:"YYYY-MM"
// },
// colProps: {}
// },
// {
// label: '人员性质',
// prop: 'personnelNature',
// component: shallowRef(fvSelect),
// props: {
// placeholder: '请选择人员性质',
// clearable: true,
// filterable: true,
// cacheKey: 'nature_of_personnel'
// }
// },
])
const tableIns = ref()
const selectData = ref([])
const tableConfig = reactive({
columns: [
{
type: 'selection',
prop: 'selection',
},
// {
// prop: 'name',
// type: 'index',
// label: '序号',
// align: 'center',
// width:85,
// index: index => {
// return (tableIns.value.getQuery().pageNum - 1) * tableIns.value.getQuery().pageSize + index + 1
// }
// },
{
prop: 'paymentYear',
label: '支付年份',
align: 'center'
},
{
prop: 'paymentMonth',
label: '支付月份',
align: 'center'
},
{
prop: 'masterProjectName',
label: '主项目',
align: 'center',
},
{
prop: 'subProjectName',
label: '子项目',
align: 'center',
},
{
prop: 'researchPersonnel',
label: '研发人员',
align: 'center',
showOverflowTooltip: false,
},
{
prop: 'personnelNature',
label: '人员性质',
align: 'center',
width: 120,
showOverflowTooltip: false,
currentRender: ({row, index}) => {
if (row.personnelNature&&row.personnelNature !== null&&row.personnelNature!==undefined) {
return (<Tag dictType={'nature_of_personnel'} value={row.personnelNature}/>)
} else {
return '--'
}
}
},
{
prop: 'researchDuration',
label: '当月研发工时(天)',
align: 'center',
// currentRender:({row})=>{
// return <span>{toThousands(row.afterTax)}</span>
// }
},
{
prop: 'workday',
label: '当月总工时(天)',
align: 'center',
showOverflowTooltip: false,
},
{
prop: 'subtotal',
label: '人工成本分摊(元)',
align: 'center',
},
],
api: '/workflow/mosr/cost/share',
params: {},
btns: [
{name: '添加分摊', key: 'add', color: '#DED0B2'},
{name: '导出', key: 'export', color: '#DED0B2'}
],
export:{
open :false,
}
})
const getMasterProjectName =async (val) => {
const res=await getCostMasterProjectNameOption(val)
if(res.code==1000){
let optionObj={}
let optionsMap = new Map();
res.data.forEach(item=>{
optionObj={
value:item.label,
label:item.label
}
optionsMap.set(optionObj.value, optionObj);
})
// 将 Map 转换为数组
searchConfig.value.find(item => item.prop == 'masterProjectName').props.options = Array.from(optionsMap.values())
}
}
const getSubprojectName =async (val) => {
const res=await getCostSubprojectNameOption(val)
if(res.code==1000){
let optionObj={}
let optionsMap = new Map();
res.data.forEach(item=>{
optionObj={
value:item.label,
label:item.label
}
optionsMap.set(optionObj.value, optionObj);
})
// 将 Map 转换为数组
searchConfig.value.find(item => item.prop == 'subProjectName').props.options = Array.from(optionsMap.values())
}
}
getMasterProjectName()
getSubprojectName()
const search = (val) => {
tableConfig.params = {...val}
tableIns.value.refresh()
}
const headBtnClick = (key) => {
switch (key) {
case 'add':
handleAdd()
break;
case 'export':
exportTable()
break;
}
}
const selectionChange = (data) => {
console.log('data', data)
selectData.value=data.map(item=>item.id)
}
const exportTable = () => {
console.log('selectData',selectData.value)
if (selectData.value.length === 0) {
ElMessage.warning('请选择要导出的费用分摊')
return
}
shareDetailExport(selectData.value).then(res => {
console.log(res)
let fileName = `科技研发项目工时及成本分摊汇总表.xlsx`
const blob = new Blob([res.data])
let a = document.createElement('a')
a.href = URL.createObjectURL(blob)
a.download = fileName
a.click()
})
}
const handleAdd = () => {
router.push({
name: 'Sharedetail/add',
query: {}
})
}
const init = async () => {
const res = await getSubCompOpt()
searchConfig.value.find(item=>item.prop == 'affiliatedCompanyIds').props.data = res.data
}
// init()
</script>
<style scoped lang="scss">
:deep(.el-table__header) {
.is-leaf:first-child {
.cell {
//margin-left: -25px !important;
}
}
}
:deep(.el-table__body) {
.el-table__cell:first-child {
.cell {
//margin-left: -13px !important;
}
}
}
:deep(.el-date-editor--month){
width: 100%;
}
</style>