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({
url: '/oa/erp/timesheetPreAlloc/getStaffAllocDetails',
url: '/oa/erp/timesheetPreAlloc/getAllocDetails',
method: 'get',
params: query
});
@ -89,10 +89,10 @@ export const delTimesheetPreAlloc = (allocId: string | number | Array<string | n
* @param query
* @returns {*}
*/
export function getErpTimesheetPreAllocList (query) {
return request({
url: '/oa/erp/timesheetPreAlloc/getErpTimesheetPreAllocList',
method: 'get',
params: query
});
};
export function getErpTimesheetPreAllocList(query) {
return request({
url: '/oa/erp/timesheetPreAlloc/getErpTimesheetPreAllocList',
method: 'get',
params: query
});
}

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

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

Loading…
Cancel
Save