diff --git a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java index b4eb2cf..c1bab59 100644 --- a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java +++ b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java @@ -17,6 +17,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.datetime.DateFormatter; +import org.springframework.format.number.NumberStyleFormatter; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.WebDataBinder; @@ -551,6 +552,7 @@ public class ProjectController extends BaseController { @InitBinder public void initBinder(WebDataBinder webDataBinder) { webDataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd")); + webDataBinder.addCustomFormatter(new NumberStyleFormatter()); } /** diff --git a/src/main/resources/static/assets/js/project_common.js b/src/main/resources/static/assets/js/project_common.js index a848702..c61cd3c 100644 --- a/src/main/resources/static/assets/js/project_common.js +++ b/src/main/resources/static/assets/js/project_common.js @@ -9,7 +9,6 @@ var layuiAlert = function(msg) { }); }; - /** * parse float保留两位小数,四舍五入 * 空格或者非数字认为是0 @@ -20,6 +19,10 @@ function f2(x) { if(!x){ return 0; } + if(typeof x === 'string'){ + //这一步因为数字格式化为了包含分隔符,获取的时候就去掉这个分隔符 + x = x.replaceAll(",",""); + } var f = parseFloat(x); if (isNaN(f)) { return 0; @@ -28,17 +31,24 @@ function f2(x) { } /** - * 给定一个数字,保留两位小数输出 + * 给定一个数字,保留两位小数输出,格式化为包含分隔符 * @param f * @returns {string} */ function f2Fixed(f) { - return Number(f).toFixed(2); - - //格式化413,423,423.24,数字类型的输入框填入这样的有问题 - //return Number(f).toLocaleString('zh',{minimumFractionDigits: 2, maximumFractionDigits: 2, useGrouping: true}); + //return Number(f).toFixed(2); + //格式化413,423,423.24 + f = Number(f).toLocaleString('en-US',{minimumFractionDigits: 2, maximumFractionDigits: 2, useGrouping: true}); + return f; } +function digitalSelf(name, action) { + var self = inputVal(name); + + var $action = $(action); + + $action.val(f2Fixed(f2(self))); +} /** * 计算利润率 @@ -56,32 +66,37 @@ function rate(r1,r2) { /** - * 保留两位小数 + * 保留数字两位小数 */ function bindNumberInput() { - //所有的数字输入框 - var $inputs = $("input[type='number']"); + //所有的数字类型输入框 + var $numberTypeInputs = $("input[type='number']"); + inputKeepDigital($numberTypeInputs); + //所有的number类的输入框 + var $numberClassInputs = $("input.number"); + inputKeepDigital($numberClassInputs); +} + +function inputKeepDigital($inputs) { //键盘键弹起的时候 $inputs.keyup(function () { keepDigital($(this)); }); //失去焦点时再校验一遍 $inputs.blur(function() { - - /*var reg = new RegExp("^(\-)?[0-9]+(.[0-9]{1,2})?$"); - if (reg.test(value)) { - //是数字就是数字,可以两位或者不带小数 - $(this).val(value); - } else { - $(this).val(""); - }*/ keepDigital($(this)); }); } function keepDigital($input) { - var value = $input.val(); + $input.val(keepDigitalVal($input.val())); +} + +/** + * 只保留数字 + */ +function keepDigitalVal(value) { value = value.replace(/[^\-\d.]/g, ""); //清除“-”、“数字”和“.”以外的字符 value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的 value = value.replace(".", "$#$").replace(/\./g, "").replace("$#$", "."); @@ -90,7 +105,8 @@ function keepDigital($input) { //以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额 value = parseFloat(value); } - $input.val(value); + + return value; } /** diff --git a/src/main/resources/static/assets/js/project_estimate.js b/src/main/resources/static/assets/js/project_estimate.js index b33e3a4..19af6c8 100644 --- a/src/main/resources/static/assets/js/project_estimate.js +++ b/src/main/resources/static/assets/js/project_estimate.js @@ -4,30 +4,36 @@ function calIncomeAndCost() { calIncomeCost(); calIncomeDeviceTaxExclude(); + digitalSelf("incomeDeviceTaxInclude", "input[name='incomeDeviceTaxInclude']"); }); $("input[name='incomeEngineerTaxInclude']").change(function () { calIncomeInclude(); calIncomeCost(); calIncomeEngineerTaxExclude(); + digitalSelf("incomeEngineerTaxInclude", "input[name='incomeEngineerTaxInclude']"); }); $("input[name='incomeServiceTaxInclude']").change(function () { calIncomeInclude(); calIncomeCost(); calIncomeServiceTaxExclude(); + digitalSelf("incomeServiceTaxInclude", "input[name='incomeServiceTaxInclude']"); }); $("input[name='incomeDeviceTaxExclude']").change(function () { calIncomeExclude(); calIncomeCost(); + digitalSelf("incomeDeviceTaxExclude", "input[name='incomeDeviceTaxExclude']"); }); $("input[name='incomeEngineerTaxExclude']").change(function () { calIncomeExclude(); calIncomeCost(); + digitalSelf("incomeEngineerTaxExclude", "input[name='incomeEngineerTaxExclude']"); }); $("input[name='incomeServiceTaxExclude']").change(function () { calIncomeExclude(); calIncomeCost(); + digitalSelf("incomeServiceTaxExclude", "input[name='incomeServiceTaxExclude']"); }); @@ -38,24 +44,28 @@ function calIncomeAndCost() { calIncomeCost(); calCostPurchaseDeviceTaxInclude(); + digitalSelf("costPurchaseDeviceTaxInclude", "input[name='costPurchaseDeviceTaxInclude']"); }); $("input[name='costPurchaseBuildTaxInclude']").change(function () { calCostInclude(); calIncomeCost(); calCostPurchaseBuildTaxInclude(); + digitalSelf("costPurchaseBuildTaxInclude", "input[name='costPurchaseBuildTaxInclude']"); }); $("input[name='costPurchaseServiceTaxInclude']").change(function () { calCostInclude(); calIncomeCost(); calCostPurchaseServiceTaxInclude(); + digitalSelf("costPurchaseServiceTaxInclude", "input[name='costPurchaseServiceTaxInclude']"); }); $("input[name='costPurchaseOtherTaxInclude']").change(function () { calCostInclude(); calIncomeCost(); calCostPurchaseOtherTaxInclude(); + digitalSelf("costPurchaseOtherTaxInclude", "input[name='costPurchaseOtherTaxInclude']"); }); /*$("input[name='costProjectManageTaxInclude']").change(function () { calCostInclude(); @@ -66,23 +76,28 @@ function calIncomeAndCost() { calIncomeCost(); calCostOtherOtherTaxInclude(); + digitalSelf("costOtherOtherTaxInclude", "input[name='costOtherOtherTaxInclude']"); }); $("input[name='costPurchaseDeviceTaxExclude']").change(function () { calCostExclude(); calIncomeCost(); + digitalSelf("costPurchaseDeviceTaxExclude", "input[name='costPurchaseDeviceTaxExclude']"); }); $("input[name='costPurchaseBuildTaxExclude']").change(function () { calCostExclude(); calIncomeCost(); + digitalSelf("costPurchaseBuildTaxExclude", "input[name='costPurchaseBuildTaxExclude']"); }); $("input[name='costPurchaseServiceTaxExclude']").change(function () { calCostExclude(); calIncomeCost(); + digitalSelf("costPurchaseServiceTaxExclude", "input[name='costPurchaseServiceTaxExclude']"); }); $("input[name='costPurchaseOtherTaxExclude']").change(function () { calCostExclude(); calIncomeCost(); + digitalSelf("costPurchaseOtherTaxExclude", "input[name='costPurchaseOtherTaxExclude']"); }); $("input[name='costProjectManageTaxExclude']").change(function () { calCostExclude(); @@ -93,17 +108,22 @@ function calIncomeAndCost() { calCostInclude(); calIncomeCost(); + digitalSelf("costProjectManageTaxExclude", "input[name='costProjectManageTaxExclude']"); + digitalSelf("costProjectManageTaxInclude", "input[name='costProjectManageTaxInclude']"); }); $("input[name='costOtherOtherTaxExclude']").change(function () { calCostExclude(); calIncomeCost(); + digitalSelf("costOtherOtherTaxExclude", "input[name='costOtherOtherTaxExclude']"); }); $("input[name='costExpropriationTaxExclude']").change(function () { calIncomeCost(); + digitalSelf("costExpropriationTaxExclude", "input[name='costExpropriationTaxExclude']"); }); $("input[name='costCompanyManageTaxExclude']").change(function () { calIncomeCost(); + digitalSelf("costCompanyManageTaxExclude", "input[name='costCompanyManageTaxExclude']"); }); //设备类收入 @@ -421,7 +441,7 @@ function calIncomeCost() { } if ($projectGrossProfit.val()) { - $projectContributionProfit.val(f2(f2Fixed($projectGrossProfit.val()) - f2(costCompanyManageTaxExclude))); + $projectContributionProfit.val(f2Fixed(f2($projectGrossProfit.val()) - f2(costCompanyManageTaxExclude))); $projectContributionProfitRate.val(f2Fixed(f2($projectContributionProfit.val()) * 100 / f2(incomeTotalTaxExclude))) } else { $projectContributionProfit.val(""); diff --git a/src/main/resources/templates/admin/project_estimate_add.ftl b/src/main/resources/templates/admin/project_estimate_add.ftl index 3b26a10..5f8a91a 100644 --- a/src/main/resources/templates/admin/project_estimate_add.ftl +++ b/src/main/resources/templates/admin/project_estimate_add.ftl @@ -113,7 +113,7 @@ <#--
*垫资利息
--> <#--
--> <#-- -<#-- name="advanceInterestAmount" placeholder="单位(元)" min="0.00" max="9999999999.99" step="0.01" maxlength="13"--> +<#-- name="advanceInterestAmount" placeholder="单位(元)" maxlength="16"--> <#-- value="" required />--> <#--
--> <#--
--> @@ -122,7 +122,7 @@ <#--
*垫资峰值
--> <#--
--> <#-- -<#-- name="advancePeakAmount" placeholder="单位(元)" min="0.00" max="9999999999.99" step="0.01" maxlength="13"--> +<#-- name="advancePeakAmount" placeholder="单位(元)" maxlength="16"--> <#-- value="" required />--> <#--
--> <#--
--> @@ -131,7 +131,7 @@
*合同金额
@@ -149,7 +149,7 @@
华智产品金额
+ name="huazhiProductAmount" placeholder="单位(元)" maxlength="16" value="" />
@@ -157,7 +157,7 @@
其他产品金额
+ name="ziguangOtherAmount" placeholder="单位(元)" maxlength="16" value="" />
@@ -199,8 +199,8 @@ 收入 设备类 - - + + - + + - + + - + + / @@ -274,8 +274,8 @@ 成本 采购成本 设备 - - + + - + + - + + - + + - + + / @@ -359,8 +359,8 @@ 其他 - - + + - + + / @@ -395,12 +395,12 @@ 财务费用 资金占用成本 - + 公司管理费用 - + @@ -414,19 +414,19 @@ 项目毛利(元) - + 项目毛利率(%) - + 项目贡献利润(元) - + 项目贡献利润率(%) - + diff --git a/src/main/resources/templates/admin/project_estimate_edit.ftl b/src/main/resources/templates/admin/project_estimate_edit.ftl index 00f5063..f80d8ab 100644 --- a/src/main/resources/templates/admin/project_estimate_edit.ftl +++ b/src/main/resources/templates/admin/project_estimate_edit.ftl @@ -120,7 +120,7 @@ <#--
*垫资利息
--> <#--
--> <#-- -<#-- name="advanceInterestAmount" placeholder="单位(元)" min="0.00" max="9999999999.99" step="0.01" maxlength="13"--> +<#-- name="advanceInterestAmount" placeholder="单位(元)" maxlength="16"--> <#-- value="${Utils.format(project.advanceInterestAmount)}" required />--> <#--
--> <#--
--> @@ -129,7 +129,7 @@ <#--
*垫资峰值
--> <#--
--> <#-- -<#-- name="advancePeakAmount" placeholder="单位(元)" min="0.00" max="9999999999.99" step="0.01" maxlength="13"--> +<#-- name="advancePeakAmount" placeholder="单位(元)" maxlength="16"--> <#-- value="${Utils.format(project.advancePeakAmount)}" required />--> <#--
--> <#--
--> @@ -138,7 +138,7 @@
*合同金额
@@ -156,7 +156,7 @@
<#--*-->华智产品金额
+ name="huazhiProductAmount" placeholder="单位(元)" maxlength="16" value="${Utils.format(project.huazhiProductAmount)}" />
@@ -164,7 +164,7 @@
<#--*-->其他产品金额
+ name="ziguangOtherAmount" placeholder="单位(元)" maxlength="16" value="${Utils.format(project.ziguangOtherAmount)}" />
@@ -206,8 +206,8 @@ 收入 设备类 - - readonly required> + + readonly required> - readonly required> + + readonly required> - readonly required> + + readonly required> - + + / @@ -281,8 +281,8 @@ 成本 采购成本 设备 - - readonly required> + + readonly required> - readonly required> + + readonly required> - readonly required> + + readonly required> - readonly required> + + readonly required> - + + 成本 其他 - - readonly required> + + readonly required> - + + / @@ -401,12 +401,12 @@ 财务费用 资金占用成本 - + 公司管理费用 - + @@ -420,19 +420,19 @@ 项目毛利(元) - + 项目毛利率(%) - + 项目贡献利润(元) - + 项目贡献利润率(%) - +