<?php

use backend\widgets\ActiveForm;
use backend\widgets\meta\MetaForm;
use common\helpers\Tree;
use yii\helpers\Html;
use common\models\Category;

/* @var $this yii\web\View */
/* @var $model common\models\Category */
/* @var $childCateList [] */
/* @var $form backend\widgets\ActiveForm */

$cssString = "
 select[readonly] {
        cursor: no-drop;
    }
    select[readonly] option {
        display: none;
    }
";
$this->registerCss($cssString);

?>

<div class="box box-primary">
    <div class="box-body">
        <?php $form = ActiveForm::begin(); ?>

        <!--        --><? //= $form->field($model, 'pid')->dropDownList(Category::getDropDownList(Category::lists()), ['prompt' => '请选择']) ?>
        <?= $form->field($model, 'pid')->dropDownList(Category::getDropDownList(Tree::build(Category::listsByType(0))), ['prompt' => '请选择']) ?>

        <?= $form->field($model, 'type')->dropDownList(Category::getTypeEnum(), ['readonly' => true]) ?>

        <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

        <!--        --><? //= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'sort')->textInput() ?>

        <?= $form->field($model, 'description')->textarea(['maxlength' => true]) ?>

        <!--        --><? //= $form->field($model, 'module')->checkboxList(\common\models\ArticleModule::getTypeEnum()) ?>


        <!--        --><? //= $form->boxField($model, 'meta',["collapsed"=>true])->widget(MetaForm::className())->header("SEO"); ?>

        <div class="form-group">
            <?= Html::submitButton($model->isNewRecord ? '创建' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success  btn-block' : 'btn btn-primary  btn-block']) ?>
        </div>

        <?php ActiveForm::end(); ?>
    </div>
</div>


<?php
$childCateList = \yii\helpers\Json::htmlEncode($childCateList);
$js = <<<JS

    function pidToggle() {
        let pid = $('#category-pid').val();
      if ($childCateList.indexOf(pid) != -1) {
          //产业链
            $('#category-type').val(1);
        } else {
            $('#category-type').val(0);
        }
    }
    
    $('#category-pid').change(function(e) {
        pidToggle();
    });
       
    //初始化调用
    pidToggle();
    
    
JS;
$this->registerJs($js);
?>


