index.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/3/17 0017
  6. * Time: 上午 10:52
  7. */
  8. use yii\helpers\Url;
  9. use yii\widgets\LinkPager;
  10. ?>
  11. <div class="panel panel-default">
  12. <div class="panel-heading">
  13. <h3 class="panel-title">分类</h3>
  14. </div>
  15. <div class="panel-body">
  16. <a class="btn btn-primary btn-sm " href="<?=Url::toRoute(['matertype/add'])?>">创建分类</a>
  17. </div>
  18. <table class="table">
  19. <tr>
  20. <th>名称</th>
  21. <th>排序</th>
  22. <th>添加时间</th>
  23. <th>状态</th>
  24. <th>操作</th>
  25. </tr>
  26. <?php foreach ($models as $vo):?>
  27. <tr >
  28. <td><?=$vo->name;?></td>
  29. <td><?=$vo->sort;?></td>
  30. <td><?=date('Y-m-d H:i',$vo->c_time);?></td>
  31. <td>
  32. <div class="switch">
  33. <div class="onoffswitch">
  34. <input type="checkbox" data-id="<?=$vo->id?>" name="MaterType[status]" <?= $vo->status==\common\models\MaterType::STATUS_YES?"checked":"" ?> class="onoffswitch-checkbox" id="example<?=$vo->id?>">
  35. <label class="onoffswitch-label" for="example<?=$vo->id?>">
  36. <span class="onoffswitch-inner"></span>
  37. <span class="onoffswitch-switch"></span>
  38. </label>
  39. </div>
  40. </div>
  41. </td>
  42. <td>
  43. <a class="btn btn-info btn-sm " href="<?=Url::toRoute(['matertype/add','id'=>$vo->id])?>" ><i class="fa fa-paste"></i> 编辑</a>
  44. </td>
  45. </tr>
  46. <?php endforeach;?>
  47. </table>
  48. </div>
  49. <?=LinkPager::widget(['pagination' => $pages]); ?>
  50. <script type="text/javascript">
  51. toastr.options={ "closeButton": true};
  52. $('.onoffswitch-checkbox').on('click',function(){
  53. var id =$(this).attr('data-id');
  54. $.ajax({
  55. type:"POST",
  56. data:{id:id,'<?=Yii::$app->request->csrfParam;?>':"<?=Yii::$app->request->csrfToken;?>"},
  57. dataType:"JSON",
  58. url:"<?=Url::toRoute(['matertype/update-status']);?>",
  59. success:function(data){
  60. if(data.sign == 1)
  61. {
  62. toastr.success("", data.msg);
  63. }else{
  64. toastr.error("", data.msg);
  65. }
  66. }
  67. })
  68. })
  69. </script>