feat(oa/erp): 预投工时分配功能由员工级分配改为项目级且不回写月汇总

dev
yangk 3 weeks ago
parent f6252d66f2
commit c7e1f9483d

@ -30,9 +30,9 @@ export const getTimesheetPreAlloc = (allocId: string | number): AxiosPromise<Pre
/** /**
* *
*/ */
export const getStaffAllocDetails = (query: { monthCode: string; projectId: string | number }): AxiosPromise<PreAllocDetailVO> => { export const getAllocDetails = (query: { monthCode: string; projectId: string | number }): AxiosPromise<PreAllocDetailVO> => {
return request({ return request({
url: '/oa/erp/timesheetPreAlloc/getStaffAllocDetails', url: '/oa/erp/timesheetPreAlloc/getAllocDetails',
method: 'get', method: 'get',
params: query params: query
}); });
@ -89,10 +89,10 @@ export const delTimesheetPreAlloc = (allocId: string | number | Array<string | n
* @param query * @param query
* @returns {*} * @returns {*}
*/ */
export function getErpTimesheetPreAllocList (query) { export function getErpTimesheetPreAllocList(query) {
return request({ return request({
url: '/oa/erp/timesheetPreAlloc/getErpTimesheetPreAllocList', url: '/oa/erp/timesheetPreAlloc/getErpTimesheetPreAllocList',
method: 'get', method: 'get',
params: query params: query
}); });
}; }

@ -1,302 +1,52 @@
export interface TimesheetPreAllocVO { export interface TimesheetPreAllocVO {
/**
* ID
*/
allocId: string | number; allocId: string | number;
/**
*
*/
allocCode: string; allocCode: string;
/**
* (YYYYMM)
*/
monthCode: string; monthCode: string;
standardMonthId?: string | number;
/**
* ID(erp_timesheet_standard_month)
*/
standardMonthId: string | number;
/**
* ID
*/
projectId: string | number; projectId: string | number;
/**
* ()
*/
projectCode: string; projectCode: string;
/**
* ()
*/
projectName: string; projectName: string;
/**
* (,)
*/
sourceTotalHours: number; sourceTotalHours: number;
/**
* ()
*/
allocatedTotalHours: number; allocatedTotalHours: number;
/**
*
*/
staffCount: number; staffCount: number;
/**
* 0 1 2
*/
allocStatus: string; allocStatus: string;
/**
* 0 1
*/
appliedFlag: string;
/**
* ID
*/
summaryId: string | number;
/**
*
*/
applyTime: string;
/**
*
*/
remark: string;
}
export interface TimesheetPreAllocForm extends BaseEntity {
/**
* ID
*/
allocId?: string | number;
/**
*
*/
allocCode?: string;
/**
* (YYYYMM)
*/
monthCode?: string;
/**
* ID(erp_timesheet_standard_month)
*/
standardMonthId?: string | number;
/**
* ID
*/
projectId?: string | number;
/**
* ()
*/
projectCode?: string;
/**
* ()
*/
projectName?: string;
/**
* (,)
*/
sourceTotalHours?: number;
/**
* ()
*/
allocatedTotalHours?: number;
/**
*
*/
staffCount?: number;
/**
* 0 1 2
*/
allocStatus?: string;
/**
* 0 1
*/
appliedFlag?: string;
/**
* ID
*/
summaryId?: string | number;
/**
*
*/
applyTime?: string;
/**
*
*/
remark?: string; remark?: string;
/**
*
*/
staffAllocList?: PreAllocStaffAlloc[];
}
export interface TimesheetPreAllocQuery extends PageQuery {
/**
*
*/
allocCode?: string;
/**
* (YYYYMM)
*/
monthCode?: string;
/**
* ID(erp_timesheet_standard_month)
*/
standardMonthId?: string | number;
/**
* ID
*/
projectId?: string | number;
/**
* ()
*/
projectCode?: string;
/**
* ()
*/
projectName?: string;
/**
* (,)
*/
sourceTotalHours?: number;
/**
* ()
*/
allocatedTotalHours?: number;
/**
*
*/
staffCount?: number;
/**
* 0 1 2
*/
allocStatus?: string;
/**
* 0 1
*/
appliedFlag?: string;
/**
* ID
*/
summaryId?: string | number;
/**
*
*/
applyTime?: string;
/**
*
*/
params?: any;
} }
export interface PreAllocTarget { export interface PreAllocTarget {
/**
* ID
*/
targetProjectId?: string | number; targetProjectId?: string | number;
/**
*
*/
targetProjectCode?: string; targetProjectCode?: string;
/**
*
*/
targetProjectName?: string; targetProjectName?: string;
/**
* ()
*/
allocHours?: number; allocHours?: number;
} }
export interface PreAllocStaffAlloc { export interface TimesheetPreAllocForm extends BaseEntity {
/** allocId?: string | number;
* ID allocCode?: string;
*/ monthCode?: string;
staffUserId?: string | number; standardMonthId?: string | number;
projectId?: string | number;
/** projectCode?: string;
* projectName?: string;
*/ sourceTotalHours?: number;
staffName?: string; allocatedTotalHours?: number;
staffCount?: number;
/** allocStatus?: string;
* () remark?: string;
*/
sourceHours?: number;
/**
* ()
*/
allocatedHours?: number;
/**
* ()
*/
remainingHours?: number;
/**
*
*/
allocItems?: PreAllocTarget[]; allocItems?: PreAllocTarget[];
} }
export interface PreAllocDetailVO extends TimesheetPreAllocVO { export interface TimesheetPreAllocQuery extends PageQuery {
/** allocCode?: string;
* () monthCode?: string;
*/ projectId?: string | number;
remainingTotalHours: number; projectCode?: string;
projectName?: string;
/** allocStatus?: string;
* params?: any;
*/
staffAllocList: PreAllocStaffAlloc[];
} }
export interface PreAllocDetailVO extends TimesheetPreAllocVO {
remainingTotalHours: number;
allocItems: PreAllocTarget[];
}

@ -5,12 +5,7 @@
<el-card shadow="hover"> <el-card shadow="hover">
<el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="90px"> <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="90px">
<el-form-item label="分配单编号" prop="allocCode"> <el-form-item label="分配单编号" prop="allocCode">
<el-input <el-input v-model="queryParams.allocCode" placeholder="请输入分配单编号" clearable @keyup.enter="handleQuery" />
v-model="queryParams.allocCode"
placeholder="请输入分配单编号"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item> </el-form-item>
<el-form-item label="月份" prop="monthCode"> <el-form-item label="月份" prop="monthCode">
<el-date-picker <el-date-picker
@ -20,6 +15,7 @@
format="YYYY-MM" format="YYYY-MM"
clearable clearable
placeholder="请选择月份" placeholder="请选择月份"
@change="handleQueryMonthChange"
/> />
</el-form-item> </el-form-item>
<el-form-item label="预投项目" prop="projectId"> <el-form-item label="预投项目" prop="projectId">
@ -62,7 +58,7 @@
type="danger" type="danger"
plain plain
icon="Delete" icon="Delete"
:disabled="multiple || hasAppliedSelected" :disabled="multiple"
@click="handleDelete()" @click="handleDelete()"
v-hasPermi="['oa/erp:timesheetPreAlloc:remove']" v-hasPermi="['oa/erp:timesheetPreAlloc:remove']"
> >
@ -78,9 +74,9 @@
<el-table v-loading="loading" border :data="timesheetPreAllocList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" border :data="timesheetPreAllocList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="分配单编号" align="center" prop="allocCode" width="180" v-if="columns[8].visible" /> <el-table-column label="分配单编号" align="center" prop="allocCode" width="180" v-if="columns[0].visible" />
<el-table-column label="月份" align="center" prop="monthCode" width="100" v-if="columns[0].visible" /> <el-table-column label="月份" align="center" prop="monthCode" width="100" v-if="columns[1].visible" />
<el-table-column label="来源预投项目" align="center" min-width="260" v-if="columns[1].visible"> <el-table-column label="来源预投项目" align="center" min-width="260" v-if="columns[2].visible">
<template #default="scope"> <template #default="scope">
<div class="project-cell"> <div class="project-cell">
<span>{{ scope.row.projectCode }}</span> <span>{{ scope.row.projectCode }}</span>
@ -88,40 +84,26 @@
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="来源工时" align="center" prop="sourceTotalHours" width="110" v-if="columns[2].visible"> <el-table-column label="来源工时" align="center" prop="sourceTotalHours" width="110" v-if="columns[3].visible">
<template #default="scope">{{ formatHours(scope.row.sourceTotalHours) }}</template> <template #default="scope">{{ formatHours(scope.row.sourceTotalHours) }}</template>
</el-table-column> </el-table-column>
<el-table-column label="已分配工时" align="center" prop="allocatedTotalHours" width="120" v-if="columns[3].visible"> <el-table-column label="已分配工时" align="center" prop="allocatedTotalHours" width="120" v-if="columns[4].visible">
<template #default="scope">{{ formatHours(scope.row.allocatedTotalHours) }}</template> <template #default="scope">{{ formatHours(scope.row.allocatedTotalHours) }}</template>
</el-table-column> </el-table-column>
<el-table-column label="涉及人数" align="center" prop="staffCount" width="100" v-if="columns[4].visible" /> <el-table-column label="涉及人数" align="center" prop="staffCount" width="100" v-if="columns[5].visible" />
<el-table-column label="分配状态" align="center" prop="allocStatus" width="110" v-if="columns[5].visible"> <el-table-column label="分配状态" align="center" prop="allocStatus" width="110" v-if="columns[6].visible">
<template #default="scope"> <template #default="scope">
<dict-tag :options="alloc_status" :value="scope.row.allocStatus" /> <dict-tag :options="alloc_status" :value="scope.row.allocStatus" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="回写时间" align="center" prop="applyTime" width="170" v-if="columns[6].visible">
<template #default="scope">
<span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" min-width="160" show-overflow-tooltip v-if="columns[7].visible" /> <el-table-column label="备注" align="center" prop="remark" min-width="160" show-overflow-tooltip v-if="columns[7].visible" />
<el-table-column label="操作" align="center" fixed="right" width="110" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" fixed="right" width="110" class-name="small-padding fixed-width">
<template #default="scope"> <template #default="scope">
<el-tooltip content="修改" placement="top"> <el-tooltip content="修改" placement="top">
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['oa/erp:timesheetPreAlloc:edit']" /> <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['oa/erp:timesheetPreAlloc:edit']" />
</el-tooltip> </el-tooltip>
<el-tooltip content="已回写单据不允许删除" placement="top" :disabled="scope.row.appliedFlag !== '1'"> <el-tooltip content="删除" placement="top">
<span> <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['oa/erp:timesheetPreAlloc:remove']" />
<el-button
link
type="primary"
icon="Delete"
:disabled="scope.row.appliedFlag === '1'"
@click="handleDelete(scope.row)"
v-hasPermi="['oa/erp:timesheetPreAlloc:remove']"
/>
</span>
</el-tooltip> </el-tooltip>
</template> </template>
</el-table-column> </el-table-column>
@ -130,7 +112,7 @@
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" /> <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
</el-card> </el-card>
<el-dialog :title="dialog.title" v-model="dialog.visible" width="1180px" append-to-body> <el-dialog :title="dialog.title" v-model="dialog.visible" width="960px" append-to-body>
<el-form ref="timesheetPreAllocFormRef" :model="form" :rules="rules" label-width="100px"> <el-form ref="timesheetPreAllocFormRef" :model="form" :rules="rules" label-width="100px">
<el-row :gutter="16"> <el-row :gutter="16">
<el-col :span="8"> <el-col :span="8">
@ -156,7 +138,7 @@
:disabled="Boolean(form.allocId)" :disabled="Boolean(form.allocId)"
placeholder="请选择来源预投项目" placeholder="请选择来源预投项目"
class="full-width" class="full-width"
@change="loadStaffAllocDetails" @change="loadAllocDetails"
> >
<el-option <el-option
v-for="project in sourceProjectOptions" v-for="project in sourceProjectOptions"
@ -193,39 +175,36 @@
</div> </div>
</div> </div>
<el-table v-loading="detailLoading" border :data="form.staffAllocList || []" class="alloc-table" empty-text="请选择月份和预投项目"> <div v-loading="detailLoading" class="alloc-section">
<el-table-column label="员工" prop="staffName" width="140" /> <div class="target-toolbar">
<el-table-column label="原预投工时" align="right" width="120"> <span>分配去向</span>
<template #default="scope">{{ formatHours(scope.row.sourceHours) }}</template> <el-button type="primary" link icon="Plus" @click="addTarget"></el-button>
</el-table-column> </div>
<el-table-column label="已分配" align="right" width="110"> <el-table border :data="form.allocItems || []" class="alloc-table" empty-text="">
<template #default="scope">{{ formatHours(calcStaffAllocated(scope.row)) }}</template> <el-table-column label="目标物流/备件项目" min-width="420">
</el-table-column> <template #default="scope">
<el-table-column label="未分配" align="right" width="110"> <el-select v-model="scope.row.targetProjectId" filterable placeholder="请选择目标项目" class="full-width">
<template #default="scope"> <el-option
<span :class="{ 'hour-warn': calcStaffRemaining(scope.row) < 0 }">{{ formatHours(calcStaffRemaining(scope.row)) }}</span> v-for="project in targetProjectOptions"
</template> :key="project.projectId"
</el-table-column> :label="projectLabel(project)"
<el-table-column label="分配去向" min-width="560"> :value="project.projectId"
<template #default="scope"> />
<div class="target-list"> </el-select>
<div v-for="(allocItem, index) in scope.row.allocItems" :key="index" class="target-row"> </template>
<el-select v-model="allocItem.targetProjectId" filterable placeholder="目标物流/备件项目" class="target-project-select"> </el-table-column>
<el-option <el-table-column label="分配工时" align="center" width="180">
v-for="project in targetProjectOptions" <template #default="scope">
:key="project.projectId" <el-input-number v-model="scope.row.allocHours" :precision="2" :step="0.5" :min="0" controls-position="right" />
:label="projectLabel(project)" </template>
:value="project.projectId" </el-table-column>
/> <el-table-column label="操作" align="center" width="80">
</el-select> <template #default="scope">
<el-input-number v-model="allocItem.allocHours" :precision="2" :step="0.5" :min="0" controls-position="right" /> <el-button link type="danger" icon="Delete" @click="removeTarget(scope.$index)" />
<el-button link type="danger" icon="Delete" @click="removeTarget(scope.row, index)" /> </template>
</div> </el-table-column>
<el-button link type="primary" icon="Plus" @click="addTarget(scope.row)"></el-button> </el-table>
</div> </div>
</template>
</el-table-column>
</el-table>
<el-form-item label="备注" prop="remark" class="mt-4"> <el-form-item label="备注" prop="remark" class="mt-4">
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注" /> <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注" />
@ -233,8 +212,8 @@
</el-form> </el-form>
<template #footer> <template #footer>
<div class="dialog-footer"> <div class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm"> </el-button> <el-button :loading="buttonLoading" type="primary" @click="submitForm"></el-button>
<el-button @click="cancel"> </el-button> <el-button @click="cancel"></el-button>
</div> </div>
</template> </template>
</el-dialog> </el-dialog>
@ -248,14 +227,13 @@ import {
delTimesheetPreAlloc, delTimesheetPreAlloc,
addTimesheetPreAlloc, addTimesheetPreAlloc,
updateTimesheetPreAlloc, updateTimesheetPreAlloc,
getStaffAllocDetails, getAllocDetails,
listAvailableSourceProjects listAvailableSourceProjects
} from '@/api/oa/erp/timesheetPreAlloc'; } from '@/api/oa/erp/timesheetPreAlloc';
import { import {
TimesheetPreAllocVO, TimesheetPreAllocVO,
TimesheetPreAllocQuery, TimesheetPreAllocQuery,
TimesheetPreAllocForm, TimesheetPreAllocForm,
PreAllocStaffAlloc,
PreAllocTarget, PreAllocTarget,
PreAllocDetailVO PreAllocDetailVO
} from '@/api/oa/erp/timesheetPreAlloc/types'; } from '@/api/oa/erp/timesheetPreAlloc/types';
@ -294,15 +272,14 @@ const dialog = reactive<DialogOption>({
}); });
const columns = ref<FieldOption[]>([ const columns = ref<FieldOption[]>([
{ key: 0, label: `月份`, visible: true }, { key: 0, label: `分配单编号`, visible: true },
{ key: 1, label: `来源预投项目`, visible: true }, { key: 1, label: `月份`, visible: true },
{ key: 2, label: `来源工时`, visible: true }, { key: 2, label: `来源预投项目`, visible: true },
{ key: 3, label: `已分配工时`, visible: true }, { key: 3, label: `来源工时`, visible: true },
{ key: 4, label: `涉及人数`, visible: true }, { key: 4, label: `已分配工时`, visible: true },
{ key: 5, label: `分配状态`, visible: true }, { key: 5, label: `涉及人数`, visible: true },
{ key: 6, label: `回写时间`, visible: true }, { key: 6, label: `分配状态`, visible: true },
{ key: 7, label: `备注`, visible: true }, { key: 7, label: `备注`, visible: true }
{ key: 8, label: `分配单编号`, visible: true }
]); ]);
const getCurrentMonthCode = () => { const getCurrentMonthCode = () => {
@ -318,9 +295,8 @@ const initFormData = (): TimesheetPreAllocForm => ({
allocatedTotalHours: 0, allocatedTotalHours: 0,
staffCount: 0, staffCount: 0,
allocStatus: '0', allocStatus: '0',
appliedFlag: '0',
remark: undefined, remark: undefined,
staffAllocList: [] allocItems: []
}); });
const data = reactive<PageData<TimesheetPreAllocForm, TimesheetPreAllocQuery>>({ const data = reactive<PageData<TimesheetPreAllocForm, TimesheetPreAllocQuery>>({
@ -362,37 +338,50 @@ const toNumber = (value?: number | string | null) => {
const formatHours = (value?: number | string | null) => toNumber(value).toFixed(2); const formatHours = (value?: number | string | null) => toNumber(value).toFixed(2);
const calcStaffAllocated = (staff: PreAllocStaffAlloc) => (staff.allocItems || []).reduce((sum, item) => sum + toNumber(item.allocHours), 0); const normalizeTarget = (item: PreAllocTarget): PreAllocTarget => ({
targetProjectId: item.targetProjectId ? String(item.targetProjectId) : undefined,
targetProjectCode: item.targetProjectCode,
targetProjectName: item.targetProjectName,
allocHours: toNumber(item.allocHours)
});
const calcStaffRemaining = (staff: PreAllocStaffAlloc) => toNumber(staff.sourceHours) - calcStaffAllocated(staff); const sourceTotalHours = computed(() => toNumber(form.value.sourceTotalHours));
const allocatedTotalHours = computed(() => (form.value.allocItems || []).reduce((sum, item) => sum + toNumber(item.allocHours), 0));
const sourceTotalHours = computed(() => (form.value.staffAllocList || []).reduce((sum, staff) => sum + toNumber(staff.sourceHours), 0));
const allocatedTotalHours = computed(() => (form.value.staffAllocList || []).reduce((sum, staff) => sum + calcStaffAllocated(staff), 0));
const remainingTotalHours = computed(() => sourceTotalHours.value - allocatedTotalHours.value); const remainingTotalHours = computed(() => sourceTotalHours.value - allocatedTotalHours.value);
const staffCount = computed(() => (form.value.staffAllocList || []).filter((staff) => toNumber(staff.sourceHours) > 0).length); const staffCount = computed(() => toNumber(form.value.staffCount));
const currentAllocStatus = computed(() => { const currentAllocStatus = computed(() => {
if (allocatedTotalHours.value <= 0) { if (allocatedTotalHours.value <= 0) {
return '0'; return '0';
} }
return allocatedTotalHours.value < sourceTotalHours.value ? '1' : '2'; return allocatedTotalHours.value < sourceTotalHours.value ? '1' : '2';
}); });
const hasAppliedSelected = computed(() => selectedRows.value.some((row) => row.appliedFlag === '1'));
const loadProjectOptions = async () => { const loadTargetProjectOptions = async () => {
if (querySourceProjectOptions.value.length === 0) { if (targetProjectOptions.value.length > 0) {
const sourceRes: any = await getErpProjectInfoList({ projectCategory: '4' }); return;
querySourceProjectOptions.value = (sourceRes.data || []).map(normalizeProject);
} }
if (targetProjectOptions.value.length === 0) { const [logisticsRes, spareRes]: any[] = await Promise.all([
const [logisticsRes, spareRes]: any[] = await Promise.all([ getErpProjectInfoList({ projectCategory: '1' }),
getErpProjectInfoList({ projectCategory: '1' }), getErpProjectInfoList({ projectCategory: '2' })
getErpProjectInfoList({ projectCategory: '2' }) ]);
]); const merged = [...(logisticsRes.data || []), ...(spareRes.data || [])].map(normalizeProject);
const merged = [...(logisticsRes.data || []), ...(spareRes.data || [])].map(normalizeProject); const uniqueMap = new Map<string, ProjectOption>();
const uniqueMap = new Map<string, ProjectOption>(); merged.forEach((project) => uniqueMap.set(project.projectId, project));
merged.forEach((project) => uniqueMap.set(project.projectId, project)); targetProjectOptions.value = Array.from(uniqueMap.values());
targetProjectOptions.value = Array.from(uniqueMap.values()); };
const loadAllPreProjectOptions = async () => {
const res: any = await getErpProjectInfoList({ projectCategory: '4' });
querySourceProjectOptions.value = (res.data || []).map(normalizeProject);
};
const loadQuerySourceProjectOptions = async (monthCode?: string) => {
if (!monthCode) {
await loadAllPreProjectOptions();
return;
} }
const res: any = await listAvailableSourceProjects({ monthCode });
querySourceProjectOptions.value = (res.data || []).map(normalizeProject);
}; };
const loadSourceProjectOptions = async (monthCode?: string) => { const loadSourceProjectOptions = async (monthCode?: string) => {
@ -404,19 +393,18 @@ const loadSourceProjectOptions = async (monthCode?: string) => {
sourceProjectOptions.value = (res.data || []).map(normalizeProject); sourceProjectOptions.value = (res.data || []).map(normalizeProject);
}; };
const normalizeStaffAlloc = (staff: PreAllocStaffAlloc): PreAllocStaffAlloc => ({ const appendMissingTargetOptions = (items: PreAllocTarget[]) => {
staffUserId: staff.staffUserId, items.forEach((item) => {
staffName: staff.staffName, const targetProjectId = item.targetProjectId ? String(item.targetProjectId) : undefined;
sourceHours: toNumber(staff.sourceHours), if (targetProjectId && !targetProjectOptions.value.some((project) => project.projectId === targetProjectId)) {
allocatedHours: toNumber(staff.allocatedHours), targetProjectOptions.value.push({
remainingHours: toNumber(staff.remainingHours), projectId: targetProjectId,
allocItems: (staff.allocItems || []).map((item) => ({ projectCode: item.targetProjectCode,
targetProjectId: item.targetProjectId ? String(item.targetProjectId) : undefined, projectName: item.targetProjectName
targetProjectCode: item.targetProjectCode, });
targetProjectName: item.targetProjectName, }
allocHours: toNumber(item.allocHours) });
})) };
});
const applyDetailToForm = (detail: PreAllocDetailVO) => { const applyDetailToForm = (detail: PreAllocDetailVO) => {
const sourceProjectId = detail.projectId ? String(detail.projectId) : undefined; const sourceProjectId = detail.projectId ? String(detail.projectId) : undefined;
@ -428,6 +416,10 @@ const applyDetailToForm = (detail: PreAllocDetailVO) => {
projectCategory: '4' projectCategory: '4'
}); });
} }
const allocItems = (detail.allocItems || []).map(normalizeTarget);
appendMissingTargetOptions(allocItems);
form.value.allocId = detail.allocId; form.value.allocId = detail.allocId;
form.value.allocCode = detail.allocCode; form.value.allocCode = detail.allocCode;
form.value.monthCode = detail.monthCode; form.value.monthCode = detail.monthCode;
@ -439,33 +431,26 @@ const applyDetailToForm = (detail: PreAllocDetailVO) => {
form.value.allocatedTotalHours = toNumber(detail.allocatedTotalHours); form.value.allocatedTotalHours = toNumber(detail.allocatedTotalHours);
form.value.staffCount = detail.staffCount; form.value.staffCount = detail.staffCount;
form.value.allocStatus = detail.allocStatus; form.value.allocStatus = detail.allocStatus;
form.value.appliedFlag = detail.appliedFlag;
form.value.summaryId = detail.summaryId;
form.value.applyTime = detail.applyTime;
form.value.remark = detail.remark; form.value.remark = detail.remark;
form.value.staffAllocList = (detail.staffAllocList || []).map(normalizeStaffAlloc); form.value.allocItems = allocItems;
form.value.staffAllocList.forEach((staff) => {
(staff.allocItems || []).forEach((item) => {
const targetProjectId = item.targetProjectId ? String(item.targetProjectId) : undefined;
if (targetProjectId && !targetProjectOptions.value.some((project) => project.projectId === targetProjectId)) {
targetProjectOptions.value.push({
projectId: targetProjectId,
projectCode: item.targetProjectCode,
projectName: item.targetProjectName
});
}
});
});
}; };
const loadStaffAllocDetails = async () => { const resetSourceTotals = () => {
form.value.sourceTotalHours = 0;
form.value.allocatedTotalHours = 0;
form.value.staffCount = 0;
form.value.allocStatus = '0';
form.value.allocItems = [];
};
const loadAllocDetails = async () => {
if (!form.value.monthCode || !form.value.projectId) { if (!form.value.monthCode || !form.value.projectId) {
form.value.staffAllocList = []; resetSourceTotals();
return; return;
} }
detailLoading.value = true; detailLoading.value = true;
try { try {
const res: any = await getStaffAllocDetails({ const res: any = await getAllocDetails({
monthCode: form.value.monthCode, monthCode: form.value.monthCode,
projectId: form.value.projectId projectId: form.value.projectId
}); });
@ -479,20 +464,28 @@ const handleMonthChange = async () => {
form.value.projectId = undefined; form.value.projectId = undefined;
form.value.projectCode = undefined; form.value.projectCode = undefined;
form.value.projectName = undefined; form.value.projectName = undefined;
form.value.staffAllocList = []; resetSourceTotals();
await loadSourceProjectOptions(form.value.monthCode); await loadSourceProjectOptions(form.value.monthCode);
}; };
const handleQueryMonthChange = async () => {
queryParams.value.projectId = undefined;
await loadQuerySourceProjectOptions(queryParams.value.monthCode);
};
const getList = async () => { const getList = async () => {
loading.value = true; loading.value = true;
const params = { try {
...queryParams.value, const params = {
projectId: queryParams.value.projectId || undefined ...queryParams.value,
}; projectId: queryParams.value.projectId || undefined
const res: any = await listTimesheetPreAlloc(params); };
timesheetPreAllocList.value = res.rows; const res: any = await listTimesheetPreAlloc(params);
total.value = res.total; timesheetPreAllocList.value = res.rows;
loading.value = false; total.value = res.total;
} finally {
loading.value = false;
}
}; };
const cancel = () => { const cancel = () => {
@ -510,8 +503,9 @@ const handleQuery = () => {
getList(); getList();
}; };
const resetQuery = () => { const resetQuery = async () => {
queryFormRef.value?.resetFields(); queryFormRef.value?.resetFields();
await loadQuerySourceProjectOptions();
handleQuery(); handleQuery();
}; };
@ -524,7 +518,7 @@ const handleSelectionChange = (selection: TimesheetPreAllocVO[]) => {
const handleAdd = async () => { const handleAdd = async () => {
reset(); reset();
await loadProjectOptions(); await loadTargetProjectOptions();
await loadSourceProjectOptions(form.value.monthCode); await loadSourceProjectOptions(form.value.monthCode);
dialog.visible = true; dialog.visible = true;
dialog.title = '预投工时分配'; dialog.title = '预投工时分配';
@ -532,23 +526,24 @@ const handleAdd = async () => {
const handleUpdate = async (row?: TimesheetPreAllocVO) => { const handleUpdate = async (row?: TimesheetPreAllocVO) => {
reset(); reset();
await loadProjectOptions(); await loadTargetProjectOptions();
const allocId = row?.allocId || ids.value[0]; const allocId = row?.allocId || ids.value[0];
const res: any = await getTimesheetPreAlloc(allocId); const res: any = await getTimesheetPreAlloc(allocId);
await loadSourceProjectOptions(res.data?.monthCode);
applyDetailToForm(res.data); applyDetailToForm(res.data);
dialog.visible = true; dialog.visible = true;
dialog.title = '预投工时分配'; dialog.title = '预投工时分配';
}; };
const addTarget = (staff: PreAllocStaffAlloc) => { const addTarget = () => {
if (!staff.allocItems) { if (!form.value.allocItems) {
staff.allocItems = []; form.value.allocItems = [];
} }
staff.allocItems.push({ targetProjectId: undefined, allocHours: 0 }); form.value.allocItems.push({ targetProjectId: undefined, allocHours: 0 });
}; };
const removeTarget = (staff: PreAllocStaffAlloc, index: number) => { const removeTarget = (index: number) => {
staff.allocItems?.splice(index, 1); form.value.allocItems?.splice(index, 1);
}; };
const validateAllocation = () => { const validateAllocation = () => {
@ -556,28 +551,26 @@ const validateAllocation = () => {
proxy?.$modal.msgError('本月该预投项目没有可分配工时'); proxy?.$modal.msgError('本月该预投项目没有可分配工时');
return false; return false;
} }
for (const staff of form.value.staffAllocList || []) { const usedTargets = new Set<string>();
const usedTargets = new Set<string>(); for (const item of form.value.allocItems || []) {
for (const item of staff.allocItems || []) { if (!item.targetProjectId) {
if (!item.targetProjectId) { proxy?.$modal.msgError('存在未选择目标项目的分配行');
proxy?.$modal.msgError(`员工[${staff.staffName}]存在未选择目标项目的分配行`);
return false;
}
const targetProjectId = String(item.targetProjectId);
if (usedTargets.has(targetProjectId)) {
proxy?.$modal.msgError(`员工[${staff.staffName}]不能重复选择同一目标项目`);
return false;
}
usedTargets.add(targetProjectId);
if (toNumber(item.allocHours) <= 0) {
proxy?.$modal.msgError(`员工[${staff.staffName}]分配工时必须大于0`);
return false;
}
}
if (calcStaffRemaining(staff) < -0.000001) {
proxy?.$modal.msgError(`员工[${staff.staffName}]分配工时不能超过原预投工时`);
return false; return false;
} }
const targetProjectId = String(item.targetProjectId);
if (usedTargets.has(targetProjectId)) {
proxy?.$modal.msgError('同一张分配单不能重复选择同一目标项目');
return false;
}
usedTargets.add(targetProjectId);
if (toNumber(item.allocHours) <= 0) {
proxy?.$modal.msgError('分配工时必须大于0');
return false;
}
}
if (allocatedTotalHours.value - sourceTotalHours.value > 0.000001) {
proxy?.$modal.msgError('分配工时合计不能超过来源预投工时');
return false;
} }
return true; return true;
}; };
@ -591,14 +584,9 @@ const buildSubmitPayload = (): TimesheetPreAllocForm => ({
staffCount: staffCount.value, staffCount: staffCount.value,
allocStatus: currentAllocStatus.value, allocStatus: currentAllocStatus.value,
remark: form.value.remark, remark: form.value.remark,
staffAllocList: (form.value.staffAllocList || []).map((staff) => ({ allocItems: (form.value.allocItems || []).map((item) => ({
staffUserId: staff.staffUserId, targetProjectId: item.targetProjectId,
staffName: staff.staffName, allocHours: toNumber(item.allocHours)
sourceHours: toNumber(staff.sourceHours),
allocItems: (staff.allocItems || []).map((item: PreAllocTarget) => ({
targetProjectId: item.targetProjectId,
allocHours: toNumber(item.allocHours)
}))
})) }))
}); });
@ -625,11 +613,6 @@ const submitForm = () => {
}; };
const handleDelete = async (row?: TimesheetPreAllocVO) => { const handleDelete = async (row?: TimesheetPreAllocVO) => {
const deleteRows = row ? [row] : selectedRows.value;
if (deleteRows.some((item) => item.appliedFlag === '1')) {
proxy?.$modal.msgError('已回写月汇总的预投工时分配单不允许删除');
return;
}
const allocIds = row?.allocId || ids.value; const allocIds = row?.allocId || ids.value;
await proxy?.$modal.confirm(`是否确认删除预投工时分配编号为"${allocIds}"的数据项?`).finally(() => (loading.value = false)); await proxy?.$modal.confirm(`是否确认删除预投工时分配编号为"${allocIds}"的数据项?`).finally(() => (loading.value = false));
await delTimesheetPreAlloc(allocIds); await delTimesheetPreAlloc(allocIds);
@ -648,7 +631,7 @@ const handleExport = () => {
}; };
onMounted(async () => { onMounted(async () => {
await loadProjectOptions(); await Promise.all([loadTargetProjectOptions(), loadQuerySourceProjectOptions()]);
await getList(); await getList();
}); });
</script> </script>
@ -695,25 +678,19 @@ onMounted(async () => {
font-size: 16px; font-size: 16px;
} }
.alloc-table { .alloc-section {
width: 100%; min-height: 120px;
} }
.target-list { .target-toolbar {
display: flex; display: flex;
flex-direction: column;
gap: 8px;
padding: 4px 0;
}
.target-row {
display: grid;
grid-template-columns: minmax(260px, 1fr) 150px 32px;
gap: 8px;
align-items: center; align-items: center;
justify-content: space-between;
margin-bottom: 8px;
font-weight: 600;
} }
.target-project-select { .alloc-table {
width: 100%; width: 100%;
} }
@ -726,9 +703,5 @@ onMounted(async () => {
.summary-strip { .summary-strip {
grid-template-columns: repeat(2, minmax(120px, 1fr)); grid-template-columns: repeat(2, minmax(120px, 1fr));
} }
.target-row {
grid-template-columns: 1fr;
}
} }
</style> </style>

Loading…
Cancel
Save