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.

112 lines
2.9 KiB

  1. <?php
  2. use blobt\widgets\Icheck;
  3. use backend\models\ars\ExpressTemplate;
  4. /* @var $this yii\web\View */
  5. /* @var $model backend\models\ars\ExpressTemplate */
  6. /* @var $form yii\widgets\ActiveForm */
  7. ?>
  8. <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
  9. <?= $form->field($model, 'calculation')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculation, 'type' => "radio"]) ?>
  10. <?= $form->field($model, 'basic_amount')->textInput() ?>
  11. <?= $form->field($model, 'basic_price')->textInput() ?>
  12. <?= $form->field($model, 'extra_amount')->textInput() ?>
  13. <?= $form->field($model, 'extra_price')->textInput() ?>
  14. <?php
  15. $js=<<<JS
  16. const formList = [//切换时,class对应的标题
  17. {
  18. "field-expresstemplate-basic_amount":"基本重量(KG)",
  19. "field-expresstemplate-basic_price":"基本运费(元)",
  20. "field-expresstemplate-extra_amount":"续重重量(KG)",
  21. "field-expresstemplate-extra_price":"续重运费(元)"
  22. },
  23. {
  24. "field-expresstemplate-basic_amount":"基本数量(件)",
  25. "field-expresstemplate-basic_price":"基本运费(元)",
  26. "field-expresstemplate-extra_amount":"续重数量(件)",
  27. "field-expresstemplate-extra_price":"续重运费(元)"
  28. }
  29. ]
  30. const udfVal = [//初始值
  31. [0.1,"0.00"],
  32. [1,"0.00"]
  33. ]
  34. var calType = 1;//初始的计算方式0:计重 1:计件
  35. function changeCalType(type){//当切换计算方式
  36. $.each(formList[type],function(index,value){ //更改文字标题
  37. $("." + index).children("label").html(value)
  38. });
  39. $(".form-control").eq(1).val(udfVal[type][0])//重置初始值
  40. $(".form-control").eq(2).val(udfVal[type][1])
  41. calType = type;
  42. }
  43. $(document).ready(function(){
  44. $(".form-control").eq(1).blur(function(){
  45. if (calType == 0) {
  46. if($(this).val() < 0.1){
  47. $(this).val(0.1)
  48. }
  49. var basicAmount = $(this).val();
  50. $(this).val(Math.floor(basicAmount * 10) / 10);
  51. } else{
  52. if($(this).val() < 1){
  53. $(this).val(1)
  54. }
  55. var basicAmount = $(this).val();
  56. $(this).val(Math.floor(basicAmount * 1) / 1);
  57. }
  58. })
  59. $(".form-control").eq(2).blur(function(){
  60. if($(this).val() < 0){
  61. $(this).val("0.00")
  62. }
  63. var basicPrice = $(this).val();
  64. $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/));
  65. })
  66. $(".form-control").eq(3).blur(function(){
  67. if (calType == 0) {
  68. if($(this).val() < 0){
  69. $(this).val(0)
  70. }
  71. var basicAmount = $(this).val();
  72. $(this).val(Math.floor(basicAmount * 10) / 10);
  73. } else{
  74. if($(this).val() < 0){
  75. $(this).val(0)
  76. }
  77. var basicAmount = $(this).val();
  78. $(this).val(Math.floor(basicAmount * 1) / 1);
  79. }
  80. })
  81. $(".form-control").eq(4).blur(function(){
  82. if($(this).val() < 0){
  83. $(this).val("0.00")
  84. }
  85. var basicPrice = $(this).val();
  86. $(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/));
  87. })
  88. $("input:radio[name='ExpressTemplate[calculation]']").on('ifChecked', function(event){
  89. changeCalType($(this).val()-1)
  90. })
  91. changeCalType(calType)
  92. })
  93. JS;
  94. $this->registerJs($js)
  95. ?>