From 6ab5ebf42ebb857e4b4846f59647a5692e1ad03c Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Tue, 9 Dec 2025 17:07:57 +0800 Subject: [PATCH] up --- .env.development | 4 +- .../components/paymentRegistration.vue | 153 +- src/views/contract/contractList copy.vue | 4265 +++++++++++++++++ src/views/contract/contractList.vue | 442 +- .../statisticalReport/budgetProgress.vue | 18 + .../statisticalReport/quarterlyStatistics.vue | 24 +- 6 files changed, 4765 insertions(+), 141 deletions(-) create mode 100644 src/views/contract/contractList copy.vue diff --git a/.env.development b/.env.development index 4b86c0b..10d6f17 100644 --- a/.env.development +++ b/.env.development @@ -3,9 +3,9 @@ ENV = 'development' # base api -VUE_APP_DOMIAN=http://192.168.60.99:9003/ +VUE_APP_DOMIAN=http://192.168.60.99:8003/ VUE_APP_BASE_API = '' -VUE_APP_UPLOAD=http://192.168.60.99:9003/api/admin/upload-file +VUE_APP_UPLOAD=http://192.168.60.99:8003/api/admin/upload-file VUE_APP_OUT_URL = http://192.168.60.18:8001 #VUE_APP_DOMIAN=http://192.168.60.99:9003/ diff --git a/src/views/contract/components/paymentRegistration.vue b/src/views/contract/components/paymentRegistration.vue index 8c5d523..4d900f4 100644 --- a/src/views/contract/components/paymentRegistration.vue +++ b/src/views/contract/components/paymentRegistration.vue @@ -1017,8 +1017,15 @@ export default { model: 'Contract' }).then(res => { this.templateContextData = res - // 初始化模板字段值 - this.initTemplateFields(res) + // 如果已经在第二步,立即填充到DOM;否则先在HTML字符串中填充值 + if (this.currentStep === 2) { + this.$nextTick(() => { + this.initTemplateFields(res) + }) + } else { + // 在第一步时,先在HTML字符串中填充值 + this.initTemplateFields(res) + } }) } @@ -1071,11 +1078,75 @@ export default { } }, + // 在HTML字符串中填充字段值 + fillFieldsInHtml(html, fields) { + if (!html || !fields) return html + let filledHtml = html + + fields.forEach(field => { + if (field.link_field && field.value !== undefined && field.value !== null && field.value !== '') { + const fieldValue = String(field.value) + + // 先处理 textarea(双标签,需要特殊处理) + const textareaRegex = new RegExp(`(]*data-field="${field.field}"[^>]*>)([\\s\\S]*?)()`, 'gi') + if (textareaRegex.test(filledHtml)) { + filledHtml = filledHtml.replace(textareaRegex, (match, openTag, content, closeTag) => { + return `${openTag}${fieldValue}${closeTag}` + }) + } + + // 处理其他单标签控件(input, select等) + const singleTagRegex = new RegExp(`<([^>]*data-field="${field.field}"[^>]*)>`, 'gi') + filledHtml = filledHtml.replace(singleTagRegex, (match) => { + const controlType = this.getControlType(match) + + if (controlType === 'checkbox' || controlType === 'radio') { + // 对于复选框和单选框,需要处理 checked 属性 + const currentValue = this.getControlValue(match) + if (String(fieldValue) === String(currentValue)) { + if (!match.includes('checked')) { + return match.replace('>', ' checked>') + } + } else { + // 如果值不匹配,移除 checked 属性 + return match.replace(/\s+checked(\s|>)/g, '$1') + } + } else { + // 对于其他控件,设置 value 属性 + if (!match.includes('value=')) { + return match.replace('>', ` value="${fieldValue}">`) + } else { + return match.replace(/value="[^"]*"/i, `value="${fieldValue}"`) + } + } + return match + }) + } + }) + + return filledHtml + }, + + // 获取控件类型 + getControlType(controlHtml) { + if (controlHtml.includes('type="checkbox"')) return 'checkbox' + if (controlHtml.includes('type="radio"')) return 'radio' + if (controlHtml.includes(' { - // 检查字段是否有link_type且该字段在other_data_fill中存在 + // 检查字段是否有link_field且该字段在other_data_fill中存在 if (field.link_field && contextData.other_data_fill[field.link_field]) { let value = contextData.other_data_fill[field.link_field] @@ -1086,34 +1157,54 @@ export default { // 设置字段值 field.value = value + } + }) - // 更新DOM中的值 + // 如果当前在第二步,DOM已经渲染,可以直接填充 + if (this.currentStep === 2) { + this.$nextTick(() => { const dom = tableIndex === 1 ? this.$refs.mainTable1 : this.$refs.mainTable2 if (dom) { - const input = dom.querySelector(`[data-field="${field.field}"]`) - if (input) { - if (input.type === 'checkbox' || input.type === 'radio') { - if (field.value === input.value) { - input.checked = true + // 遍历字段,填充到DOM + fields.forEach(field => { + if (field.link_field && field.value !== undefined && field.value !== null && field.value !== '') { + const input = dom.querySelector(`[data-field="${field.field}"]`) + if (input) { + if (input.type === 'checkbox' || input.type === 'radio') { + if (String(field.value) === input.value) { + input.checked = true + } + } else if (input.tagName.toLowerCase() === 'textarea') { + input.textContent = field.value + } else { + input.value = field.value + } } - } else { - input.value = field.value } + }) + + // 更新对应tab的数据源 + const updatedForms = syncFormDomToHtml(dom, fields) + if (tableIndex === 1) { + this.forms1 = updatedForms + this.forms = this.forms1 // 默认使用第一个表格的数据 + } else if (tableIndex === 2) { + this.forms2 = updatedForms } } - } - }) - - // 更新对应tab的数据源 - const dom = tableIndex === 1 ? this.$refs.mainTable1 : this.$refs.mainTable2 - if (dom) { - const updatedForms = syncFormDomToHtml(dom, fields) - if (tableIndex === 1) { - this.forms1 = updatedForms - this.forms = this.forms1 // 默认使用第一个表格的数据 - } else if (tableIndex === 2) { - this.forms2 = updatedForms + }) + } else { + // 如果还在第一步,先在HTML字符串中填充值 + let html = tableIndex === 1 ? this.forms1 : this.forms2 + if (html) { + html = this.fillFieldsInHtml(html, fields) + if (tableIndex === 1) { + this.forms1 = html + this.forms = this.forms1 + } else if (tableIndex === 2) { + this.forms2 = html + } } } }, @@ -1307,8 +1398,13 @@ export default { if (res) { // 验证通过,进入第二步显示事后支付表格 this.currentStep = 2 - // 切换到第二步后,需要重新设置amount输入框的监听 + // 切换到第二步后,需要重新设置amount输入框的监听,并填充模板字段值 this.$nextTick(() => { + // 填充模板字段值 + if (this.templateContextData) { + this.initTemplateFields(this.templateContextData) + } + // 设置amount输入框的监听 this.setupAmountListeners(this.$refs.mainTable1) this.setupAmountListeners(this.$refs.mainTable2) }) @@ -1323,8 +1419,13 @@ export default { } else { // 如果没有表单验证器,直接进入第二步 this.currentStep = 2 - // 切换到第二步后,需要重新设置amount输入框的监听 + // 切换到第二步后,需要重新设置amount输入框的监听,并填充模板字段值 this.$nextTick(() => { + // 填充模板字段值 + if (this.templateContextData) { + this.initTemplateFields(this.templateContextData) + } + // 设置amount输入框的监听 this.setupAmountListeners(this.$refs.mainTable1) this.setupAmountListeners(this.$refs.mainTable2) }) diff --git a/src/views/contract/contractList copy.vue b/src/views/contract/contractList copy.vue new file mode 100644 index 0000000..662fa62 --- /dev/null +++ b/src/views/contract/contractList copy.vue @@ -0,0 +1,4265 @@ + + + + + + + + + + diff --git a/src/views/contract/contractList.vue b/src/views/contract/contractList.vue index 07cf2c5..0c15865 100644 --- a/src/views/contract/contractList.vue +++ b/src/views/contract/contractList.vue @@ -284,21 +284,39 @@ -