advert.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. <style>
  12. .color{
  13. color: red;
  14. }
  15. </style>
  16. <div class="row">
  17. <div class="col-sm-12">
  18. <div class="ibox float-e-margins">
  19. <div class="ibox-content">
  20. <div class="row">
  21. <div class="col-sm-5 m-b-xs">
  22. <a class="btn btn-sm btn-primary addhotsearch" href="<?=Url::toRoute(['webconfig/addadvert'])?>"> 新建广告</a>
  23. </div>
  24. </div>
  25. <div class="table-responsive">
  26. <table class="table table-striped">
  27. <thead>
  28. <tr>
  29. <th>ID</th>
  30. <th>图片名称</th>
  31. <!-- <th>所属房子</th>-->
  32. <th>图片</th>
  33. <th>链接地址</th>
  34. <th>轮播顺序</th>
  35. <th>是否显示</th>
  36. <th>操作</th>
  37. </tr>
  38. </thead>
  39. <tbody>
  40. <form id="checkForm" method="post">
  41. <?php if(!empty($datas)):?>
  42. <?php $i=0; foreach($datas as $data):?>
  43. <tr class="hotsearch_<?=$data->id?>">
  44. <td><?php $i++;echo $i;?></td>
  45. <td class="keyword"><?= $data->name?></td>
  46. <!-- <td class="keyword">--><?//= $data->uid?><!--</td>-->
  47. <td><img src="<?=Yii::getAlias('@imgdomain').'/'.$data->imgurl; ?>" style=" width: 50px;"></td>
  48. <td class="keyword"><?= $data->link?></td>
  49. <td class="keyword"><?= $data->orderby?></td>
  50. <td>
  51. <a>
  52. <?php if($data->status==\common\models\advert::ADVERT_STATE_SHOW):?>
  53. <i class="fa fa-check text-navy" data="<?=$data->id?>"></i>
  54. <?php else:?>
  55. <i class="fa fa-close text-danger" data="<?=$data->id?>"></i>
  56. <?php endif;?>
  57. </a>
  58. </td>
  59. <td>
  60. <a href="<?=Url::toRoute(['webconfig/addadvert','id'=>$data->id])?>" class="btn btn-sm btn-primary edit_advert">修改</a>
  61. <a class="btn btn-sm btn-danger del_advert"data="<?= $data->id?>">删除</a>
  62. </td>
  63. </tr>
  64. <?php endforeach;?>
  65. <?php endif?>
  66. <input type="hidden" name="_csrf-backend" value="<?=Yii::$app->request->csrfToken;?>" />
  67. <input type="hidden" value="" name="key" class="shelves-key">
  68. </form>
  69. </tbody>
  70. </table>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. <script>
  77. $('.table-responsive').on('click','.fa',function(){
  78. var advertid = $(this).attr('data');
  79. var text = $(this);
  80. if($(this).hasClass('text-navy')){
  81. var title = '确定将该图片不显示?';
  82. }else{
  83. var title = '确定将该图片显示?';
  84. }
  85. swal({
  86. title: title,
  87. type: "warning",
  88. showCancelButton: true,
  89. confirmButtonColor: "#DD6B55",
  90. confirmButtonText: "确定",
  91. cancelButtonText: "取消",
  92. closeOnConfirm: true,
  93. closeOnCancel: true },
  94. function(isConfirm){
  95. if (isConfirm) {
  96. $.ajax({
  97. url:'<?=Url::toRoute(['webconfig/show']);?>',
  98. type:'POST',
  99. dataType:'json',
  100. data:{id:advertid,'_csrf-backend':'<?=Yii::$app->request->csrfToken;?>'},
  101. success:function(data){
  102. if(data.sign==1){
  103. if(text.hasClass('text-navy')){
  104. text.addClass('text-danger');
  105. text.addClass('fa-close');
  106. text.removeClass('text-navy');
  107. text.removeClass('fa-check');
  108. }else{
  109. text.addClass('text-navy');
  110. text.addClass('fa-check');
  111. text.removeClass('text-danger');
  112. text.removeClass('fa-close');
  113. }
  114. }else{
  115. swal("", data.msg, "error");
  116. }
  117. }
  118. })
  119. }
  120. });
  121. });
  122. $('.table-responsive').on('click','.del_advert',function(){
  123. var id = $(this).attr('data');
  124. var text = $(this);
  125. swal({
  126. title: "确定删除该轮播图?",
  127. type: "warning",
  128. showCancelButton: true,
  129. confirmButtonColor: "#DD6B55",
  130. confirmButtonText: "确定",
  131. cancelButtonText: "取消",
  132. closeOnConfirm: true,
  133. closeOnCancel: true },
  134. function(isConfirm){
  135. if (isConfirm) {
  136. $.ajax({
  137. url:'<?=Url::toRoute(['webconfig/del_advert']);?>',
  138. type:'POST',
  139. dataType:'json',
  140. data:{id:id,'_csrf-backend':'<?=Yii::$app->request->csrfToken;?>'},
  141. success:function(data){
  142. if(data.sign==1){
  143. text.parents('tr').remove();
  144. }else{
  145. swal("", data.msg, "error");
  146. }
  147. }
  148. })
  149. }
  150. });
  151. })
  152. </script>