index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. {include file="user/tab"}
  27. <form class="layui-form serch" action="{:url('index')}" method="post">
  28. <div class="layui-form-item" style="float: left;">
  29. <div class="layui-input-inline" style="width: 90px;">
  30. <input type="text" name="id" lay-verify="title" autocomplete="off" placeholder="消息ID"
  31. class="layui-input layui-btn-sm">
  32. </div>
  33. <div class="layui-input-inline" style="width: 90px;">
  34. <input type="text" name="from_user_id" lay-verify="title" autocomplete="off" placeholder="发送人ID"
  35. class="layui-input layui-btn-sm">
  36. </div>
  37. <div class="layui-input-inline" style="width: 90px;">
  38. <input type="text" name="to_user_id" lay-verify="title" autocomplete="off" placeholder="接收人ID"
  39. class="layui-input layui-btn-sm">
  40. </div>
  41. <div class="layui-input-inline">
  42. <input type="text" name="keywords" lay-verify="title" autocomplete="off" placeholder="查找内容"
  43. class="layui-input layui-btn-sm">
  44. </div>
  45. <div class="layui-input-inline">
  46. <input type="text" name="ip" lay-verify="title" autocomplete="off" placeholder="IP"
  47. class="layui-input layui-btn-sm">
  48. </div>
  49. <div class="layui-input-inline">
  50. <input type="text" class="layui-input" id="time_range" placeholder="时间" autocomplete="off"
  51. name="create_time">
  52. </div>
  53. <div class="layui-input-inline" style="width: 90px;">
  54. <select name="is_look" lay-search="">
  55. <option value="">阅读状态</option>
  56. <option value="0">未读</option>
  57. <option value="1">已读</option>
  58. </select>
  59. </div>
  60. <div class="layui-input-inline" style="width: 90px;">
  61. <select name="status" lay-search="">
  62. <option value="">审核</option>
  63. <option value="0">待审核</option>
  64. <option value="1">已审核</option>
  65. <option value="-1">已拒绝</option>
  66. </select>
  67. </div>
  68. <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
  69. </div>
  70. </form>
  71. <script type="text/html" id="toolbarDemo">
  72. <div class="layui-btn-container">
  73. <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="deletes">批量删除</button>
  74. <button class="layui-btn layui-btn-sm" lay-event="sysmessage">回复消息</button>
  75. <button class="layui-btn layui-btn-sm" lay-event="sendmessage">发送公告</button>
  76. </div>
  77. </script>
  78. <script type="text/html" id="barDemo">
  79. <div class="layui-btn-group">
  80. <button class="layui-btn layui-btn-xs a_menu" lay-event="edit"><i class="layui-icon"
  81. style="margin-right: 0;"></i></button>
  82. <button class="layui-btn layui-btn-xs delete" lay-event="del"><i class="layui-icon"
  83. style="margin-right: 0;"></i></button>
  84. </div>
  85. </script>
  86. <table class="layui-table" id="table" lay-filter="table"></table>
  87. {include file="public/foot"}
  88. <script type="text/javascript">
  89. layui.use(['table', 'layer', 'form'], function () {
  90. var table = layui.table,
  91. form = layui.form,
  92. layer = layui.layer;
  93. //第一个实例
  94. table.render({
  95. id: 'table'
  96. , elem: '#table'
  97. , size: 'sm' //小尺寸的表格
  98. , toolbar: '#toolbarDemo'
  99. // , defaultToolbar: []
  100. , limit: 15
  101. , limits: [15, 20, 30, 40, 50, 100]
  102. , url: "{:url('index')}" //数据接口
  103. , page: true //开启分页
  104. , cols: [[ //表头
  105. {type: 'checkbox'},
  106. {field: 'id', title: 'ID', width: 60},
  107. {field: 'from_user', title: '消息发送人', width: 160},
  108. {field: 'message', title: '内容', minWidth:200},
  109. {field: 'to_user', title: '消息接收人', width: 160},
  110. {field: 'to_msg_id', title: '回复消息ID', width: 160},
  111. {field: 'create_time', title: '时间', width: 160},
  112. {
  113. field: 'is_look', title: '阅读状态', align: 'center', width: 80, templet: function (row) {
  114. return '<a href="javascript:;" style="font-size:18px;" class="is_look" data-id="' + row.id + '" data-val="' + row.is_look + '">' + (row.is_look == 1 ? '<i class="fa fa-toggle-on"></i>' : '<i class="fa fa-toggle-off"></i>') + '</a>';
  115. }
  116. },
  117. {
  118. field: 'status', title: '审核', width: 80, fixed: 'right', templet: function (row) {
  119. if (row.status == 1) {
  120. return '<span class="layui-badge status" style="background-color: #8FCDA0" data-id="'+row.id+'">'+row.status_text+'</span>';
  121. } else if (row.status == -1) {
  122. return '<span class="layui-badge status" data-id="'+row.id+'">'+row.status_text+'</span>';
  123. } else {
  124. return '<span class="layui-badge layui-bg-gray status" data-id="'+row.id+'">'+row.status_text+'</span>';
  125. }
  126. }
  127. },
  128. {field: 'ip', title: 'IP', width: 100},
  129. // {field: 'action', title: '操作', align: 'center', toolbar: '#barDemo', fixed: 'right',width:100}
  130. ]],
  131. done: function () {
  132. switchLook();
  133. switchStatus(table);
  134. }
  135. });
  136. form.on('submit(serch)', function (data) {
  137. table.reload('table', {
  138. where: data.field
  139. , page: {
  140. curr: 1 //重新从第 1 页开始
  141. }
  142. });
  143. return false;
  144. });
  145. //编辑
  146. table.on('tool(table)', function (obj) {
  147. if (obj.event == 'edit') {
  148. location.href = "{:url('publish')}?id=" + obj.data.id;
  149. }
  150. else if (obj.event == 'del') {
  151. layer.confirm('确定要删除?', function (index) {
  152. $.ajax({
  153. url: "{:url('delete')}",
  154. dataType: 'json',
  155. data: {id: obj.data.id},
  156. success: function (res) {
  157. layer.msg(res.msg);
  158. if (res.code == 1) {
  159. table.reload('table');
  160. }
  161. }
  162. })
  163. })
  164. }
  165. //
  166. });
  167. //监听事件
  168. table.on('toolbar(table)', function (obj) {
  169. if (obj.event == 'deletes') {
  170. var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
  171. var data = checkStatus.data;
  172. if (data.length > 0) {
  173. var ids = [];//数组
  174. data.forEach(function (item, key) {
  175. ids[key] = item.id;
  176. })
  177. layer.confirm('是否删除?', function (index, layero) {
  178. $.ajax({
  179. url: "{:url('deletes')}",
  180. dataType: 'json',
  181. data: {"ids": ids},
  182. type: 'post',
  183. success: function (res) {
  184. layer.msg(res.msg);
  185. if (res.code == 1) {
  186. table.reload('table');
  187. }
  188. }
  189. })
  190. layer.close(index)
  191. });
  192. } else {
  193. layer.msg('请先勾选,需要操作的记录');
  194. }
  195. }
  196. else if (obj.event == 'sysmessage') {
  197. var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
  198. var data = checkStatus.data;
  199. if (data.length > 0) {
  200. var ids = [];//数组
  201. data.forEach(function (item, key) {
  202. ids[key] = item.id;
  203. })
  204. layer.prompt({
  205. formType: 2,
  206. anim: 1,
  207. title: '请输入内容',
  208. skin: 'demo-class',
  209. area: ['280px', '150px'],
  210. id: 'remember',//设定一个id,防止重复弹出
  211. moveType: 1, //拖拽模式,0或者1
  212. }, function (value, index, elem) {
  213. layer.confirm('确认发送?', function (index2, layero) {
  214. $.ajax({
  215. url: "{:url('sysmessage')}",
  216. dataType: 'json',
  217. data: {"ids": ids, message: value},
  218. type: 'post',
  219. success: function (res) {
  220. layer.msg(res.msg);
  221. if (res.code == 1) {
  222. table.reload('table');
  223. }
  224. }
  225. });
  226. layer.close(index2);
  227. layer.close(index);
  228. });
  229. })
  230. } else {
  231. layer.msg('请先勾选,需要回复的消息');
  232. }
  233. }
  234. else if(obj.event == 'sendmessage'){
  235. window.parent.document.getElementById('tag').click();
  236. }
  237. });
  238. });
  239. </script>
  240. <script>
  241. function switchLook() {
  242. $('.is_look').click(function () {
  243. var val = $(this).attr('data-val');
  244. var id = $(this).attr('data-id');
  245. var i = $(this).find('i');
  246. var the = $(this);
  247. if (val == 1) {
  248. var status = 0;
  249. } else {
  250. var status = 1;
  251. }
  252. $.ajax({
  253. type: "post",
  254. url: "{:url('look')}",
  255. dataType: 'json',
  256. data: {id: id, status: status},
  257. success: function (res) {
  258. if (res.code == 1) {
  259. tostatus();
  260. } else {
  261. layer.msg(res.msg);
  262. }
  263. }
  264. })
  265. function tostatus() {
  266. if (val == 1) {
  267. i.attr("class", "fa fa-toggle-off");
  268. the.attr('data-val', 0);
  269. } else {
  270. i.attr("class", "fa fa-toggle-on");
  271. the.attr('data-val', 1);
  272. }
  273. }
  274. })
  275. }
  276. function switchStatus(table) {
  277. $('.status').click(function () {
  278. var id = $(this).attr('data-id');
  279. layer.msg('审核', {
  280. time: 20000,
  281. btn: ['通过', '拒绝','待审', '再想想'],
  282. yes: function (index, layero) {
  283. $.ajax({
  284. url: "{:url('admin/tomessages/status')}",
  285. type: 'post',
  286. dataType: 'json', data: {id: id, status: '1'},
  287. success: function (res) {
  288. layer.msg(res.msg);
  289. if (res.code == 1) {
  290. table.reload('table');
  291. }
  292. }
  293. })
  294. },
  295. btn2: function (index, layero) {
  296. $.ajax({
  297. url: "{:url('admin/tomessages/status')}",
  298. type: 'post',
  299. dataType: 'json', data: {id: id, status: '-1'},
  300. success: function (res) {
  301. layer.msg(res.msg);
  302. if (res.code == 1) {
  303. table.reload('table');
  304. }
  305. }
  306. })
  307. }
  308. ,btn3: function(index, layero){
  309. $.ajax({
  310. url: "{:url('admin/tomessages/status')}",
  311. type: 'post',
  312. dataType: 'json', data: {id: id, status: '0'},
  313. success: function (res) {
  314. layer.msg(res.msg);
  315. if (res.code == 1) {
  316. table.reload('table');
  317. }
  318. }
  319. })
  320. },
  321. })
  322. })
  323. }
  324. </script>
  325. </div>
  326. </body>
  327. </html>