index.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. {extend name="common/common2" /}
  2. {block name="main"}
  3. <style>
  4. .ibox .open > .dropdown-menu{
  5. left: 0;
  6. right: auto;
  7. width: 80px !important;
  8. }
  9. </style>
  10. <div class="ibox">
  11. <div class="ibox-content">
  12. <div class="row">
  13. <div class="col-xs-3">
  14. <div class="btn-group dropdown">
  15. <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  16. 新增文章 <span class="caret"></span>
  17. </button>
  18. <ul class="dropdown-menu" role="menu">
  19. <li><a url="{:url('add',['type'=>1])}" href="javascript:;" data-title="PDF" onclick="layer_open(this,1)">PDF</a></li>
  20. <li><a url="{:url('add',['type'=>2])}" href="javascript:;" data-title="文章" onclick="layer_open(this,1)">文章</a></li>
  21. <li><a url="{:url('add',['type'=>3])}" href="javascript:;" data-title="视频" onclick="layer_open(this,1)">视频</a></li>
  22. <li><a url="{:url('add',['type'=>4])}" href="javascript:;" data-title="音频" onclick="layer_open(this,1)">音频</a></li>
  23. </ul>
  24. </div>
  25. <a href="javascript:;" onclick="batchSorts()" class="btn btn-sm btn-warning">保存排序</a>
  26. </div>
  27. <div class="col-xs-9" style="text-align: right;">
  28. <form class="form-inline" id="form-search" action="{:url('index')}">
  29. <div class="input-group">
  30. <input type="text" class="form-control" name="title" placeholder="名称">
  31. </div>
  32. <div class="input-group">
  33. <select name="enable" class="form-control">
  34. <option value="">选择状态</option>
  35. <option value="0">禁用</option>
  36. <option value="1">正常</option>
  37. </select>
  38. </div>
  39. <div class="input-group">
  40. <select name="cate_id" class="form-control">
  41. <option value="">选择分类</option>
  42. {foreach $cate as $k=>$v}
  43. <option value="{$v['id']}">{$v['title']}</option>
  44. {/foreach}
  45. </select>
  46. </div>
  47. <div class="input-group">
  48. <span class="input-group-btn">
  49. <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
  50. </span> &nbsp;
  51. <span class="input-group-btn">
  52. <button class="btn-sm btn-warning" type="button" id="search-clear"><i class="fa fa-undo"></i></button>
  53. </span>
  54. </div>
  55. </form>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="ibox-content">
  60. <div class="jqGrid_wrapper">
  61. <table id="table" style="border-collapse: collapse"></table>
  62. <div id="pager"></div>
  63. </div>
  64. </div>
  65. </div>
  66. {/block}
  67. {block name="script"}
  68. <script>
  69. $(function () {
  70. $(window).bind("resize",function(){
  71. var width=$(".jqGrid_wrapper").width();
  72. $("#table").setGridWidth(width);
  73. });
  74. $.jgrid.defaults.styleUI="Bootstrap";
  75. $("#table").jqGrid({
  76. url:"{:url('index')}",
  77. datatype: "json",
  78. colModel:[
  79. {label:'ID',name:'id',index:'id', width:30,sortable: false},
  80. {label:'标题',name:'title',index:'title',width:100,editable: false,sortable: false},
  81. {label:'描述',name:'description',index:'description',width:80,sortable: true},
  82. {label:'分类',name:'cate_name',index:'cate_name',width:40,sortable: true},
  83. {label:'排序',name:'sort',index:'sort',width:40,sortable: true,formatter: function (a, b, c) {
  84. return '<input type="number" data-url="{:url('changeSort')}" class="form-control input-sm usersorts" data-id="'+c.id+'" data-old="'+a+'" value="'+a+'" />';
  85. }},
  86. {label:'状态',name:'enable',index:'enable',width:40,editable: false,sortable: false,formatter:function (a,b,c){
  87. if(a == 0){
  88. var url = "{:url('changeField',[],'')}/fn/enable/fv/1/id/"+c.id;
  89. return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-danger" title="禁用">禁用</span></a>';
  90. } else{
  91. var url = "{:url('changeField',[],'')}/fn/enable/fv/0/id/"+c.id;
  92. return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-primary" title="正常">正常</span></a>';
  93. }
  94. }},
  95. {label:'操作',width:50,sortable: false,formatter: function (a, b, c) {
  96. var editurl = "{:url('add',[],'')}/id/"+c.id;
  97. var delurl = "{:url('del',[],'')}/id/"+c.id;
  98. var btn = '<a url="'+editurl+'" href="javascript:;" data-title="编辑" onclick="layer_open(this,1)"><span class="label label-primary" title="编辑">编辑</span></a>&nbsp;';
  99. btn += '<a {if !btnAuth(session("user_auth.id"),"Article/del")} style="display:none" {/if} href="'+delurl+'" class="confirm ajax-get" data-confirm="确定要删除此记录吗?" data-table="1"><span class="label label-danger" title="删除">删除</span></a>';
  100. return btn;
  101. }},
  102. ],
  103. rowNum:10,
  104. rowList:[10,20,30,50,100],
  105. pager: '#pager',
  106. sortname: 'sort',
  107. viewrecords: true,
  108. autowidth:true,
  109. mtype: 'post',
  110. height: 'auto',
  111. emptyrecords: "暂无数据",
  112. sortorder: "asc",
  113. caption:"{$m_name}",
  114. loadComplete: function (xhr) {
  115. if(xhr.code==0){
  116. layer.msg(xhr.msg);
  117. return false;
  118. }
  119. },
  120. });
  121. });
  122. function batchSorts() {
  123. let data = [];
  124. $('.usersorts').each(function(){
  125. data.push({
  126. id: $(this).attr('data-id'),
  127. sort: $(this).val(),
  128. })
  129. });
  130. let url = "{:url('Article/batchSort')}";
  131. $.post(url,{data:JSON.stringify(data)},function (res) {
  132. if(res.code == 1){
  133. updateAlert('操作成功','alert-success');
  134. setTimeout(function(){
  135. $('#top-alert').find('button').click();
  136. },1500);
  137. $("#table").trigger("reloadGrid");
  138. }else{
  139. updateAlert(data.msg,'alert-danger');
  140. setTimeout(function(){
  141. $('#top-alert').find('button').click();
  142. },1500);
  143. }
  144. });
  145. }
  146. </script>
  147. {/block}