index.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>layui</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
  10. <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all"/>
  11. <link rel="stylesheet" href="__CSS__/admin.css" media="all">
  12. <style type="text/css">
  13. /* tooltip */
  14. #tooltip {
  15. position: absolute;
  16. border: 1px solid #ccc;
  17. background: #333;
  18. padding: 2px;
  19. display: none;
  20. color: #fff;
  21. }
  22. </style>
  23. </head>
  24. <body style="padding:10px;">
  25. <div class="tplay-body-div">
  26. <div class="layui-tab">
  27. <ul class="layui-tab-title">
  28. <li class="layui-this">配置项</li>
  29. <li><a href="{:url('publish',['pid'=>$Request.param.pid])}" class="a_menu">新增</a>
  30. </ul>
  31. </div>
  32. <form class="layui-form serch" action="{:url('index')}" method="post">
  33. <div class="layui-form-item" style="float: left;">
  34. <div class="layui-input-inline">
  35. <input type="text" name="keywords" lay-verify="title" autocomplete="off" placeholder="请输入名称"
  36. class="layui-input layui-btn-sm">
  37. </div>
  38. <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
  39. </div>
  40. </form>
  41. <script type="text/html" id="toolbarDemo">
  42. <div class="layui-btn-container">
  43. <button class="layui-btn layui-btn-sm" lay-submit lay-filter="admin">排序</button>
  44. <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="deletes">批量删除</button>
  45. </div>
  46. </script>
  47. <script type="text/html" id="barDemo">
  48. <div class="layui-btn-group">
  49. <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon"
  50. style="margin-right: 0;"></i></a>
  51. <a class="layui-btn layui-btn-xs delete" lay-event="del"><i class="layui-icon"
  52. style="margin-right: 0;"></i></a>
  53. </div>
  54. </script>
  55. <table class="layui-table" id="table" lay-filter="table"></table>
  56. {include file="public/foot"}
  57. <script type="text/javascript">
  58. layui.use(['table', 'layer', 'form'], function () {
  59. var table = layui.table,
  60. form = layui.form,
  61. layer = layui.layer;
  62. //第一个实例
  63. table.render({
  64. id: 'table'
  65. , elem: '#table'
  66. , size: 'sm' //小尺寸的表格
  67. , toolbar: '#toolbarDemo'
  68. , defaultToolbar: []
  69. , limit: 15
  70. , limits: [15, 20, 30, 40, 50, 100]
  71. , url: "{:url('index',['pid'=>$Request.param.pid])}" //数据接口
  72. , page: true //开启分页
  73. , cols: [[ //表头
  74. {
  75. key: 'sort', title: '排序', align: 'center', width: 60, templet: function (row) {
  76. return '<input type="text" name="sorts[]" value="' + row.sort + '" style="width: 20px;" class="sort"><input type="hidden" name="ids[]" value="' + row.id + '">';
  77. }
  78. },
  79. {type: 'checkbox'},
  80. {field: 'id', title: 'ID', width: 60, align: 'center'},
  81. {field: 'name', title: '{$config.name_label}', minWidth: 150},
  82. {field: 'value', title: '{$config.value_label}', align: 'center',minWidth:150},
  83. {field: 'description', title: '{$config.desc_label}', minWidth:150},
  84. //{if condition="$config->image_open"}
  85. {
  86. field: 'image', title: '{$config.image_label}', minWidth: 80, align: 'center', templet: function (row) {
  87. return (row.thumb_url == '') ? '' : '<a href="' + row.thumb_url + '" class="tooltip" target="_blank"><img src="' + row.thumb_url + '" width="20" height="20"></a>';
  88. }
  89. },
  90. //{/if}
  91. {
  92. field: 'status', title: '状态', align: 'center', width: 100, templet: function (row) {
  93. if (row.group_type == 2) {
  94. return '<a style="font-size:18px;color: #009688" lay-event="single_status">' + (row.single_status == 1 ? '<i class="layui-icon layui-icon-radio"></i>' : '<i class="layui-icon layui-icon-circle"></i>') + '</a>';
  95. }
  96. return '<a href="javascript:;" style="font-size:18px;" class="status" data-id="' + row.id + '" data-val="' + row.status + '">' + (row.status == 1 ? '<i class="fa fa-toggle-on"></i>' : '<i class="fa fa-toggle-off"></i>') + '</a>';
  97. }
  98. },
  99. {field: 'action', title: '操作', toolbar: '#barDemo', align: 'center',fixed: 'right',minWidth:80}
  100. ]],
  101. done: function () {
  102. showThumb();
  103. switchStatus('.status', "{:url('status')}");
  104. }
  105. });
  106. form.on('submit(serch)', function (data) {
  107. table.reload('table', {
  108. where: data.field
  109. , page: {
  110. curr: 1 //重新从第 1 页开始
  111. }
  112. });
  113. return false;
  114. });
  115. table.on('tool(table)', function (obj) {
  116. if (obj.event == 'edit') {
  117. location.href = "{:url('publish',['pid'=>$Request.param.pid])}?id=" + obj.data.id;
  118. }
  119. else if (obj.event == 'del') {
  120. layer.confirm('确定要删除?', function (index) {
  121. $.ajax({
  122. url: "{:url('delete')}",
  123. dataType: 'json',
  124. data: {id: obj.data.id},
  125. success: function (res) {
  126. layer.msg(res.msg);
  127. if (res.code == 1) {
  128. table.reload('table');
  129. }
  130. }
  131. })
  132. })
  133. }
  134. else if (obj.event == 'single_status') {
  135. var status = obj.data.single_status == 1 ? 0 : 1;
  136. $.ajax({
  137. type: "post",
  138. url: '{:url("single_status")}',
  139. data: {status: status, id: obj.data.id , pid:'{$Request.param.pid}'},
  140. dataType: 'json',
  141. success: function (res) {
  142. if (res.code == 1) {
  143. table.reload('table');
  144. } else {
  145. layer.msg(res.msg);
  146. }
  147. }
  148. })
  149. }
  150. });
  151. //监听事件
  152. table.on('toolbar(table)', function (obj) {
  153. if (obj.event == 'deletes') {
  154. var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
  155. var data = checkStatus.data;
  156. if (data.length > 0) {
  157. var ids = [];//数组
  158. data.forEach(function (item, key) {
  159. ids[key] = item.id;
  160. })
  161. layer.confirm('是否删除?', function (index, layero) {
  162. $.ajax({
  163. url: "{:url('deletes')}",
  164. dataType: 'json',
  165. data: {"ids": ids},
  166. type: 'post',
  167. success: function (res) {
  168. layer.msg(res.msg);
  169. if (res.code == 1) {
  170. table.reload('table');
  171. }
  172. }
  173. })
  174. layer.close(index)
  175. });
  176. } else {
  177. layer.msg('请先勾选需要操作的记录');
  178. }
  179. }
  180. });
  181. });
  182. </script>
  183. <script>
  184. // 排序
  185. layui.use(['layer', 'form'], function () {
  186. var layer = layui.layer,
  187. $ = layui.jquery,
  188. form = layui.form;
  189. $(window).on('load', function () {
  190. form.on('submit(admin)', function (data) {
  191. $sort_eles = $('.sort');
  192. $data = {};
  193. if ($sort_eles.length > 0) {
  194. for (var i = 0; i < $sort_eles.length; i++) {
  195. $data['sorts[' + i + ']'] = $sort_eles[i].value;
  196. $data['ids[' + i + ']'] = $sort_eles[i].nextSibling.value;
  197. }
  198. }
  199. console.log($data)
  200. $.ajax({
  201. url: "{:url('sort')}",
  202. data: $data,
  203. type: 'post',
  204. async: false,
  205. success: function (res) {
  206. if (res.code == 1) {
  207. layer.alert(res.msg, function (index) {
  208. location.reload();
  209. })
  210. } else {
  211. layer.msg(res.msg);
  212. }
  213. }
  214. })
  215. return false;
  216. });
  217. });
  218. });
  219. </script>
  220. </div>
  221. </body>
  222. </html>