index.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. use common\helpers\Html;
  3. $cityId = $areaId = $townshipId = $villageId = -1;
  4. $col = 12;
  5. if ($template == 'short') {
  6. $col = $level <= 3 ? 12 / $level : 4;
  7. }
  8. $level >= 2 && $cityId = Html::getInputId($model, $two['name']);
  9. $level >= 3 && $areaId = Html::getInputId($model, $three['name']);
  10. $level >= 4 &&$townshipId = Html::getInputId($model, $four['name']);
  11. $level >= 5 &&$villageId = Html::getInputId($model, $five['name']);
  12. ?>
  13. <div class="row">
  14. <div class="col-<?= $col; ?>">
  15. <?php if ($level >= 1){ ?>
  16. <?= $form->field($model, $one['name'])->dropDownList($one['list'], [
  17. 'prompt' => $one['title'],
  18. 'onchange' => "widgetProvinces" . $random . "(this, 1, '$cityId', '$areaId', '$townshipId', '$villageId')",
  19. ]); ?>
  20. <?php }?>
  21. </div>
  22. <div class="col-<?= $col; ?>">
  23. <?php if ($level >= 2){ ?>
  24. <?= $form->field($model, $two['name'])->dropDownList($two['list'], [
  25. 'prompt' => $two['title'],
  26. 'onchange' => "widgetProvinces" . $random . "(this, 2, '$cityId', '$areaId', '$townshipId', '$villageId')",
  27. ]); ?>
  28. <?php }?>
  29. </div>
  30. <div class="col-<?= $col; ?>">
  31. <?php if ($level >= 3){ ?>
  32. <?= $form->field($model, $three['name'])->dropDownList($three['list'], [
  33. 'prompt' => $three['title'],
  34. 'onchange' => "widgetProvinces" . $random . "(this, 3, '$cityId', '$areaId', '$townshipId', '$villageId')",
  35. ]) ?>
  36. <?php }?>
  37. </div>
  38. <div class="col-<?= $col; ?>">
  39. <?php if ($level >= 4){ ?>
  40. <?= $form->field($model, $four['name'])->dropDownList($four['list'], [
  41. 'prompt' => $four['title'],
  42. 'onchange' => "widgetProvinces" . $random . "(this, 4, '$cityId', '$areaId', '$townshipId', '$villageId')",
  43. ]) ?>
  44. <?php }?>
  45. </div>
  46. <div class="col-<?= $col; ?>">
  47. <?php if ($level >= 5){ ?>
  48. <?= $form->field($model, $five['name'])->dropDownList($five['list'], [
  49. 'prompt' => $five['title'],
  50. 'onchange' => "widgetProvinces" . $random . "(this, 5, '$cityId', '$areaId', '$townshipId', '$villageId')",
  51. ]) ?>
  52. <?php }?>
  53. </div>
  54. </div>
  55. <script>
  56. function widgetProvinces<?= $random ?>(obj, type_id, cityId, areaId, townshipId, villageId) {
  57. switch (type_id) {
  58. case 1 :
  59. $(".form-group.field-" + areaId).hide();
  60. $(".form-group.field-" + townshipId).hide();
  61. $(".form-group.field-" + villageId).hide();
  62. break;
  63. case 2 :
  64. $(".form-group.field-" + areaId).hide();
  65. $(".form-group.field-" + townshipId).hide();
  66. $(".form-group.field-" + villageId).hide();
  67. break;
  68. case 3 :
  69. $(".form-group.field-" + townshipId).hide();
  70. $(".form-group.field-" + villageId).hide();
  71. break;
  72. case 4 :
  73. $(".form-group.field-" + villageId).hide();
  74. break;
  75. }
  76. var pid = $(obj).val();
  77. $.ajax({
  78. type: "get",
  79. url: "<?= $url; ?>",
  80. dataType: "json",
  81. data: {type_id: type_id, pid: pid},
  82. success: function (data) {
  83. switch (type_id) {
  84. case 1 :
  85. $("select#" + cityId + "").html(data);
  86. break;
  87. case 2 :
  88. $(".form-group.field-" + areaId).show();
  89. $("select#" + areaId + "").html(data);
  90. break;
  91. case 3 :
  92. $(".form-group.field-" + townshipId).show();
  93. $("select#" + townshipId + "").html(data);
  94. break;
  95. case 4 :
  96. $(".form-group.field-" + villageId).show();
  97. $("select#" + villageId + "").html(data);
  98. break;
  99. }
  100. }
  101. });
  102. }
  103. </script>
粤ICP备19079148号