_index.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. use kartik\grid\GridView;
  3. use yii\helpers\Html;
  4. use yii\helpers\Url;
  5. use yii\widgets\Pjax;
  6. /* @var $goods \common\models\Goods */
  7. /* @var $dataProvider \yii\data\ActiveDataProvider */
  8. ?>
  9. <p>
  10. <?= Html::a(Yii::t('common', 'Create Goods Attr'), 'javascript:;', [
  11. 'url' => Url::to([
  12. '/goods-attr/create',
  13. 'goods_id' => $goods->id,
  14. 'origin' => Yii::$app->request->url
  15. ]),
  16. 'class' => 'btn btn-success js-layer-attr-link',
  17. 'title' => Yii::t('common', 'Create Goods Attr'),
  18. ]) ?>
  19. </p>
  20. <div class="box box-primary">
  21. <div class="box-body">
  22. <?php Pjax::begin(['id' => 'goods-attr-list']) ?>
  23. <?= GridView::widget([
  24. 'dataProvider' => $dataProvider,
  25. 'export' => false,
  26. 'options' => ['id' => 'attr_list'],
  27. 'columns' => [
  28. [
  29. 'class' => 'kartik\grid\CheckboxColumn',
  30. 'name' => 'id',
  31. ],//复选框列
  32. 'name',
  33. 'value',
  34. // 'created_at:datetime',
  35. // 'updated_at:datetime',
  36. [
  37. 'class' => 'backend\widgets\grid\PositionColumn',
  38. 'attribute' => 'sort'
  39. ],
  40. [
  41. 'class' => 'common\helpers\DiyActionColumn',
  42. 'template' => '{update} {delete}',
  43. 'buttons' => [
  44. 'update' => function ($url, $model, $key) {
  45. return Html::a(Yii::t('yii', 'Update'), 'javascript:;', [
  46. 'url' => Url::to(['/goods-attr/update', 'id' => $model->id]),
  47. 'class' => 'btn btn-success btn-xs js-layer-attr-link',
  48. 'title' => Yii::t('common', 'Update Goods Attr'),
  49. ]);
  50. },
  51. 'delete' => function ($url, $model, $key) {
  52. return Html::a('删除', 'javascript:;', [
  53. 'url' => Url::to(['/goods-attr/delete', 'id' => $model->id]),
  54. 'class' => 'btn btn-success btn-xs js-attr-del',
  55. 'title' => Yii::t('common', '删除商品属性'),
  56. ]);
  57. },
  58. ],
  59. ],
  60. ],
  61. ]); ?>
  62. <?php Pjax::end() ?>
  63. </div>
  64. </div>
  65. <?php
  66. $js = <<<JS
  67. //layer弹窗
  68. $(document).on('click', '.js-layer-attr-link',function() {
  69. let _this = $(this);
  70. layer.open({
  71. type: 2,
  72. title: _this.attr('title'),
  73. shadeClose: true,
  74. shade: 0.8,
  75. area: ['600px', '450px'],
  76. content: _this.attr('url'),
  77. end: function() {
  78. //关闭弹窗,刷新数据
  79. attrPjax();
  80. }
  81. });
  82. });
  83. $(document).on('click', '.js-attr-del', function(e) {
  84. e.preventDefault();
  85. let link = $(this);
  86. $.modal.confirm('确定删除“' + link.parents('tr').find('td:eq(1)').text() + '”吗?', () => {
  87. //表单提交
  88. $.post(link.attr('url'), {}, (res) => {
  89. if (res.errcode == 0) {
  90. $.modal.notify(res.errmsg, 'success', () => {
  91. //移除行
  92. // link.parents('tr').slideUp().remove();
  93. attrPjax();
  94. });
  95. } else {
  96. $.modal.error(res.errmsg);
  97. }
  98. });
  99. });
  100. });
  101. function attrPjax() {
  102. location.hash = '#attr';
  103. $.pjax({
  104. url: location.href,
  105. container: '#goods-attr-list',
  106. timeout: 0
  107. });
  108. }
  109. JS;
  110. $this->registerJs($js);
  111. ?>