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;
= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
= Html::a('返回', ['index'], ['class' => '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){