|
|
@@ -1,11 +1,11 @@
|
|
|
<script lang="ts" setup>
|
|
|
import {
|
|
|
IotProjectTaskPlanApi,
|
|
|
+ IotProjectTaskPlanUpdateData,
|
|
|
type IotProjectTaskPlanCreateData,
|
|
|
type IotProjectTaskPlanPageParams,
|
|
|
type IotProjectTaskPlanPageVO,
|
|
|
- type IotProjectTaskPlanTeamProjectBiz,
|
|
|
- type IotProjectTaskPlanUpdateData
|
|
|
+ type IotProjectTaskPlanTeamProjectBiz
|
|
|
} from '@/api/pms/iotprojecttaskplan'
|
|
|
import * as DeptApi from '@/api/system/dept'
|
|
|
import { useUserStore } from '@/store/modules/user'
|
|
|
@@ -53,7 +53,6 @@ interface DeptOption {
|
|
|
interface CreatePlanForm {
|
|
|
id?: number
|
|
|
deptId?: number
|
|
|
- companyId?: number
|
|
|
startTime?: number | string
|
|
|
business: string
|
|
|
workloadUnit: string
|
|
|
@@ -97,7 +96,6 @@ const formMode = ref<FormMode>('create')
|
|
|
const deptOptionsLoading = ref(false)
|
|
|
const businessOptionsLoading = ref(false)
|
|
|
const deptOptions = ref<DeptOption[]>([])
|
|
|
-const flatDeptOptions = ref<DeptOption[]>([])
|
|
|
const createFormRef = ref<FormInstance>()
|
|
|
|
|
|
const isReadonly = computed(() => formMode.value === 'view')
|
|
|
@@ -113,7 +111,6 @@ const dialogDescription = computed(() =>
|
|
|
const createInitialForm = (): CreatePlanForm => ({
|
|
|
id: undefined,
|
|
|
deptId: undefined,
|
|
|
- companyId: undefined,
|
|
|
startTime: dayjs().startOf('month').valueOf(),
|
|
|
business: '',
|
|
|
workloadUnit: '',
|
|
|
@@ -134,31 +131,17 @@ const loadDeptOptions = async () => {
|
|
|
deptOptionsLoading.value = true
|
|
|
try {
|
|
|
const data = (await DeptApi.specifiedSimpleDepts(deptId)) as DeptOption[]
|
|
|
- flatDeptOptions.value = data.map((dept) => ({
|
|
|
+ const selectableDeptOptions = data.map((dept) => ({
|
|
|
...dept,
|
|
|
type: String(dept.type || ''),
|
|
|
disabled: String(dept.type || '') !== '3'
|
|
|
}))
|
|
|
- deptOptions.value = handleTree(flatDeptOptions.value)
|
|
|
+ deptOptions.value = handleTree(selectableDeptOptions)
|
|
|
} finally {
|
|
|
deptOptionsLoading.value = false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const findCompanyId = (selectedDeptId: number) => {
|
|
|
- const deptMap = new Map(flatDeptOptions.value.map((dept) => [dept.id, dept]))
|
|
|
- const visitedIds = new Set<number>()
|
|
|
- let currentDept = deptMap.get(selectedDeptId)
|
|
|
-
|
|
|
- while (currentDept && !visitedIds.has(currentDept.id)) {
|
|
|
- visitedIds.add(currentDept.id)
|
|
|
- if (String(currentDept.type) === '1') return currentDept.id
|
|
|
- currentDept = currentDept.parentId ? deptMap.get(currentDept.parentId) : undefined
|
|
|
- }
|
|
|
-
|
|
|
- return undefined
|
|
|
-}
|
|
|
-
|
|
|
const loadTeamProjectBizOptions = async (selectedDeptId?: number) => {
|
|
|
teamProjectBizOptions.value = []
|
|
|
if (!selectedDeptId) return
|
|
|
@@ -173,7 +156,6 @@ const loadTeamProjectBizOptions = async (selectedDeptId?: number) => {
|
|
|
}
|
|
|
|
|
|
const handleDeptChange = async (selectedDeptId?: number) => {
|
|
|
- createFormData.value.companyId = selectedDeptId ? findCompanyId(selectedDeptId) : undefined
|
|
|
createFormData.value.business = ''
|
|
|
createFormData.value.workloadUnit = ''
|
|
|
createFormData.value.planWorkload = undefined
|
|
|
@@ -209,7 +191,6 @@ const handleOpenForm = async (mode: FormMode, id?: number) => {
|
|
|
createFormData.value = {
|
|
|
id: data.id,
|
|
|
deptId: data.deptId,
|
|
|
- companyId: data.companyId || findCompanyId(data.deptId),
|
|
|
startTime: normalizeStartTime(data.startTime),
|
|
|
business,
|
|
|
workloadUnit: data.workloadUnit || businessOption?.unit || config?.unit || '',
|
|
|
@@ -242,7 +223,6 @@ const submitCreate = async () => {
|
|
|
|
|
|
const {
|
|
|
deptId: formDeptId,
|
|
|
- companyId,
|
|
|
startTime,
|
|
|
business,
|
|
|
workloadUnit,
|
|
|
@@ -250,21 +230,13 @@ const submitCreate = async () => {
|
|
|
} = createFormData.value
|
|
|
const config = getBusinessPlanConfig(business)
|
|
|
|
|
|
- if (
|
|
|
- !formDeptId ||
|
|
|
- !companyId ||
|
|
|
- !startTime ||
|
|
|
- !workloadUnit ||
|
|
|
- planWorkload === undefined ||
|
|
|
- !config
|
|
|
- ) {
|
|
|
+ if (!formDeptId || !startTime || !workloadUnit || planWorkload === undefined || !config) {
|
|
|
message.error('表单数据不完整或项目业务未配置计划工作量字段')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
const data: IotProjectTaskPlanCreateData = {
|
|
|
deptId: formDeptId,
|
|
|
- companyId,
|
|
|
startTime: dayjs(Number(startTime)).startOf('month').valueOf(),
|
|
|
business,
|
|
|
workloadUnit
|