_form.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. use backend\widgets\ActiveForm;
  3. use backend\widgets\meta\MetaForm;
  4. use common\helpers\Tree;
  5. use yii\helpers\Html;
  6. use common\models\Category;
  7. /* @var $this yii\web\View */
  8. /* @var $model common\models\Category */
  9. /* @var $childCateList [] */
  10. /* @var $form backend\widgets\ActiveForm */
  11. $cssString = "
  12. select[readonly] {
  13. cursor: no-drop;
  14. }
  15. select[readonly] option {
  16. display: none;
  17. }
  18. ";
  19. $this->registerCss($cssString);
  20. ?>
  21. <div class="box box-primary">
  22. <div class="box-body">
  23. <?php $form = ActiveForm::begin(); ?>
  24. <!-- --><? //= $form->field($model, 'pid')->dropDownList(Category::getDropDownList(Category::lists()), ['prompt' => '请选择']) ?>
  25. <?= $form->field($model, 'pid')->dropDownList(Category::getDropDownList(Tree::build(Category::listsByType(0))), ['prompt' => '请选择']) ?>
  26. <?= $form->field($model, 'type')->dropDownList(Category::getTypeEnum(), ['readonly' => true]) ?>
  27. <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
  28. <!-- --><? //= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?>
  29. <?= $form->field($model, 'sort')->textInput() ?>
  30. <?= $form->field($model, 'description')->textarea(['maxlength' => true]) ?>
  31. <!-- --><? //= $form->field($model, 'module')->checkboxList(\common\models\ArticleModule::getTypeEnum()) ?>
  32. <!-- --><? //= $form->boxField($model, 'meta',["collapsed"=>true])->widget(MetaForm::className())->header("SEO"); ?>
  33. <div class="form-group">
  34. <?= Html::submitButton($model->isNewRecord ? '创建' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success btn-block' : 'btn btn-primary btn-block']) ?>
  35. </div>
  36. <?php ActiveForm::end(); ?>
  37. </div>
  38. </div>
  39. <?php
  40. $childCateList = \yii\helpers\Json::htmlEncode($childCateList);
  41. $js = <<<JS
  42. function pidToggle() {
  43. let pid = $('#category-pid').val();
  44. if ($childCateList.indexOf(pid) != -1) {
  45. //产业链
  46. $('#category-type').val(1);
  47. } else {
  48. $('#category-type').val(0);
  49. }
  50. }
  51. $('#category-pid').change(function(e) {
  52. pidToggle();
  53. });
  54. //初始化调用
  55. pidToggle();
  56. JS;
  57. $this->registerJs($js);
  58. ?>