index.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. use yii\grid\GridView;
  3. use yii\helpers\Html;
  4. /* @var $this yii\web\View */
  5. /* @var $dataProvider yii\data\ActiveDataProvider */
  6. $this->title = '分类';
  7. $this->params['breadcrumbs'][] = $this->title;
  8. ?>
  9. <?php $this->beginBlock('content-header') ?>
  10. <?= $this->title . ' ' . Html::a('新建分类', ['create'], ['class' => 'btn btn-primary ']) ?>
  11. <?php $this->endBlock() ?>
  12. <div class="box box-primary">
  13. <div class="box-body">
  14. <?= \backend\widgets\grid\TreeGrid::widget([
  15. 'dataProvider' => $dataProvider,
  16. 'keyColumnName' => 'id',
  17. 'parentColumnName' => 'pid',
  18. 'parentRootValue' => 0, //first parentId value
  19. 'pluginOptions' => [
  20. 'initialState' => 'expanded',
  21. ],
  22. 'columns' => [
  23. 'title',
  24. 'id',
  25. [
  26. 'attribute' => 'type',
  27. 'value' => function ($model) {
  28. return $model->getTypeEnum()[$model->type];
  29. }
  30. ],
  31. // 'slug',
  32. // 'article',
  33. [
  34. 'attribute' => 'module',
  35. 'value' => function ($model) {
  36. return $model->renderModule();
  37. }
  38. ],
  39. [
  40. 'class' => 'backend\widgets\grid\PositionColumn',
  41. 'attribute' => 'sort'
  42. ],
  43. [
  44. 'class' => 'backend\widgets\grid\SwitcherColumn',
  45. 'attribute' => 'status'
  46. ],
  47. [
  48. 'class' => 'yii\grid\ActionColumn',
  49. 'template' => '{create} {view} {update} {delete}',
  50. 'buttons' => [
  51. 'create' => function ($url, $model, $key) {
  52. //一级分类添加子分类
  53. if ($model->type == 0 and $model->pid == 0) {
  54. return Html::a('<i class="fa fa-plus"></i>', ['create', 'id' => $model->id], ['class' => 'btn btn-xs btn-default', 'data-toggle' => 'tooltip', 'title' => '添加子分类']);
  55. }
  56. //二级分类添加产业链
  57. if ($model->type == 0 and $model->pid != 0) {
  58. return Html::a('<i class="fa fa-plus"></i>', ['create', 'id' => $model->id], ['class' => 'btn btn-xs btn-default', 'data-toggle' => 'tooltip', 'title' => '添加产业链']);
  59. }
  60. }
  61. ]
  62. ],
  63. ],
  64. ]); ?>
  65. </div>
  66. </div>