大写金额

master
lion 3 months ago
parent f645540906
commit b21278dfb6

@ -287,17 +287,20 @@ export function numberToChinese(num) {
for (let i = 0; i < groups.length; i++) { for (let i = 0; i < groups.length; i++) {
const section = groups[i] const section = groups[i]
if (section === 0) { if (section === 0) {
if (result) needZero = true if (groups.slice(i + 1).some(g => g > 0)) {
needZero = true
}
continue continue
} }
const sectionStr = convertSection(section) const sectionStr = convertSection(section)
let prefix = sectionStr + bigUnits[i] const prefix = sectionStr + bigUnits[i]
if (needZero) { if (needZero && result) {
result = prefix + '零' + result result = prefix + '零' + result
needZero = false needZero = false
} else { } else {
const lower = groups.slice(0, i).reduce((sum, g, idx) => sum + g * Math.pow(10000, idx), 0) const lower = groups.slice(0, i).reduce((sum, g, idx) => sum + g * Math.pow(10000, idx), 0)
const padZero = i > 0 && lower > 0 && section < 1000 // 低位段不足千位,或高位段整百/整千结尾且低位非空时,需补「零」
const padZero = i > 0 && lower > 0 && (lower < 1000 || (section >= 100 && section % 100 === 0))
result = prefix + (padZero ? '零' : '') + result result = prefix + (padZero ? '零' : '') + result
} }
} }

@ -35,7 +35,7 @@
<!-- Post-payment Form --> <!-- Post-payment Form -->
<div v-else-if="currentForm === 'post'" ref="printtable" class="payment-form"> <div v-else-if="currentForm === 'post'" ref="printtable" class="payment-form">
<!-- 财务审核表内容放到事后支付表头部 --> <!-- 财务审核表内容放到事后支付表头部(仅预览,不参与保存/打印) -->
<table class="finance-review-table no-print"> <table class="finance-review-table no-print">
<tr> <tr>
<th colspan="2" class="finance-header-row">合同信息</th> <th colspan="2" class="finance-header-row">合同信息</th>
@ -68,7 +68,7 @@
<td colspan="2">{{ fundLog && fundLog.remark || '-' }}</td> <td colspan="2">{{ fundLog && fundLog.remark || '-' }}</td>
</tr> </tr>
</table> </table>
<div v-if="getForms" :key="formsRenderKey" v-html="getForms" /> <div v-if="getForms" ref="formsContent" :key="formsRenderKey" v-html="getForms" />
<div v-else class="no-form-message">暂无事后支付表格内容</div> <div v-else class="no-form-message">暂无事后支付表格内容</div>
</div> </div>
</div> </div>
@ -182,6 +182,9 @@ export default {
try { try {
this.fundLog = null this.fundLog = null
const res = await detailFundLog({ id }) const res = await detailFundLog({ id })
if (res && res.forms) {
res.forms = this.stripFinanceReviewTable(res.forms)
}
this.fundLog = res this.fundLog = res
this.formsRenderKey += 1 this.formsRenderKey += 1
} catch (error) { } catch (error) {
@ -190,6 +193,17 @@ export default {
throw error throw error
} }
}, },
/** 移除 forms 中误保存的合同信息表(历史数据兼容) */
stripFinanceReviewTable(html) {
if (!html || typeof html !== 'string') return html
const wrapper = document.createElement('div')
wrapper.innerHTML = html
wrapper.querySelectorAll('.finance-review-table').forEach(el => el.remove())
return wrapper.innerHTML
},
getFormContentDom() {
return this.$refs.formsContent || this.$refs.printtable
},
handleCancel() { handleCancel() {
this.isShow = false this.isShow = false
}, },
@ -316,7 +330,7 @@ export default {
this.syncAllUppercase(dom) this.syncAllUppercase(dom)
}, },
syncFormDomToHtml() { syncFormDomToHtml() {
const dom = this.$refs.printtable const dom = this.getFormContentDom()
if (!dom || !this.fundLog) return if (!dom || !this.fundLog) return
const templateFields = this.fundLog.other_data const templateFields = this.fundLog.other_data
const inputs = dom.querySelectorAll('input, select, textarea') const inputs = dom.querySelectorAll('input, select, textarea')
@ -351,13 +365,13 @@ export default {
input.setAttribute('value', input.value) input.setAttribute('value', input.value)
} }
}) })
this.fundLog.forms = dom.innerHTML this.fundLog.forms = this.stripFinanceReviewTable(dom.innerHTML)
}, },
async syncAndSave() { async syncAndSave() {
if (!this.fundLog || !this.fundLog.id) { if (!this.fundLog || !this.fundLog.id) {
throw new Error('缺少付款登记数据') throw new Error('缺少付款登记数据')
} }
const dom = this.$refs.printtable const dom = this.getFormContentDom()
if (dom) { if (dom) {
this.syncAllUppercase(dom) this.syncAllUppercase(dom)
this.syncFormDomToHtml() this.syncFormDomToHtml()
@ -918,20 +932,23 @@ export default {
}, },
async print() { async print() {
try { try {
const sourceDom = this.getFormContentDom()
if (!sourceDom) {
this.$Message.error('暂无可打印内容')
return
}
const tempContainer = document.createElement('div') const tempContainer = document.createElement('div')
tempContainer.style.position = 'absolute' tempContainer.style.position = 'absolute'
tempContainer.style.left = '-9999px' tempContainer.style.left = '-9999px'
tempContainer.style.top = '-9999px' tempContainer.style.top = '-9999px'
document.body.appendChild(tempContainer) document.body.appendChild(tempContainer)
const originalContent = this.$refs['printtable'].cloneNode(true) const originalContent = sourceDom.cloneNode(true)
tempContainer.appendChild(originalContent) tempContainer.appendChild(originalContent)
// 移除财务审核表 // 移除所有合同信息表
const financeTable = tempContainer.querySelector('.finance-review-table') tempContainer.querySelectorAll('.finance-review-table').forEach(el => el.remove())
if (financeTable) {
financeTable.remove()
}
this.replaceControls(tempContainer) this.replaceControls(tempContainer)
@ -958,8 +975,9 @@ export default {
return Number(val).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') return Number(val).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
}, },
printHtml() { printHtml() {
// 先同步用户输入到HTML // 只同步/打印表单内容,不包含预览用的合同信息表
const dom = this.$refs.printtable const formsDom = this.getFormContentDom()
const dom = formsDom || this.$refs.printtable
if (dom) { if (dom) {
this.syncAllUppercase(dom) this.syncAllUppercase(dom)
// 获取所有输入控件 // 获取所有输入控件
@ -1019,15 +1037,12 @@ export default {
}) })
} }
// 使用同步后的HTML数据 // 使用同步后的HTML数据(仅表单区域)
const printNode = document.createElement('div') const printNode = document.createElement('div')
printNode.innerHTML = dom.innerHTML printNode.innerHTML = dom ? dom.innerHTML : ''
// 移除财务审核表 // 移除所有合同信息表
const financeTable = printNode.querySelector('.finance-review-table') printNode.querySelectorAll('.finance-review-table').forEach(el => el.remove())
if (financeTable) {
financeTable.remove()
}
// 替换控件为纯文本(保留样式) // 替换控件为纯文本(保留样式)
this.replaceControls(printNode) this.replaceControls(printNode)

Loading…
Cancel
Save