<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model common\models\SurveyNew */
/* @var $form yii\widgets\ActiveForm */
/* @var $configModels [] */
/* @var $cengciModels [] */
?>

<div class="box box-success">
    <div class="box-body">
        <?php $form = ActiveForm::begin(['enableClientValidation'=>false]); ?>

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



		<?php
	    //人才层次
        foreach ($cengciModels as $index => $configModel) {

			$value = explode("\r\n",$configModel['extra']);

			$arr = [];
			foreach($value as &$val){
				$val = trim($val);
				$arr[$val] = $val;
			}

            echo $form->field($model, 'id')->checkboxList($arr,[
				'name'=>$configModel['name'],
				'value'=>$model->filter[$configModel['name']]
			])->label($configModel['description']);
        }
        foreach ($configModels as $index => $configModel) {

			$value = explode("\r\n",$configModel['extra']);

			$arr = [];
			foreach($value as &$val){
				$val = trim($val);
				$arr[$val] = $val;
			}

            echo $form->field($model, 'id')->checkboxList($arr,[
				'name'=>$configModel['name'],
				'value'=>$model->filter[$configModel['name']]
			])->label($configModel['description']);
        }

        ?>

        <?= $form->field($model, 'content')->widget(\common\widgets\EditorWidget::className(), $model->isNewRecord ? ['type' => request('editor') ?: config('page_editor_type')] : ['isMarkdown' => $model->markdown]) ?>

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


        <?php ActiveForm::end(); ?>
    </div>
</div>
<?php $this->beginBlock('js') ?>
<script>
    $(document).on('change', '#choose-editor', function () {
        var url = '<?= \yii\helpers\Url::to(['create']) ?>';
        var type = $(this).val();
        url = url.addQueryParams({editor: type});
        location.href = url;
    })
</script>
<?php $this->endBlock() ?>


<?php
$js = <<<JS
    //nav导航切换
    $('#formNavs li').click(function (e) {
        $('#formNavs li').removeClass('active');
        $(this).addClass('active');
    });

    function skuToggle() {
      if ($('input[name="Goods[is_sku]"]:checked').val() == 1) {
            $('#goods-stock').prop('readonly', true).val(0);
            $('#goodsSku').slideDown();
        } else {
            $('#goods-stock').prop('readonly', false);
             $('#goodsSku').slideUp();
        }
    }
    function shareDiyToggle() {
      if ($('input[name="Goods[is_share_diy]"]:checked').val() == 1) {
            $('#goodsShareDiy').slideDown();
        } else {
             $('#goodsShareDiy').slideUp();
        }
    }
    
    $('#goods-is_sku').change(function(e) {
        skuToggle();
    });
    
    $('#goods-is_share_diy').change(function(e) {
        shareDiyToggle();
    });
       
    //初始化调用
    skuToggle();
    shareDiyToggle();
    
    //滚动监听
    $('body').scrollspy({ target: '#formNavs' });
    $('#formNavs').on('activate.bs.scrollspy', function (e) {
        location.hash = $(e.target).find('a').attr('href');
    })
JS;
$this->registerJs($js);
?>

