index.html 6.0 KB

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