index.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. //{if condition="$config->color_open"}
  92. {
  93. field: 'color', title: '{$config.color_label}', minWidth: 80, align: 'center', templet: function (row) {
  94. return '<div style="color:' + row.color + '">' + row.color + '</div>';
  95. }
  96. },
  97. //{/if}
  98. {
  99. field: 'status', title: '状态', align: 'center', width: 100, templet: function (row) {
  100. if (row.group_type == 2) {
  101. 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>';
  102. }
  103. 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>';
  104. }
  105. },
  106. {field: 'action', title: '操作', toolbar: '#barDemo', align: 'center',fixed: 'right',minWidth:80}
  107. ]],
  108. done: function () {
  109. showThumb();
  110. switchStatus('.status', "{:url('status')}");
  111. }
  112. });
  113. form.on('submit(serch)', function (data) {
  114. table.reload('table', {
  115. where: data.field
  116. , page: {
  117. curr: 1 //重新从第 1 页开始
  118. }
  119. });
  120. return false;
  121. });
  122. table.on('tool(table)', function (obj) {
  123. if (obj.event == 'edit') {
  124. location.href = "{:url('publish',['pid'=>$Request.param.pid])}?id=" + obj.data.id;
  125. }
  126. else if (obj.event == 'del') {
  127. layer.confirm('确定要删除?', function (index) {
  128. $.ajax({
  129. url: "{:url('delete')}",
  130. dataType: 'json',
  131. data: {id: obj.data.id},
  132. success: function (res) {
  133. layer.msg(res.msg);
  134. if (res.code == 1) {
  135. table.reload('table');
  136. }
  137. }
  138. })
  139. })
  140. }
  141. else if (obj.event == 'single_status') {
  142. var status = obj.data.single_status == 1 ? 0 : 1;
  143. $.ajax({
  144. type: "post",
  145. url: '{:url("single_status")}',
  146. data: {status: status, id: obj.data.id , pid:'{$Request.param.pid}'},
  147. dataType: 'json',
  148. success: function (res) {
  149. if (res.code == 1) {
  150. table.reload('table');
  151. } else {
  152. layer.msg(res.msg);
  153. }
  154. }
  155. })
  156. }
  157. });
  158. //监听事件
  159. table.on('toolbar(table)', function (obj) {
  160. if (obj.event == 'deletes') {
  161. var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
  162. var data = checkStatus.data;
  163. if (data.length > 0) {
  164. var ids = [];//数组
  165. data.forEach(function (item, key) {
  166. ids[key] = item.id;
  167. })
  168. layer.confirm('是否删除?', function (index, layero) {
  169. $.ajax({
  170. url: "{:url('deletes')}",
  171. dataType: 'json',
  172. data: {"ids": ids},
  173. type: 'post',
  174. success: function (res) {
  175. layer.msg(res.msg);
  176. if (res.code == 1) {
  177. table.reload('table');
  178. }
  179. }
  180. })
  181. layer.close(index)
  182. });
  183. } else {
  184. layer.msg('请先勾选需要操作的记录');
  185. }
  186. }
  187. });
  188. });
  189. </script>
  190. <script>
  191. // 排序
  192. layui.use(['layer', 'form'], function () {
  193. var layer = layui.layer,
  194. $ = layui.jquery,
  195. form = layui.form;
  196. $(window).on('load', function () {
  197. form.on('submit(admin)', function (data) {
  198. $sort_eles = $('.sort');
  199. $data = {};
  200. if ($sort_eles.length > 0) {
  201. for (var i = 0; i < $sort_eles.length; i++) {
  202. $data['sorts[' + i + ']'] = $sort_eles[i].value;
  203. $data['ids[' + i + ']'] = $sort_eles[i].nextSibling.value;
  204. }
  205. }
  206. console.log($data)
  207. $.ajax({
  208. url: "{:url('sort')}",
  209. data: $data,
  210. type: 'post',
  211. async: false,
  212. success: function (res) {
  213. if (res.code == 1) {
  214. layer.alert(res.msg, function (index) {
  215. location.reload();
  216. })
  217. } else {
  218. layer.msg(res.msg);
  219. }
  220. }
  221. })
  222. return false;
  223. });
  224. });
  225. });
  226. </script>
  227. </div>
  228. </body>
  229. </html>