From ed4565a4cd6f282a67f06b983c72ffce80174bf9 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Fri, 19 Dec 2025 15:04:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/paymentRegistration.vue | 174 ++++++++++++++++-- .../contract/components/printPaymentForm.vue | 40 ++-- src/views/contract/contractList.vue | 6 +- .../contract/paymentRegistrationList.vue | 2 + src/views/contract/seeContract.vue | 19 +- 5 files changed, 205 insertions(+), 36 deletions(-) diff --git a/src/views/contract/components/paymentRegistration.vue b/src/views/contract/components/paymentRegistration.vue index 4d900f4..4487307 100644 --- a/src/views/contract/components/paymentRegistration.vue +++ b/src/views/contract/components/paymentRegistration.vue @@ -1084,8 +1084,24 @@ export default { let filledHtml = html fields.forEach(field => { - if (field.link_field && field.value !== undefined && field.value !== null && field.value !== '') { - const fieldValue = String(field.value) + // 特殊字段:即使值为0或空字符串也要填充 + const isSpecialField = field.field === 'auditAmount' || field.field === 'currentDuePayment' || + field.field === 'currentPayment' || field.field === 'currentPaymentRemark' || + field.field === 'totalPaid' || field.field === 'totalPlanned' + + // 特殊字段或普通字段,只要有值就填充 + if (isSpecialField || (field.value !== undefined && field.value !== null && field.value !== '')) { + // 特殊字段如果值为空,根据字段类型设置默认值 + let fieldValue = '' + if (isSpecialField) { + if (field.field === 'currentPaymentRemark') { + fieldValue = String(field.value || '') + } else { + fieldValue = String(field.value || '0') + } + } else { + fieldValue = String(field.value) + } // 先处理 textarea(双标签,需要特殊处理) const textareaRegex = new RegExp(`(]*data-field="${field.field}"[^>]*>)([\\s\\S]*?)()`, 'gi') @@ -1096,6 +1112,21 @@ export default { } // 处理其他单标签控件(input, select等) + // 对于单选框,需要先移除所有同名的单选框的 checked 属性 + if (field.field === 'currentPaymentRemark') { + const radioNameMatch = filledHtml.match(new RegExp(`]*data-field="${field.field}"[^>]*name="([^"]*)"[^>]*>`, 'i')) + if (radioNameMatch) { + const radioName = radioNameMatch[1] + // 转义特殊字符 + const escapedRadioName = radioName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + // 先移除所有同名单选框的 checked 属性 + const allRadioRegex = new RegExp(`(]*name="${escapedRadioName}"[^>]*)checked[^>]*>`, 'gi') + filledHtml = filledHtml.replace(allRadioRegex, (match) => { + return match.replace(/\s+checked(\s|>)/g, '$1') + }) + } + } + const singleTagRegex = new RegExp(`<([^>]*data-field="${field.field}"[^>]*)>`, 'gi') filledHtml = filledHtml.replace(singleTagRegex, (match) => { const controlType = this.getControlType(match) @@ -1103,9 +1134,24 @@ export default { if (controlType === 'checkbox' || controlType === 'radio') { // 对于复选框和单选框,需要处理 checked 属性 const currentValue = this.getControlValue(match) - if (String(fieldValue) === String(currentValue)) { + const fieldValueTrimmed = String(fieldValue).trim() + const currentValueTrimmed = String(currentValue).trim() + if (field.field === 'currentPaymentRemark') { + console.log('HTML fill - currentPaymentRemark:', { + fieldValue: fieldValueTrimmed, + currentValue: currentValueTrimmed, + match: fieldValueTrimmed === currentValueTrimmed, + originalMatch: match + }) + } + if (fieldValueTrimmed === currentValueTrimmed) { if (!match.includes('checked')) { - return match.replace('>', ' checked>') + // 在 > 之前插入 checked 属性,确保格式正确 + const newMatch = match.replace(/(\s*)>/, ' checked$1>') + if (field.field === 'currentPaymentRemark') { + console.log('Added checked to HTML:', newMatch) + } + return newMatch } } else { // 如果值不匹配,移除 checked 属性 @@ -1144,10 +1190,46 @@ export default { // 为指定表格初始化模板字段值 initTemplateFieldsForTable(fields, contextData, tableIndex) { + // 先获取 previousPayment 的值(用于计算 totalPaid) + let previousPaymentValue = 0 + const previousPaymentField = fields.find(f => f.field === 'previousPayment') + if (previousPaymentField && previousPaymentField.link_field && contextData && contextData.other_data_fill && contextData.other_data_fill[previousPaymentField.link_field]) { + previousPaymentValue = parseFloat(contextData.other_data_fill[previousPaymentField.link_field]) || 0 + } + + // 获取 currentPayment 的值(用于计算 totalPaid 和 totalPlanned) + const currentPaymentValue = parseFloat(this.paymentRegistrationForm.deductionMoney) || 0 + // 遍历模板字段,先设置字段值 fields.forEach(field => { - // 检查字段是否有link_field且该字段在other_data_fill中存在 - if (field.link_field && contextData.other_data_fill[field.link_field]) { + // 特殊字段处理:从 paymentRegistrationForm 中获取值 + if (field.field === 'auditAmount') { + // 审计金额:从 paymentRegistrationForm.audit_money 获取,如果没有则为 0 + field.value = this.paymentRegistrationForm.audit_money || '0' + } else if (field.field === 'currentDuePayment') { + // 当前应付金额:从 paymentRegistrationForm.applyMoney 获取,如果没有则为 0 + field.value = this.paymentRegistrationForm.applyMoney || '0' + } else if (field.field === 'currentPayment') { + // 当前扣款金额:从 paymentRegistrationForm.deductionMoney 获取,如果没有则为 0 + field.value = this.paymentRegistrationForm.deductionMoney || '0' + } else if (field.field === 'currentPaymentRemark') { + // 当前付款备注:从 paymentRegistrationForm.type 获取,如果没有则为空字符串 + field.value = this.paymentRegistrationForm.type || '' + console.log('currentPaymentRemark field value:', field.value, 'from paymentRegistrationForm.type:', this.paymentRegistrationForm.type) + } else if (field.field === 'totalPaid') { + // 累计已付款:previousPayment + currentPayment + const totalPaidValue = previousPaymentValue + currentPaymentValue + field.value = totalPaidValue.toString() + } else if (field.field === 'totalPlanned') { + // 累计计划付款:对照值(从 other_data_fill 获取)+ currentPayment + let baseValue = 0 + if (field.link_field && contextData && contextData.other_data_fill && contextData.other_data_fill[field.link_field]) { + baseValue = parseFloat(contextData.other_data_fill[field.link_field]) || 0 + } + const totalPlannedValue = baseValue + currentPaymentValue + field.value = totalPlannedValue.toString() + } else if (field.link_field && contextData && contextData.other_data_fill && contextData.other_data_fill[field.link_field]) { + // 普通字段:从 other_data_fill 中获取 let value = contextData.other_data_fill[field.link_field] // 如果是upper_money字段,转换为金额大写 @@ -1166,18 +1248,86 @@ export default { const dom = tableIndex === 1 ? this.$refs.mainTable1 : this.$refs.mainTable2 if (dom) { + // 先处理所有单选框组,取消选中状态 + const radioGroups = new Set() + fields.forEach(field => { + if (field.field === 'currentPaymentRemark') { + const input = dom.querySelector(`[data-field="${field.field}"]`) + if (input && input.type === 'radio' && input.name) { + radioGroups.add(input.name) + } + } + }) + + // 取消所有单选框组的选中状态 + radioGroups.forEach(radioName => { + const allRadios = dom.querySelectorAll(`input[type="radio"][name="${radioName}"]`) + allRadios.forEach(radio => { + radio.checked = false + radio.removeAttribute('checked') + }) + }) + // 遍历字段,填充到DOM fields.forEach(field => { - if (field.link_field && field.value !== undefined && field.value !== null && field.value !== '') { + if (field.field === 'currentPaymentRemark') { + // 特殊处理 currentPaymentRemark 单选框 + const fieldValueStr = String(field.value || '').trim() + console.log('Processing currentPaymentRemark, fieldValue:', fieldValueStr) + if (fieldValueStr) { + // 先取消所有单选框的选中状态 + const allRadios = dom.querySelectorAll(`input[type="radio"][data-field="currentPaymentRemark"]`) + console.log('Found radios:', allRadios.length) + allRadios.forEach(radio => { + radio.checked = false + radio.removeAttribute('checked') + const inputValueStr = String(radio.value || '').trim() + console.log('Radio value:', inputValueStr, 'matches?', fieldValueStr === inputValueStr) + if (fieldValueStr === inputValueStr) { + radio.checked = true + radio.setAttribute('checked', 'checked') + // 触发 change 事件以确保UI更新 + const changeEvent = new Event('change', { bubbles: true }) + radio.dispatchEvent(changeEvent) + // 也触发 click 事件以确保视觉更新 + const clickEvent = new Event('click', { bubbles: true }) + radio.dispatchEvent(clickEvent) + console.log('currentPaymentRemark selected:', { + fieldValue: fieldValueStr, + inputValue: inputValueStr, + radio: radio + }) + } + }) + } + } else { const input = dom.querySelector(`[data-field="${field.field}"]`) - if (input) { - if (input.type === 'checkbox' || input.type === 'radio') { - if (String(field.value) === input.value) { + if (!input) return + + // 处理单选框和复选框 + if (input.type === 'checkbox' || input.type === 'radio') { + // 检查值是否匹配 + if (field.value !== undefined && field.value !== null && field.value !== '') { + const fieldValueStr = String(field.value).trim() + const inputValueStr = String(input.value).trim() + if (fieldValueStr === inputValueStr) { input.checked = true + input.setAttribute('checked', 'checked') } - } else if (input.tagName.toLowerCase() === 'textarea') { + } + } else if (input.tagName.toLowerCase() === 'textarea') { + // 处理文本域 + if (field.value !== undefined && field.value !== null) { input.textContent = field.value - } else { + } + } else { + // 处理普通输入框 + // 特殊字段即使值为0也要填充 + if (field.field === 'auditAmount' || field.field === 'currentDuePayment' || + field.field === 'currentPayment' || field.field === 'totalPaid' || + field.field === 'totalPlanned') { + input.value = field.value || '0' + } else if (field.value !== undefined && field.value !== null && field.value !== '') { input.value = field.value } } diff --git a/src/views/contract/components/printPaymentForm.vue b/src/views/contract/components/printPaymentForm.vue index bf8bf0b..e35ad45 100644 --- a/src/views/contract/components/printPaymentForm.vue +++ b/src/views/contract/components/printPaymentForm.vue @@ -745,26 +745,26 @@ export default { // 对于其他类型的输入,直接设置value // 如果是资金划拨审批单,为特定字段设置默认值 if (this.getForms && this.getForms.includes('资金划拨审批单')) { - const amountFields = ['contractAmount', 'auditAmount', 'previousPayment', 'currentPayment', 'currentDuePayment', 'totalPaid', 'totalPlanned'] - if (amountFields.includes(fieldName)) { - if (fieldName === 'previousPayment' && this.fundLog) { - // previousPayment字段设置为this.fundLog中的total_act_money字段值 - input.setAttribute('value', this.fundLog.total_act_money) - } else if (fieldName === 'totalPaid' && this.fundLog) { - // totalPaid字段设置为this.fundLog.total_act_money + currentPayment的值 - const currentPaymentInput = dom.querySelector('input[data-field="currentDuePayment"]') - console.log('currentPaymentInput',currentPaymentInput.value) - const currentPaymentValue = currentPaymentInput ? (parseFloat(currentPaymentInput.value) || 0) : 0 - const totalPaidValue = (parseFloat(this.fundLog.total_act_money) || 0) + currentPaymentValue - input.setAttribute('value', totalPaidValue.toString()) - } else if (!input.value || input.value === '') { - input.setAttribute('value', '0') - } else { - input.setAttribute('value', input.value) - } - } else { - input.setAttribute('value', input.value) - } + // const amountFields = ['contractAmount', 'auditAmount', 'previousPayment', 'currentPayment', 'currentDuePayment', 'totalPaid', 'totalPlanned'] + // if (amountFields.includes(fieldName)) { + // if (fieldName === 'previousPayment' && this.fundLog) { + // // previousPayment字段设置为this.fundLog中的total_act_money字段值 + // input.setAttribute('value', this.fundLog.total_act_money) + // } else if (fieldName === 'totalPaid' && this.fundLog) { + // // totalPaid字段设置为this.fundLog.total_act_money + currentPayment的值 + // const currentPaymentInput = dom.querySelector('input[data-field="currentDuePayment"]') + // console.log('currentPaymentInput',currentPaymentInput.value) + // const currentPaymentValue = currentPaymentInput ? (parseFloat(currentPaymentInput.value) || 0) : 0 + // const totalPaidValue = (parseFloat(this.fundLog.total_act_money) || 0) + currentPaymentValue + // input.setAttribute('value', totalPaidValue.toString()) + // } else if (!input.value || input.value === '') { + // input.setAttribute('value', '0') + // } else { + // input.setAttribute('value', input.value) + // } + // } else { + // input.setAttribute('value', input.value) + // } } else { input.setAttribute('value', input.value) } diff --git a/src/views/contract/contractList.vue b/src/views/contract/contractList.vue index 971001c..74e8ba6 100644 --- a/src/views/contract/contractList.vue +++ b/src/views/contract/contractList.vue @@ -215,6 +215,7 @@