From 290addcc6f30bd6609398e06cf43f1f29c67f29f Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 16:29:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E9=87=91=E9=A2=9D=E5=AD=97?= =?UTF-8?q?=E6=AE=B5js=E8=A1=A8=E5=8D=95=E8=A7=84=E5=88=99=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/goods/views/goods/express.php | 22 ++++++++- backend/modules/goods/views/goods/goods.php | 48 ++++++++++++++++++- .../express-template/express_area_form.php | 29 +++++++++-- 3 files changed, 92 insertions(+), 7 deletions(-) diff --git a/backend/modules/goods/views/goods/express.php b/backend/modules/goods/views/goods/express.php index c97839e..5900968 100755 --- a/backend/modules/goods/views/goods/express.php +++ b/backend/modules/goods/views/goods/express.php @@ -52,8 +52,28 @@ use backend\modules\shop\models\ars\ExpressTemplate; $(this).val("0.00") } var basicPrice = $(this).val(); - $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); + $(this).val(toFixeds($(this).val(), 2)); }) + //金额补全 + function toFixeds(val, pre) { + const num = parseFloat(val); + // eslint-disable-next-line no-restricted-globals + if (isNaN(num)) { + return false; + } + const p = 10 ** pre; + const value = num * p; + let f = (Math.round(value) / p).toString(); + let rs = f.indexOf('.'); + if (rs < 0) { + rs = f.length; + f += '.'; + } + while (f.length <= rs + pre) { + f += '0'; + } + return f; + } JS; $this->registerJs($js); diff --git a/backend/modules/goods/views/goods/goods.php b/backend/modules/goods/views/goods/goods.php index c53b7ea..1f9bf09 100755 --- a/backend/modules/goods/views/goods/goods.php +++ b/backend/modules/goods/views/goods/goods.php @@ -61,4 +61,50 @@ use backend\modules\goods\models\ars\Goods;
'btn btn-success']) ?> 'btn btn-info']) ?> -
\ No newline at end of file + +registerJs($js); + +?> \ No newline at end of file diff --git a/backend/modules/shop/views/express-template/express_area_form.php b/backend/modules/shop/views/express-template/express_area_form.php index 74b97d9..d014ccf 100755 --- a/backend/modules/shop/views/express-template/express_area_form.php +++ b/backend/modules/shop/views/express-template/express_area_form.php @@ -86,6 +86,26 @@ function changeCalType(type){//当切换计算方式 } calType = type; } +//金额补全 +function toFixeds(val, pre) { + const num = parseFloat(val); + // eslint-disable-next-line no-restricted-globals + if (isNaN(num)) { + return false; + } + const p = 10 ** pre; + const value = num * p; + let f = (Math.round(value) / p).toString(); + let rs = f.indexOf('.'); + if (rs < 0) { + rs = f.length; + f += '.'; + } + while (f.length <= rs + pre) { + f += '0'; + } + return f; +} $(document).ready(function(){ $("#expressarea-basic_count").blur(function(){ if(isNaN($(this).val())){ @@ -96,8 +116,7 @@ $(document).ready(function(){ $(this).val(1) } var basiccount = $(this).val(); - // $(this).val(Math.floor(basiccount * 10) / 10); - $(this).val(basiccount.toString().match(/^\d+(?:\.\d{0,1})?/)); + $(this).val(toFixeds($(this).val(), 1)); } else{ if($(this).val() < 1){ $(this).val(1) @@ -114,7 +133,7 @@ $(document).ready(function(){ $(this).val("0.00") } var basicPrice = $(this).val(); - $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); + $(this).val(toFixeds($(this).val(), 2)); }) $("#expressarea-extra_count").blur(function(){ if(isNaN($(this).val())){ @@ -125,7 +144,7 @@ $(document).ready(function(){ $(this).val(0) } var basiccount = $(this).val(); - $(this).val(Math.floor(basiccount * 10) / 10); + $(this).val(toFixeds($(this).val(), 1)); } else{ if($(this).val() < 0){ $(this).val(0) @@ -142,7 +161,7 @@ $(document).ready(function(){ $(this).val("0.00") } var basicPrice = $(this).val(); - $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/)); + $(this).val(toFixeds($(this).val(), 2)); }) $("input:radio[name='ExpressArea[calculation_type]']").on('ifChecked', function(event){