You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

113 lines
2.9 KiB

<?php
use blobt\widgets\Icheck;
use backend\models\ars\ExpressTemplate;
/* @var $this yii\web\View */
/* @var $model backend\models\ars\ExpressTemplate */
/* @var $form yii\widgets\ActiveForm */
?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'calculation')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculation, 'type' => "radio"]) ?>
<?= $form->field($model, 'basic_amount')->textInput() ?>
<?= $form->field($model, 'basic_price')->textInput() ?>
<?= $form->field($model, 'extra_amount')->textInput() ?>
<?= $form->field($model, 'extra_price')->textInput() ?>
<?php
$js=<<<JS
const formList = [//切换时,class对应的标题
{
"field-expresstemplate-basic_amount":"基本重量(KG)",
"field-expresstemplate-basic_price":"基本运费(元)",
"field-expresstemplate-extra_amount":"续重重量(KG)",
"field-expresstemplate-extra_price":"续重运费(元)"
},
{
"field-expresstemplate-basic_amount":"基本数量(件)",
"field-expresstemplate-basic_price":"基本运费(元)",
"field-expresstemplate-extra_amount":"续重数量(件)",
"field-expresstemplate-extra_price":"续重运费(元)"
}
]
const udfVal = [//初始值
[0.1,"0.00"],
[1,"0.00"]
]
var calType = 1;//初始的计算方式0:计重 1:计件
function changeCalType(type){//当切换计算方式
$.each(formList[type],function(index,value){ //更改文字标题
$("." + index).children("label").html(value)
});
$(".form-control").eq(1).val(udfVal[type][0])//重置初始值
$(".form-control").eq(2).val(udfVal[type][1])
calType = type;
}
$(document).ready(function(){
$(".form-control").eq(1).blur(function(){
if (calType == 0) {
if($(this).val() < 0.1){
$(this).val(0.1)
}
var basicAmount = $(this).val();
$(this).val(Math.floor(basicAmount * 10) / 10);
} else{
if($(this).val() < 1){
$(this).val(1)
}
var basicAmount = $(this).val();
$(this).val(Math.floor(basicAmount * 1) / 1);
}
})
$(".form-control").eq(2).blur(function(){
if($(this).val() < 0){
$(this).val("0.00")
}
var basicPrice = $(this).val();
$(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/));
})
$(".form-control").eq(3).blur(function(){
if (calType == 0) {
if($(this).val() < 0){
$(this).val(0)
}
var basicAmount = $(this).val();
$(this).val(Math.floor(basicAmount * 10) / 10);
} else{
if($(this).val() < 0){
$(this).val(0)
}
var basicAmount = $(this).val();
$(this).val(Math.floor(basicAmount * 1) / 1);
}
})
$(".form-control").eq(4).blur(function(){
if($(this).val() < 0){
$(this).val("0.00")
}
var basicPrice = $(this).val();
$(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/));
})
$("input:radio[name='ExpressTemplate[calculation]']").on('ifChecked', function(event){
changeCalType($(this).val()-1)
})
changeCalType(calType)
})
JS;
$this->registerJs($js)
?>