wuzhen update
This commit is contained in:
1 parent
5977a134ee
commit
1da0a6743f
1 file changed
+86
-24
@@ -381,10 +381,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<el-form ref="performanceFormRef" :model="form" label-width="120px" label-position="top">
|
<el-form ref="performanceFormRef" :model="form" label-width="120px" label-position="top">
|
||||||
<PerformanceIndicators
|
<PerformanceIndicators
|
||||||
ref="performanceIndicatorsRef"
|
ref="performanceIndicatorsRef"
|
||||||
v-model="form.performanceIndicators"
|
v-model="form.performanceIndicators"
|
||||||
@change="handlePerformanceIndicatorsChange"
|
@change="handlePerformanceIndicatorsChange"
|
||||||
/>
|
/>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-card>
|
</el-card>
|
||||||
@@ -450,7 +450,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<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 { useRouter, useRoute } from 'vue-router'
|
||||||
import { ElMessage, ElMessageBox, FormInstance } from 'element-plus'
|
import { ElMessage, ElMessageBox, FormInstance } from 'element-plus'
|
||||||
import {
|
import {
|
||||||
@@ -467,6 +467,11 @@ import {
|
|||||||
} from '@/api/cw/projectApplication'
|
} from '@/api/cw/projectApplication'
|
||||||
import PerformanceIndicators from './components/PerformanceIndicators.vue'
|
import PerformanceIndicators from './components/PerformanceIndicators.vue'
|
||||||
|
|
||||||
|
// 接收父组件传递的数据
|
||||||
|
const props = defineProps<{
|
||||||
|
formData?: any
|
||||||
|
}>()
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
@@ -531,6 +536,51 @@ const form = reactive({
|
|||||||
approvalStatus: 'draft'
|
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 = {
|
const rules = {
|
||||||
projectName: [
|
projectName: [
|
||||||
@@ -648,30 +698,30 @@ const initBudgetChart = async () => {
|
|||||||
// 验证绩效指标分值占比总和
|
// 验证绩效指标分值占比总和
|
||||||
const validatePerformanceIndicators = () => {
|
const validatePerformanceIndicators = () => {
|
||||||
console.log('=== 校验绩效指标 ===')
|
console.log('=== 校验绩效指标 ===')
|
||||||
|
|
||||||
// 直接使用绩效指标组件的校验方法
|
// 直接使用绩效指标组件的校验方法
|
||||||
if (performanceIndicatorsRef?.value && typeof performanceIndicatorsRef.value.validate === 'function') {
|
if (performanceIndicatorsRef?.value && typeof performanceIndicatorsRef.value.validate === 'function') {
|
||||||
const validationResult = performanceIndicatorsRef.value.validate()
|
const validationResult = performanceIndicatorsRef.value.validate()
|
||||||
console.log('绩效指标校验结果:', validationResult)
|
console.log('绩效指标校验结果:', validationResult)
|
||||||
return validationResult
|
return validationResult
|
||||||
}
|
}
|
||||||
|
|
||||||
// 回退方案:检查form中的数据
|
// 回退方案:检查form中的数据
|
||||||
if (!form.performanceIndicators || form.performanceIndicators.length === 0) {
|
if (!form.performanceIndicators || form.performanceIndicators.length === 0) {
|
||||||
return { valid: false, message: '请至少添加一个绩效指标' }
|
return { valid: false, message: '请至少添加一个绩效指标' }
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalWeight = form.performanceIndicators.reduce((sum, item) => {
|
const totalWeight = form.performanceIndicators.reduce((sum, item) => {
|
||||||
return sum + (Number(item.weightPercentage) || 0)
|
return sum + (Number(item.weightPercentage) || 0)
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
if (Math.abs(totalWeight - 100) > 0.1) {
|
if (Math.abs(totalWeight - 100) > 0.1) {
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
message: `绩效指标分值占比总和必须等于100%,当前为${totalWeight}%`
|
message: `绩效指标分值占比总和必须等于100%,当前为${totalWeight}%`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { valid: true }
|
return { valid: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,7 +733,7 @@ const handleNextStep = async () => {
|
|||||||
if (currentFormRef?.value) {
|
if (currentFormRef?.value) {
|
||||||
try {
|
try {
|
||||||
await currentFormRef.value.validate()
|
await currentFormRef.value.validate()
|
||||||
|
|
||||||
// 如果是绩效指标步骤(第3步),额外校验分值占比
|
// 如果是绩效指标步骤(第3步),额外校验分值占比
|
||||||
if (currentStep.value === 3) {
|
if (currentStep.value === 3) {
|
||||||
const validationResult = validatePerformanceIndicators()
|
const validationResult = validatePerformanceIndicators()
|
||||||
@@ -692,7 +742,7 @@ const handleNextStep = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentStep.value++
|
currentStep.value++
|
||||||
|
|
||||||
// 初始化图表
|
// 初始化图表
|
||||||
@@ -711,7 +761,7 @@ const handleNextStep = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentStep.value++
|
currentStep.value++
|
||||||
|
|
||||||
// 初始化图表
|
// 初始化图表
|
||||||
@@ -729,7 +779,7 @@ const handlePrevStep = () => {
|
|||||||
const handlePerformanceIndicatorsChange = (indicators) => {
|
const handlePerformanceIndicatorsChange = (indicators) => {
|
||||||
console.log('=== 绩效指标数据变化 ===')
|
console.log('=== 绩效指标数据变化 ===')
|
||||||
console.log('接收到的indicators:', indicators)
|
console.log('接收到的indicators:', indicators)
|
||||||
|
|
||||||
// 为每个指标添加必要的字段
|
// 为每个指标添加必要的字段
|
||||||
const processedIndicators = indicators.map((item, index) => ({
|
const processedIndicators = indicators.map((item, index) => ({
|
||||||
...item,
|
...item,
|
||||||
@@ -751,15 +801,15 @@ const handlePerformanceIndicatorsChange = (indicators) => {
|
|||||||
dataSource: item.dataSource || '',
|
dataSource: item.dataSource || '',
|
||||||
isQuantitative: item.isQuantitative !== undefined ? item.isQuantitative : true
|
isQuantitative: item.isQuantitative !== undefined ? item.isQuantitative : true
|
||||||
}))
|
}))
|
||||||
|
|
||||||
form.performanceIndicators = processedIndicators
|
form.performanceIndicators = processedIndicators
|
||||||
console.log('处理后的绩效指标数据:', form.performanceIndicators)
|
console.log('处理后的绩效指标数据:', form.performanceIndicators)
|
||||||
|
|
||||||
// 自动生成总绩效目标和当年目标(如果有目标值)
|
// 自动生成总绩效目标和当年目标(如果有目标值)
|
||||||
const totalGoals = processedIndicators
|
const totalGoals = processedIndicators
|
||||||
.filter(item => item.targetValue && !isNaN(Number(item.targetValue)))
|
.filter(item => item.targetValue && !isNaN(Number(item.targetValue)))
|
||||||
.reduce((sum, item) => sum + Number(item.targetValue), 0)
|
.reduce((sum, item) => sum + Number(item.targetValue), 0)
|
||||||
|
|
||||||
if (totalGoals > 0) {
|
if (totalGoals > 0) {
|
||||||
form.totalPerformanceGoal = totalGoals
|
form.totalPerformanceGoal = totalGoals
|
||||||
form.currentYearGoal = totalGoals
|
form.currentYearGoal = totalGoals
|
||||||
@@ -771,7 +821,7 @@ const handlePerformanceIndicatorsChange = (indicators) => {
|
|||||||
const handleSaveDraft = async () => {
|
const handleSaveDraft = async () => {
|
||||||
try {
|
try {
|
||||||
savingDraft.value = true
|
savingDraft.value = true
|
||||||
|
|
||||||
// 如果当前在绩效指标步骤(第3步),校验分值占比总和
|
// 如果当前在绩效指标步骤(第3步),校验分值占比总和
|
||||||
if (currentStep.value === 3 && form.performanceIndicators && form.performanceIndicators.length > 0) {
|
if (currentStep.value === 3 && form.performanceIndicators && form.performanceIndicators.length > 0) {
|
||||||
const validationResult = validatePerformanceIndicators()
|
const validationResult = validatePerformanceIndicators()
|
||||||
@@ -780,7 +830,7 @@ const handleSaveDraft = async () => {
|
|||||||
// 注意:这里只是警告,不阻止保存草稿
|
// 注意:这里只是警告,不阻止保存草稿
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 详细调试信息
|
// 详细调试信息
|
||||||
console.log('=== 前端保存草稿调试信息 ===')
|
console.log('=== 前端保存草稿调试信息 ===')
|
||||||
console.log('form.performanceIndicators 是否存在:', !!form.performanceIndicators)
|
console.log('form.performanceIndicators 是否存在:', !!form.performanceIndicators)
|
||||||
@@ -799,10 +849,10 @@ const handleSaveDraft = async () => {
|
|||||||
form.applicationNo = result.data.applicationNo
|
form.applicationNo = result.data.applicationNo
|
||||||
console.log('草稿保存成功,获得ID:', form.id, '申报编号:', form.applicationNo)
|
console.log('草稿保存成功,获得ID:', form.id, '申报编号:', form.applicationNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绩效指标数据已经作为form的一部分传递给后端,无需单独处理
|
// 绩效指标数据已经作为form的一部分传递给后端,无需单独处理
|
||||||
console.log('绩效指标数据已随草稿数据一起保存,数量:', form.performanceIndicators ? form.performanceIndicators.length : 0)
|
console.log('绩效指标数据已随草稿数据一起保存,数量:', form.performanceIndicators ? form.performanceIndicators.length : 0)
|
||||||
|
|
||||||
ElMessage.success('草稿保存成功')
|
ElMessage.success('草稿保存成功')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -913,7 +963,7 @@ const loadData = async () => {
|
|||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
console.log('申报基础数据加载成功:', response.data)
|
console.log('申报基础数据加载成功:', response.data)
|
||||||
Object.assign(form, response.data)
|
Object.assign(form, response.data)
|
||||||
|
|
||||||
// 检查是否有绩效指标数据
|
// 检查是否有绩效指标数据
|
||||||
if (response.data.performanceIndicators && response.data.performanceIndicators.length > 0) {
|
if (response.data.performanceIndicators && response.data.performanceIndicators.length > 0) {
|
||||||
console.log('发现绩效指标数据,数量:', response.data.performanceIndicators.length)
|
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(() => {
|
onMounted(() => {
|
||||||
loadData()
|
loadData()
|
||||||
|
|||||||
Reference in new issue
Block a user