_form.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. use backend\widgets\ActiveForm;
  3. use backend\widgets\meta\MetaForm;
  4. use common\behaviors\TagBehavior;
  5. use common\widgets\tag\TagsInput;
  6. use yii\helpers\Html;
  7. use common\models\Category;
  8. use common\helpers\Tree;
  9. use common\modules\attachment\widgets\SingleWidget;
  10. /* @var $this yii\web\View */
  11. /* @var $model common\models\Article */
  12. /* @var $moduleModel \common\models\article\Base */
  13. /* @var $form backend\widgets\ActiveForm */
  14. ?>
  15. <?php $form = ActiveForm::begin([
  16. 'enableClientValidation' => false,
  17. 'enableAjaxValidation' => true
  18. ]); ?>
  19. <div class="nav-tabs-custom">
  20. <ul class="nav nav-tabs">
  21. <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">基础信息</a></li>
  22. <li><a href="#tab_2" data-toggle="tab" aria-expanded="true">扩展信息</a></li>
  23. </ul>
  24. <div class="tab-content">
  25. <div class="tab-pane active" id="tab_1">
  26. <?= $form->field($model, 'category_id')->dropDownList(Category::getDropDownList(Tree::build(Category::listsByType(0)))) ?>
  27. <?= $form->field($model, 'chain')->checkboxList([]) ?>
  28. <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
  29. <!-- --><? //= $form->field($model, 'description')->textarea()?>
  30. <?php foreach ($moduleModel->formAttributes() as $attribute): ?>
  31. <?= $form->field($model, $attribute)->label($moduleModel->getAttributeLabel($attribute))->widget(\common\widgets\dynamicInput\DynamicInputWidget::className(), ['type' => $moduleModel->getAttributeType($attribute), 'data' => $moduleModel->getAttributeItems($attribute), 'options' => $moduleModel->getAttributeOptions($attribute)]) ?>
  32. <?php endforeach; ?>
  33. <?= $form->field($model, 'city')->textInput(['maxlength' => true]) ?>
  34. <?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
  35. <?= $form->field($model, 'tel')->textInput(['maxlength' => true]) ?>
  36. <!-- --><? //= $form->boxField($model, 'meta', ["collapsed" => true])->widget(MetaForm::className())->header("SEO"); ?>
  37. <?= $form->field($model, 'sort')->textInput(['maxlength' => true]) ?>
  38. </div>
  39. <div class="tab-pane" id="tab_2">
  40. <?= $form->field($model, 'published_at')->widget(
  41. \kartik\datetime\DateTimePicker::className(),
  42. [
  43. 'type' => 1,
  44. 'options' => [
  45. 'value' => !empty($model->published_at) ? date('Y-m-d H:i:s', $model->published_at) : ''
  46. ],
  47. 'pluginOptions' => ['autoclose' => true]
  48. ]
  49. ) ?>
  50. <?= $form->field($model, 'cover')->widget(SingleWidget::className()) ?>
  51. <!-- --><? //= $form->field($model, 'commentEnabled')->checkbox(['label' => '开启评论']) ?>
  52. <?= $form->field($model, 'is_top')->checkbox() ?>
  53. <!-- --><? //= $form->field($model, 'is_hot')->checkbox() ?>
  54. <!-- --><? //= $form->field($model, 'is_best')->checkbox() ?>
  55. <?= $form->field($model, 'status')->checkbox() ?>
  56. <?= $form->field($model, 'view')->textInput() ?>
  57. <?= $form->field($model, TagBehavior::$formName)->label(TagBehavior::$formLable)->widget(TagsInput::className()) ?>
  58. <!-- --><? //= $form->field($model, 'source')->textInput() ?>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="form-group form-submit">
  63. <?= Html::submitButton($model->isNewRecord ? '保存' : '更新', ['class' => 'btn bg-maroon btn-flat btn-block']) ?>
  64. </div>
  65. <?php ActiveForm::end(); ?>
  66. <?php
  67. $chain = \yii\helpers\Json::htmlEncode($model->chain);
  68. $js = <<<JS
  69. function cidToggle() {
  70. $.get('/admin/category/chain', {id: $('#article-category_id').val()}, (res) => {
  71. let html = '';
  72. res.data.forEach((item, index) => {
  73. html += '<label>';
  74. if ($chain && $chain.indexOf(item) != -1) {
  75. html += '<input type="checkbox" name="Article[chain][]" checked="checked" value="'+item+'">';
  76. } else {
  77. html += '<input type="checkbox" name="Article[chain][]" value="'+item+'">';
  78. }
  79. html += '<span style="margin-right: 10px">'+item+'</span>';
  80. html += '</label>';
  81. })
  82. $('#article-chain').html(html);
  83. });
  84. }
  85. $('#article-category_id').change(function(e) {
  86. cidToggle();
  87. });
  88. //初始化调用
  89. cidToggle();
  90. JS;
  91. $this->registerJs($js);
  92. ?>