index.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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: 'action', title: '操作', toolbar: '#barDemo', fixed: 'right',width:80}
  95. ]],
  96. done: function () {
  97. if (isExitsFunction('showThumb')) {
  98. showThumb()
  99. }
  100. }
  101. });
  102. form.on('submit(serch)', function (data) {
  103. table.reload('table', {
  104. where: data.field
  105. , page: {
  106. curr: 1 //重新从第 1 页开始
  107. }
  108. });
  109. return false;
  110. });
  111. table.on('tool(table)', function (obj) {
  112. if (obj.event == 'edit') {
  113. window.parent.tab.tabAdd({
  114. icon: "fa-bookmark",
  115. id: "tplay_address" + obj.data.id,
  116. title: obj.data.title == null ? "地址" + obj.data.id : obj.data.title,
  117. url: "/admin/address/publish?id=" + obj.data.id
  118. });
  119. }
  120. else if (obj.event == 'del') {
  121. layer.confirm('确定要删除?', function (index) {
  122. $.ajax({
  123. url: "{:url('delete')}",
  124. dataType: 'json',
  125. data: {id: obj.data.id},
  126. success: function (res) {
  127. layer.msg(res.msg);
  128. if (res.code == 1) {
  129. table.reload('table');
  130. }
  131. }
  132. })
  133. })
  134. }
  135. });
  136. //监听事件
  137. table.on('toolbar(table)', function (obj) {
  138. if (obj.event == 'deletes') {
  139. var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
  140. var data = checkStatus.data;
  141. if (data.length > 0) {
  142. var ids = [];//数组
  143. data.forEach(function (item, key) {
  144. ids[key] = item.id;
  145. })
  146. layer.confirm('是否删除?', function (index, layero) {
  147. $.ajax({
  148. url: "{:url('deletes')}",
  149. dataType: 'json',
  150. data: {"ids": ids},
  151. type: 'post',
  152. success: function (res) {
  153. layer.msg(res.msg);
  154. if (res.code == 1) {
  155. table.reload('table');
  156. }
  157. }
  158. })
  159. layer.close(index)
  160. });
  161. } else {
  162. layer.msg('请先勾选需要操作的记录');
  163. }
  164. }
  165. });
  166. });
  167. </script>
  168. </div>
  169. </body>
  170. </html>