diff --git a/src/views/contract/components/paymentRegistration.vue b/src/views/contract/components/paymentRegistration.vue index 474f556..8ccb008 100644 --- a/src/views/contract/components/paymentRegistration.vue +++ b/src/views/contract/components/paymentRegistration.vue @@ -228,6 +228,47 @@ } from "@/utils"; import { getContractTemplateContext } from '@/api/businessConfig/businessConfig'; + // 添加金额转大写的工具函数 + function numberToChinese(num) { + const units = ['', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿']; + const digits = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']; + + // 处理小数部分 + const [integer, decimal] = num.toString().split('.'); + let result = ''; + + // 处理整数部分 + let intNum = parseInt(integer); + if (intNum === 0) { + result = '零'; + } else { + let i = 0; + while (intNum > 0) { + const digit = intNum % 10; + if (digit !== 0) { + result = digits[digit] + units[i] + result; + } else if (result.charAt(0) !== '零') { + result = '零' + result; + } + intNum = Math.floor(intNum / 10); + i++; + } + } + + // 处理小数部分 + if (decimal) { + const decimalNum = parseInt(decimal); + if (decimalNum > 0) { + result += '点'; + for (let i = 0; i < decimal.length; i++) { + result += digits[parseInt(decimal[i])]; + } + } + } + + return result + '元整'; + } + // 添加同步表单DOM到HTML的函数 function syncFormDomToHtml(dom, contractTemplateFields) { if (!dom) return ''; @@ -308,30 +349,58 @@ form: { audit_money: 0 }, - // paymentRegistrationRules: { - // applyMoney: [{ - // required: true, - // message: "必填" - // }, - // { - // pattern: /(^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d{1,2})?$)/, - // message: '必须为数字' - // } - // ], - // deductionMoney: [{ - // required: true, - // message: "必填" - // }, - // { - // pattern: /(^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d{1,2})?$)/, - // message: '必须为数字' - // } - // ], - // type: [{ - // required: true, - // message: "必选" - // }] - // }, + paymentRegistrationRules: { + applyMoney: [ + { + required: false, + message: '必填' + }, + { + pattern: /(^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d{1,2})?$)/, + message: '必须为数字' + } + ], + deductionMoney: [ + { + required: false, + message: '必填' + }, + { + pattern: /(^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d{1,2})?$)/, + message: '必须为数字' + } + ], + audit_money: [ + { + required: false, + message: '必填' + } + ], + type: [ + { + required: false, + message: '必选' + } + ], + isLast: [ + { + required: false, + message: '必选' + } + ], + remark: [ + { + required: false, + message: '必填' + } + ], + act_date: [ + { + required: false, + message: '必填' + } + ] + }, planTable: [{ sortable: false, width: 36, @@ -538,6 +607,7 @@ this.contractTemplate = null; this.forms = null; } + // 拉取合同模板关联数据 if (this.contract && this.contract.id) { getContractTemplateContext({ @@ -545,7 +615,57 @@ model: 'Contract' }).then(res => { this.templateContextData = res; + // 初始化模板字段值 + this.initTemplateFields(res); + }); + } + }, + + // 初始化模板字段值 + initTemplateFields(contextData) { + if (!contextData || !contextData.other_data_fill) return; + + // 获取事后支付模板 + if (this.contract.contract_template && this.contract.contract_template.contract_template_fields) { + const fields = this.contract.contract_template.contract_template_fields; + + // 遍历模板字段 + fields.forEach(field => { + // 检查字段是否有link_type且该字段在other_data_fill中存在 + if (field.link_field && contextData.other_data_fill[field.link_field]) { + let value = contextData.other_data_fill[field.link_field]; + + // 如果是upper_money字段,转换为金额大写 + if (field.link_field === 'upper_money') { + value = numberToChinese(Number(value)); + } + + // 设置字段值 + field.value = value; + + // 更新DOM中的值 + const dom = this.$refs.zoomedForms || this.$refs.zoomedTemplate; + if (dom) { + const input = dom.querySelector(`[data-field="${field.field}"]`); + if (input) { + if (input.type === 'checkbox' || input.type === 'radio') { + // 对于复选框和单选框,需要设置checked属性 + if (field.value === input.value) { + input.checked = true; + } + } else { + // 对于其他类型的输入,直接设置value + input.value = field.value; + } + } + } + } }); + + // 更新forms内容 + if (this.$refs.zoomedForms) { + this.forms = syncFormDomToHtml(this.$refs.zoomedForms, fields); + } } }, @@ -590,12 +710,12 @@ let data = { contract_id: this.contract.id, - apply_money: this.paymentRegistrationForm.applyMoney, - discount_money: this.paymentRegistrationForm.deductionMoney, - type: this.paymentRegistrationForm.type, + apply_money: this.paymentRegistrationForm.applyMoney?this.paymentRegistrationForm.applyMoney:0, + discount_money: this.paymentRegistrationForm.deductionMoney?this.paymentRegistrationForm.deductionMoney:0, + type: this.paymentRegistrationForm.type?this.paymentRegistrationForm.type:0, is_end: this.paymentRegistrationForm.isLast ? 1 : 0, remark: this.paymentRegistrationForm.remark, - audit_money: this.paymentRegistrationForm.audit_money, + audit_money: this.paymentRegistrationForm.audit_money?this.paymentRegistrationForm.audit_money:0, end_time:this.paymentRegistrationForm.end_time, is_check:this.paymentRegistrationForm.isCheck ? 1 : 0, // 提交更新后的HTML和字段数据 diff --git a/src/views/contract/contractList.vue b/src/views/contract/contractList.vue index 70d05c7..5caaca9 100644 --- a/src/views/contract/contractList.vue +++ b/src/views/contract/contractList.vue @@ -1227,7 +1227,10 @@ export default { minWidth: 200, prop: "contract_carry_department", customFn: row => { - return row.contract_carry_department.map(i => i.carry_department.name).join(',') + if (!row.contract_carry_department || !row.contract_carry_department.length) { + return '未设置' + } + return row.contract_carry_department.map(i => i.carry_department?.name || '未设置').join(',') } } ],