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.
 
 
 

90 lines
2.9 KiB

<?php
use yii\helpers\Url;
use blobt\widgets\Icheck;
use backend\modules\goods\models\ars\Goods;
use linyao\widgets\Select2;
use backend\modules\shop\models\ars\ExpressTemplate;
/* @var $this yii\web\View */
/* @var $model backend\modules\goods\models\ars\Goods */
/* @var $form yii\widgets\ActiveForm */
?>
<?= $form->field($model, 'is_taking')->widget(Icheck::className(), ['items' => Goods::$isTaking, 'type' => 'radio']) ?>
<?= $form->field($model, 'is_express')->widget(Icheck::className(), ['items' => Goods::$isExpress, 'type' => 'radio']) ?>
<fieldset id="isExpress" style="display: <?= $model->is_express == Goods::IS_EXPRESS_NO ? 'none' : 'block' ?>">
<?= $form->field($model, 'express_type')->widget(Icheck::className(), ['items' => Goods::$expressType, 'type' => 'radio']) ?>
<fieldset id="uniformPostage" style="display: <?= $model->express_type == Goods::EXPRESS_TYPE_UNIFORM_POSTAGE ? 'block' : 'none' ?>">
<?= $form->field($model, 'uniform_postage')->textInput() ?>
</fieldset>
<fieldset id="expressTemplate" style="display: <?= $model->express_type == Goods::EXPRESS_TYPE_EXPRESS_TEMPLATE ? 'block' : 'none' ?>">
<?= $form->field($model, 'express_template')->widget(Select2::className(), ["items" => ExpressTemplate::modelColumn()]) ?>
</fieldset>
</fieldset>
<?php
$js =<<<JS
$(document).ready(function(){
if(!$("#goods-uniform_postage").val()){
$("#goods-uniform_postage").val("0.00")
}else{
$("#goods-uniform_postage").val(toFixeds($("#goods-uniform_postage").val(), 2));
}
$("input:radio[name='Goods[is_express]']").on('ifChecked', function(event){
if ($(this).val() === '1') {
$("#isExpress").show();
} else {
$("#isExpress").hide();
}
})
$("input:radio[name='Goods[express_type]']").on('ifChecked', function(event){
if ($(this).val() === '1') {
$("#uniformPostage").show();
$("#expressTemplate").hide();
} else {
$("#expressTemplate").show();
$("#uniformPostage").hide();
}
})
$("#goods-uniform_postage").blur(function(){
if(!$(this).val()){
$(this).val("0.00")
}
if(isNaN($(this).val())){
$(this).val("0.00")
}
if($(this).val().indexOf('-') != -1){
$(this).val("0.00")
}
var basicPrice = $(this).val();
$(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);
?>