Commit cdec3bb4 by 岑成威

fix: 验证签约

1 parent 489c03a9
/**
* @file 签约金额提交计算服务。
* 仅负责根据页面付款类型计算接口所需 fullPrice,不处理页面 setData 或接口调用。
*/
/**
* 计算签约提交参数中的合同总金额(fullPrice)。
* @param {Object} formData 页面表单数据
* @param {string|number} formData.paymentType 付款类型:1 定金+尾款,2 全款
* @param {string|number} [formData.depositPrice] 定金金额
* @param {string|number} [formData.finalPrice] 尾款金额
* @param {string|number} [formData.fullPrice] 全款金额
* @param {string|number} [formData.evalPrice] 评估价
* @param {Object} [query] 页面路由参数
* @param {string|number} [query.evalPrice] 路由透传评估价
* @returns {number|string} 提交给后端的 fullPrice;无法计算时返回空字符串
*/
function computeSubmitContractAmount(formData = {}, query = {}) {
const evalPrice = Number(formData.evalPrice || query?.evalPrice || 0)
if (formData.paymentType == 1) {
const depositPrice = Number(formData.depositPrice || 0)
const finalPrice = Number(formData.finalPrice || 0)
const splitAmount = depositPrice + finalPrice
// 定金场景优先用分金额合计,避免全款字段串场;分金额缺失时兜底评估价
return splitAmount > 0 ? splitAmount : (evalPrice || '')
}
return formData.fullPrice || evalPrice || ''
}
module.exports = {
computeSubmitContractAmount
}
...@@ -5,12 +5,14 @@ import api from '~/api/api.js' ...@@ -5,12 +5,14 @@ import api from '~/api/api.js'
import { uploadFile, getImageDisplayUrl } from '~/packageUsedCar/utils/oss/ossUpload.js' import { uploadFile, getImageDisplayUrl } from '~/packageUsedCar/utils/oss/ossUpload.js'
import newApi from '~/packageUsedCar/api' import newApi from '~/packageUsedCar/api'
import mapApi from "~/packageUsedCar/utils/mapapi/mapapi"; import mapApi from "~/packageUsedCar/utils/mapapi/mapapi";
import contractAmountService from './services/contractAmount.js'
/** 合同模板查询类型:广联 / 小鹏等 */ /** 合同模板查询类型:广联 / 小鹏等 */
const CONTRACT_TEMPLATE_TYPES = ['1', '5'] const CONTRACT_TEMPLATE_TYPES = ['1', '5']
/** 默认优先选中的合同模板名称 */ /** 默认优先选中的合同模板名称 */
const DEFAULT_TEMPLATE_NAME = '广联二手车转让协议' const DEFAULT_TEMPLATE_NAME = '广联二手车转让协议'
const { computeSubmitContractAmount } = contractAmountService
Page({ Page({
...@@ -577,15 +579,20 @@ Page({ ...@@ -577,15 +579,20 @@ Page({
) )
const pickedTemplate = const pickedTemplate =
template || this.getDefaultTemplate(this.data.contractTemplateList) template || this.getDefaultTemplate(this.data.contractTemplateList)
const evalPrice = formData.evalPrice || query?.evalPrice || ''
this.setData({ this.setData({
formFields: newFormFields, formFields: newFormFields,
'formData.paymentType': value, 'formData.paymentType': value,
'formData.finalPrice': '', 'formData.finalPrice': '',
'formData.depositPrice': '', 'formData.depositPrice': '',
'formData.fullPrice': value == 2 ? evalPrice : '', 'formData.fullPrice': '',
'formData.docTemplateId': pickedTemplate?.docTemplateId || '', 'formData.docTemplateId': pickedTemplate?.docTemplateId || '',
'formData.docTemplateName': pickedTemplate?.docTemplateName || '' 'formData.docTemplateName': pickedTemplate?.docTemplateName || ''
}, () => {
setTimeout(() => {
if (query?.evalPrice && value == 2) {
this.setData({ 'formData.fullPrice': query.evalPrice })
}
}, 150)
}) })
}, },
...@@ -1272,8 +1279,10 @@ Page({ ...@@ -1272,8 +1279,10 @@ Page({
wx.$util.showToast('请选择合同类型') wx.$util.showToast('请选择合同类型')
return return
} }
const contractAmount = computeSubmitContractAmount(formData, query)
const submitData = { const submitData = {
...formData, ...formData,
fullPrice: contractAmount,
evalOrderNo: query.evalOrderNo, evalOrderNo: query.evalOrderNo,
docTemplateId: formData.docTemplateId docTemplateId: formData.docTemplateId
} }
......
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
computeSubmitContractAmount
} = require('../services/contractAmount.js')
describe('signInfo contract amount compute', () => {
it('returns deposit + final for paymentType=1', () => {
const amount = computeSubmitContractAmount({
paymentType: 1,
depositPrice: '1200',
finalPrice: '800',
evalPrice: '3000'
}, {})
assert.equal(amount, 2000)
})
it('falls back to evalPrice for paymentType=1 when split missing', () => {
const amount = computeSubmitContractAmount({
paymentType: 1,
depositPrice: '',
finalPrice: '',
evalPrice: '25600'
}, {})
assert.equal(amount, 25600)
})
it('uses fullPrice for paymentType=2', () => {
const amount = computeSubmitContractAmount({
paymentType: 2,
fullPrice: '18800',
evalPrice: '20000'
}, {})
assert.equal(amount, '18800')
})
it('falls back to query evalPrice for paymentType=2 when fullPrice empty', () => {
const amount = computeSubmitContractAmount({
paymentType: 2,
fullPrice: '',
evalPrice: ''
}, {
evalPrice: '19999'
})
assert.equal(amount, 19999)
})
})
{ {
"projectname": "%E7%B2%BE%E5%93%81%E5%8D%87%E7%BA%A7", "projectname": "%E7%B2%BE%E5%93%81%E5%8D%87%E7%BA%A7",
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "3.13.1", "libVersion": "3.13.1",
"packOptions": { "packOptions": {
"ignore": [ "ignore": [
{ {
"value": ".vscode", "value": ".vscode",
"type": "folder" "type": "folder"
}, },
{ {
"value": "docs", "value": "docs",
"type": "folder" "type": "folder"
}, },
{ {
"value": "packageDynamicForm/tests", "value": "packageDynamicForm/tests",
"type": "folder" "type": "folder"
}, },
{ {
"value": "packageDynamicForm/test", "value": "packageDynamicForm/test",
"type": "folder" "type": "folder"
}, },
{ {
"value": "packageDynamicForm/scripts", "value": "packageDynamicForm/scripts",
"type": "folder" "type": "folder"
}, },
{ {
"value": "packageDynamicForm/docs", "value": "packageDynamicForm/docs",
"type": "folder" "type": "folder"
}, },
{ {
"value": "packageDynamicForm/README.md", "value": "packageDynamicForm/README.md",
"type": "file" "type": "file"
}, },
{ {
"value": "packageDynamicForm/fixtures/schema-staff-daily-full.json", "value": "packageDynamicForm/fixtures/schema-staff-daily-full.json",
"type": "file" "type": "file"
}, },
{ {
"value": "packageDynamicForm/fixtures/mock-store-detail-jsonContent.json", "value": "packageDynamicForm/fixtures/mock-store-detail-jsonContent.json",
"type": "file" "type": "file"
} }
], ],
"include": [] "include": []
}, },
"setting": { "setting": {
"urlCheck": false, "urlCheck": false,
"coverView": true, "coverView": true,
"es6": true, "es6": true,
"postcss": true, "postcss": true,
"minified": true, "minified": true,
"enhance": true, "enhance": true,
"showShadowRootInWxmlPanel": true, "showShadowRootInWxmlPanel": true,
"packNpmRelationList": [ "packNpmRelationList": [
{ {
"packageJsonPath": "./package.json", "packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./" "miniprogramNpmDistDir": "./"
}, },
{ {
"packageJsonPath": "./packageUsedCar/package.json", "packageJsonPath": "./packageUsedCar/package.json",
"miniprogramNpmDistDir": "./packageUsedCar/" "miniprogramNpmDistDir": "./packageUsedCar/"
} }
], ],
"ignoreUploadUnusedFiles": true, "ignoreUploadUnusedFiles": true,
"babelSetting": { "babelSetting": {
"ignore": [], "ignore": [],
"disablePlugins": [], "disablePlugins": [],
"outputPath": "" "outputPath": ""
}, },
"useCompilerPlugins": [ "useCompilerPlugins": [
"sass" "sass"
], ],
"ignoreDevUnusedFiles": false, "ignoreDevUnusedFiles": false,
"minifyWXML": true, "minifyWXML": true,
"compileWorklet": false, "compileWorklet": false,
"uglifyFileName": false, "uglifyFileName": false,
"uploadWithSourceMap": false, "uploadWithSourceMap": false,
"packNpmManually": true, "packNpmManually": true,
"minifyWXSS": true, "minifyWXSS": true,
"localPlugins": false, "localPlugins": false,
"disableUseStrict": false, "disableUseStrict": false,
"condition": false, "condition": false,
"swc": false, "swc": false,
"disableSWC": true "disableSWC": true
}, },
"editorSetting": { "editorSetting": {
"tabIndent": "insertSpaces", "tabIndent": "insertSpaces",
"tabSize": 2 "tabSize": 2
}, },
"appid": "wx4e697bcf4954ceef", "appid": "wx4e697bcf4954ceef",
"simulatorPluginLibVersion": {} "simulatorPluginLibVersion": {}
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!