index.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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="/static/public/layui/css/layui.css" media="all">
  10. <link rel="stylesheet" href="/static/public/font-awesome/css/font-awesome.min.css" media="all"/>
  11. <link rel="stylesheet" href="/static/admin/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. .tooltip > img {
  23. width: 20px;
  24. height: 20px;
  25. }
  26. </style>
  27. </head>
  28. <body style="padding:10px;">
  29. <div class="tplay-body-div">
  30. <div class="layui-tab">
  31. <ul class="layui-tab-title">
  32. <li class="layui-this">列表</li>
  33. <li><a href="{:url('publish')}" class="a_menu">新增</a></li>
  34. </ul>
  35. </div>
  36. <script type="text/html" id="toolbarDemo">
  37. <div class="layui-btn-container">
  38. <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="deletes">批量删除</button>
  39. </div>
  40. </script>
  41. <form class="layui-form serch" action="index" method="post">
  42. <div class="layui-form-item" style="float: left;">
  43. <div class="layui-input-inline">
  44. <input type="text" name="ids" autocomplete="off" placeholder="请输入ID,多个id逗号分隔"
  45. class="layui-input layui-btn-sm">
  46. </div>
  47. <div class="layui-input-inline">
  48. <input type="text" name="title" autocomplete="off" placeholder="地名(模糊搜索)"
  49. class="layui-input layui-btn-sm">
  50. </div>
  51. <div class="layui-input-inline">
  52. <input type="text" name="address" autocomplete="off" placeholder="详细地址(模糊搜索)"
  53. class="layui-input layui-btn-sm">
  54. </div>
  55. <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
  56. </div>
  57. </form>
  58. <script type="text/html" id="barDemo">
  59. <div class="layui-btn-group">
  60. <button class="layui-btn layui-btn-xs a_menu" lay-event="edit"><i class="layui-icon"
  61. style="margin-right: 0;"></i></button>
  62. <button class="layui-btn layui-btn-xs delete" lay-event="del"><i class="layui-icon"
  63. style="margin-right: 0;"></i></button>
  64. </div>
  65. </script>
  66. <table class="layui-table" id="table" lay-filter="table"></table>
  67. {include file="public/foot"}
  68. <script type="text/javascript">
  69. layui.use(['table', 'layer', 'form', 'laydate'], function () {
  70. var table = layui.table,
  71. form = layui.form,
  72. layer = layui.layer;
  73. var laydate = layui.laydate;
  74. //第一个实例
  75. table.render({
  76. id: 'table'
  77. , elem: '#table'
  78. , size: 'sm' //小尺寸的表格
  79. , toolbar: '#toolbarDemo'
  80. , limit: 15
  81. , limits: [15, 20, 30, 40, 50, 100]
  82. , url: "{:url('index')}" //数据接口
  83. , page: true //开启分页
  84. , cols: [[ //表头
  85. {type: 'checkbox'},
  86. {field: 'id', title: 'ID', width: 60},
  87. {field: "title", title: '地名'},
  88. {
  89. field: 'image', title: '缩略图', width: 70, align: 'center', templet: function (row) {
  90. return (row.thumb_url == '') ? '' : '<a href="' + row.thumb_url + '" class="tooltip" target="_blank"><img src="' + row.thumb_url + '" width="20" height="20"></a>';
  91. }
  92. },
  93. {field: "address", title: '详细地址'},
  94. {field: "status_text", title: '是否启用'},
  95. {field: 'action', title: '操作', toolbar: '#barDemo', fixed: 'right',width:80}
  96. ]],
  97. done: function () {
  98. if (isExitsFunction('showThumb')) {
  99. showThumb()
  100. }
  101. }
  102. });
  103. form.on('submit(serch)', function (data) {
  104. table.reload('table', {
  105. where: data.field
  106. , page: {
  107. curr: 1 //重新从第 1 页开始
  108. }
  109. });
  110. return false;
  111. });
  112. table.on('tool(table)', function (obj) {
  113. if (obj.event == 'edit') {
  114. window.parent.tab.tabAdd({
  115. icon: "fa-bookmark",
  116. id: "tplay_address" + obj.data.id,
  117. title: obj.data.title == null ? "地址" + obj.data.id : obj.data.title,
  118. url: "/admin/address/publish?id=" + obj.data.id
  119. });
  120. }
  121. else if (obj.event == 'del') {
  122. layer.confirm('确定要删除?', function (index) {
  123. $.ajax({
  124. url: "{:url('delete')}",
  125. dataType: 'json',
  126. data: {id: obj.data.id},
  127. success: function (res) {
  128. layer.msg(res.msg);
  129. if (res.code == 1) {
  130. table.reload('table');
  131. }
  132. }
  133. })
  134. })
  135. }
  136. });
  137. //监听事件
  138. table.on('toolbar(table)', function (obj) {
  139. if (obj.event == 'deletes') {
  140. var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
  141. var data = checkStatus.data;
  142. if (data.length > 0) {
  143. var ids = [];//数组
  144. data.forEach(function (item, key) {
  145. ids[key] = item.id;
  146. })
  147. layer.confirm('是否删除?', function (index, layero) {
  148. $.ajax({
  149. url: "{:url('deletes')}",
  150. dataType: 'json',
  151. data: {"ids": ids},
  152. type: 'post',
  153. success: function (res) {
  154. layer.msg(res.msg);
  155. if (res.code == 1) {
  156. table.reload('table');
  157. }
  158. }
  159. })
  160. layer.close(index)
  161. });
  162. } else {
  163. layer.msg('请先勾选需要操作的记录');
  164. }
  165. }
  166. });
  167. });
  168. </script>
  169. </div>
  170. </body>
  171. </html>