wuzhen update

This commit is contained in:
wuzhen committed 2025-08-01 09:03:43 +08:00
1 parent 5977a134ee
commit 1da0a6743f
1 file changed
+86 -24
+86 -24
View File
@@ -381,10 +381,10 @@
</template>
<el-form ref="performanceFormRef" :model="form" label-width="120px" label-position="top">
<PerformanceIndicators
<PerformanceIndicators
ref="performanceIndicatorsRef"
v-model="form.performanceIndicators"
@change="handlePerformanceIndicatorsChange"
v-model="form.performanceIndicators"
@change="handlePerformanceIndicatorsChange"
/>
</el-form>
</el-card>
@@ -450,7 +450,7 @@
</template>
<script setup lang="ts">
import { ref, reactive, computed, onMounted, nextTick } from 'vue'
import { ref, reactive, computed, onMounted, nextTick, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage, ElMessageBox, FormInstance } from 'element-plus'
import {
@@ -467,6 +467,11 @@ import {
} from '@/api/cw/projectApplication'
import PerformanceIndicators from './components/PerformanceIndicators.vue'
// 接收父组件传递的数据
const props = defineProps<{
formData?: any
}>()
const router = useRouter()
const route = useRoute()
@@ -531,6 +536,51 @@ const form = reactive({
approvalStatus: 'draft'
})
// 监听父组件传递的数据变化
watch(() => props.formData, (newData) => {
if (newData && typeof newData === 'object' && Object.keys(newData).length > 0) {
console.log('接收到父组件传递的数据:', newData)
// 安全地更新form数据
Object.keys(form).forEach(key => {
if (newData.hasOwnProperty(key) && newData[key] !== null && newData[key] !== undefined) {
// 特殊处理不同类型的字段
if (key === 'year' && newData[key]) {
form[key] = newData[key].toString()
} else if (key === 'startDate' || key === 'endDate') {
form[key] = newData[key] ? formatDateString(newData[key]) : ''
} else if (key.includes('Investment') || key.includes('Fiscal') || key.includes('Funding') ||
key.includes('Total') || key.includes('Municipal') || key.includes('Self') || key.includes('Other')) {
// 金额字段
form[key] = Number(newData[key]) || 0
} else {
form[key] = newData[key]
}
}
})
console.log('form数据更新完成:', form)
}
}, { deep: true, immediate: true })
// 日期格式化函数
const formatDateString = (dateValue: any): string => {
if (!dateValue) return ''
let date: Date
if (typeof dateValue === 'string') {
date = new Date(dateValue)
} else if (dateValue instanceof Date) {
date = dateValue
} else {
return ''
}
if (isNaN(date.getTime())) return ''
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
}
// 表单验证规则
const rules = {
projectName: [
@@ -648,30 +698,30 @@ const initBudgetChart = async () => {
// 验证绩效指标分值占比总和
const validatePerformanceIndicators = () => {
console.log('=== 校验绩效指标 ===')
// 直接使用绩效指标组件的校验方法
if (performanceIndicatorsRef?.value && typeof performanceIndicatorsRef.value.validate === 'function') {
const validationResult = performanceIndicatorsRef.value.validate()
console.log('绩效指标校验结果:', validationResult)
return validationResult
}
// 回退方案:检查form中的数据
if (!form.performanceIndicators || form.performanceIndicators.length === 0) {
return { valid: false, message: '请至少添加一个绩效指标' }
}
const totalWeight = form.performanceIndicators.reduce((sum, item) => {
return sum + (Number(item.weightPercentage) || 0)
}, 0)
if (Math.abs(totalWeight - 100) > 0.1) {
return {
valid: false,
message: `绩效指标分值占比总和必须等于100%,当前为${totalWeight}%`
return {
valid: false,
message: `绩效指标分值占比总和必须等于100%,当前为${totalWeight}%`
}
}
return { valid: true }
}
@@ -683,7 +733,7 @@ const handleNextStep = async () => {
if (currentFormRef?.value) {
try {
await currentFormRef.value.validate()
// 如果是绩效指标步骤(第3步),额外校验分值占比
if (currentStep.value === 3) {
const validationResult = validatePerformanceIndicators()
@@ -692,7 +742,7 @@ const handleNextStep = async () => {
return
}
}
currentStep.value++
// 初始化图表
@@ -711,7 +761,7 @@ const handleNextStep = async () => {
return
}
}
currentStep.value++
// 初始化图表
@@ -729,7 +779,7 @@ const handlePrevStep = () => {
const handlePerformanceIndicatorsChange = (indicators) => {
console.log('=== 绩效指标数据变化 ===')
console.log('接收到的indicators:', indicators)
// 为每个指标添加必要的字段
const processedIndicators = indicators.map((item, index) => ({
...item,
@@ -751,15 +801,15 @@ const handlePerformanceIndicatorsChange = (indicators) => {
dataSource: item.dataSource || '',
isQuantitative: item.isQuantitative !== undefined ? item.isQuantitative : true
}))
form.performanceIndicators = processedIndicators
console.log('处理后的绩效指标数据:', form.performanceIndicators)
// 自动生成总绩效目标和当年目标(如果有目标值)
const totalGoals = processedIndicators
.filter(item => item.targetValue && !isNaN(Number(item.targetValue)))
.reduce((sum, item) => sum + Number(item.targetValue), 0)
if (totalGoals > 0) {
form.totalPerformanceGoal = totalGoals
form.currentYearGoal = totalGoals
@@ -771,7 +821,7 @@ const handlePerformanceIndicatorsChange = (indicators) => {
const handleSaveDraft = async () => {
try {
savingDraft.value = true
// 如果当前在绩效指标步骤(第3步),校验分值占比总和
if (currentStep.value === 3 && form.performanceIndicators && form.performanceIndicators.length > 0) {
const validationResult = validatePerformanceIndicators()
@@ -780,7 +830,7 @@ const handleSaveDraft = async () => {
// 注意:这里只是警告,不阻止保存草稿
}
}
// 详细调试信息
console.log('=== 前端保存草稿调试信息 ===')
console.log('form.performanceIndicators 是否存在:', !!form.performanceIndicators)
@@ -799,10 +849,10 @@ const handleSaveDraft = async () => {
form.applicationNo = result.data.applicationNo
console.log('草稿保存成功,获得ID:', form.id, '申报编号:', form.applicationNo)
}
// 绩效指标数据已经作为form的一部分传递给后端,无需单独处理
console.log('绩效指标数据已随草稿数据一起保存,数量:', form.performanceIndicators ? form.performanceIndicators.length : 0)
ElMessage.success('草稿保存成功')
}
} catch (error) {
@@ -913,7 +963,7 @@ const loadData = async () => {
if (response.code === 200) {
console.log('申报基础数据加载成功:', response.data)
Object.assign(form, response.data)
// 检查是否有绩效指标数据
if (response.data.performanceIndicators && response.data.performanceIndicators.length > 0) {
console.log('发现绩效指标数据,数量:', response.data.performanceIndicators.length)
@@ -931,6 +981,18 @@ const loadData = async () => {
}
}
// 暴露给父组件的方法
const validate = (callback: (valid: boolean) => void) => {
// 简单的验证逻辑,检查必填字段
const isValid = !!(form.projectName && form.principal && form.totalInvestment > 0)
callback(isValid)
}
// 暴露方法给父组件
defineExpose({
validate
})
// 组件挂载
onMounted(() => {
loadData()