commentlist.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <div class="layui-fluid">
  2. <div class="layui-card">
  3. <div class="layui-form layui-form-pane layui-card-header layuiadmin-card-header-auto" lay-filter="LAY-artapp-article-commentlist-search">
  4. <div class="layui-form-item">
  5. <div class="layui-inline">
  6. <label class="layui-form-label">标题</label>
  7. <div class="layui-input-block">
  8. <input type="text" name="keywords" placeholder="请输入" autocomplete="off" class="layui-input">
  9. </div>
  10. </div>
  11. <div class="layui-inline">
  12. <label class="layui-form-label">状态</label>
  13. <div class="layui-input-block">
  14. <select name="status">
  15. <option value="">全部状态</option>
  16. <option value="1">已通过</option>
  17. <option value="2">待审核</option>
  18. </select>
  19. </div>
  20. </div>
  21. <div class="layui-inline">
  22. <button class="layui-btn" lay-submit lay-filter="LAY-artapp-article-commentlist-search-btn">
  23. <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
  24. </button>
  25. </div>
  26. </div>
  27. </div>
  28. <div class="layui-card-body">
  29. <div style="padding-bottom: 10px;">
  30. <button class="layui-btn layuiadmin-btn" data-type="batchdel">删除</button>
  31. <button class="layui-btn layuiadmin-btn" data-type="batchstatus">批量审核通过</button>
  32. </div>
  33. <table id="LAY-artapp-article-commentlist-table" lay-filter="LAY-artapp-article-commentlist-table"></table>
  34. <script type="text/html" id="useravatarTpl">
  35. <img style="width: 100%; height: 100%;" src="{{d.user.avatar}}" alt="{{d.user.nickname}}">
  36. </script>
  37. <script type="text/html" id="usernicknameTpl">
  38. {{d.user.nickname}}
  39. </script>
  40. <script type="text/html" id="detailsTpl">
  41. {{# if(d.puserid == 0){ }}
  42. {{d.details}}
  43. {{# } else { }}
  44. 回复{{d.puser.nickname}}:{{d.details}}
  45. {{# } }}
  46. </script>
  47. <script type="text/html" id="statusTpl">
  48. {{# if(d.status == 1){ }}
  49. 已通过
  50. {{# } else { }}
  51. 待审核
  52. {{# } }}
  53. </script>
  54. <script type="text/html" id="setTpl">
  55. {{# if(d.status == 1){ }}
  56. <a class="layui-btn layui-btn-xs" lay-event="setstatus"><i class="layui-icon layui-icon-ok"></i>已通过</a>
  57. {{# } else { }}
  58. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="setstatus"><i class="layui-icon layui-icon-edit"></i>待审核</a>
  59. {{# } }}
  60. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delcomment"><i class="layui-icon layui-icon-delete"></i>删除</a>
  61. </script>
  62. </div>
  63. </div>
  64. </div>
  65. <script>
  66. layui.config({
  67. base: '/static/echoui/' //静态资源所在路径
  68. }).extend({
  69. index: 'lib/index' //主入口模块
  70. }).use(['index', 'form', 'set', 'table'], function() {
  71. var $ = layui.$,
  72. setter = layui.setter,
  73. admin = layui.admin,
  74. form = layui.form,
  75. table = layui.table;
  76. form.render();
  77. table.render({
  78. elem: '#LAY-artapp-article-commentlist-table',
  79. url: setter.baseAdminUrl + 'article/listcomment',
  80. cols: [[
  81. {type: 'checkbox', fixed: 'left'},
  82. {field: 'id', width: 80, title: '表ID', sort: true},
  83. {field: 'useravatar', width: 60, title: '头像', templet: '#useravatarTpl'},
  84. {field: 'usernickname', width: 150, title: '昵称', templet: '#usernicknameTpl'},
  85. {field: 'details', title: '内容', templet: '#detailsTpl', edit: 'text'},
  86. {field: 'status', width: 160, title: '状态', templet: '#statusTpl'},
  87. {field: 'createtime', width: 160, title: '发布时间', sort: true},
  88. {title: '操作', width: 200, align: 'center', fixed: 'right', toolbar: '#setTpl'}
  89. ]],
  90. page: true,
  91. limit: 50,
  92. cellMinWidth: 150,
  93. text: '对不起,加载出现异常!'
  94. });
  95. form.on('submit(LAY-artapp-article-commentlist-search-btn)', function(data) {
  96. table.reload('LAY-artapp-article-commentlist-table', {
  97. where: data.field,
  98. page: {
  99. curr: 1
  100. }
  101. });
  102. });
  103. table.on('edit(LAY-artapp-article-commentlist-table)', function(obj){
  104. var id = obj.data.id,
  105. field = obj.field,
  106. value = obj.value;
  107. admin.req({
  108. url: setter.baseAdminUrl + 'article/fieldcomment',
  109. data: {id: id, field: field, value: value},
  110. done: function(res) {
  111. layer.msg('修改成功');
  112. }
  113. });
  114. });
  115. table.on('tool(LAY-artapp-article-commentlist-table)', function(obj) {
  116. var data = obj.data;
  117. if (obj.event === 'delcomment') {
  118. layer.confirm('确定删除此评论吗?', function(index) {
  119. admin.req({
  120. url: setter.baseAdminUrl + 'article/delcomment',
  121. data: {
  122. idarr: [data.id]
  123. },
  124. done: function(res) {
  125. obj.del();
  126. layer.msg('已删除');
  127. }
  128. });
  129. layer.close(index);
  130. });
  131. } else if (obj.event === 'setstatus') {
  132. admin.req({
  133. url: setter.baseAdminUrl + 'article/statuscomment',
  134. data: {id: data.id},
  135. done: function(res) {
  136. layer.msg('状态修改成功');
  137. layui.table.reload('LAY-artapp-article-commentlist-table');
  138. }
  139. });
  140. }
  141. });
  142. var active = {
  143. batchdel: function() {
  144. var checkStatus = table.checkStatus('LAY-artapp-article-commentlist-table'),
  145. checkData = checkStatus.data; //得到选中的数据
  146. if (checkData.length === 0) {
  147. return layer.msg('请选择数据');
  148. }
  149. var idarr = [];
  150. for (var i = 0; i < checkData.length; i++) {
  151. idarr.push(checkData[i].id);
  152. }
  153. layer.confirm('确定删除所选评论吗?', function(index) {
  154. admin.req({
  155. url: setter.baseAdminUrl + 'article/delcomment',
  156. data: {
  157. idarr: idarr
  158. },
  159. done: function(res) {
  160. table.reload('LAY-artapp-article-commentlist-table');
  161. layer.msg('已删除');
  162. }
  163. });
  164. layer.close(index);
  165. });
  166. },
  167. batchstatus: function() {
  168. var checkStatus = table.checkStatus('LAY-artapp-article-commentlist-table'),
  169. checkData = checkStatus.data; //得到选中的数据
  170. if (checkData.length === 0) {
  171. return layer.msg('请选择数据');
  172. }
  173. var idarr = [];
  174. for (var i = 0; i < checkData.length; i++) {
  175. idarr.push(checkData[i].id);
  176. }
  177. layer.confirm('确定批量通过所选评论吗?', function(index) {
  178. admin.req({
  179. url: setter.baseAdminUrl + 'article/statuscommentall',
  180. data: {
  181. idarr: idarr
  182. },
  183. done: function(res) {
  184. table.reload('LAY-artapp-article-commentlist-table');
  185. layer.msg('已审核通过');
  186. }
  187. });
  188. layer.close(index);
  189. });
  190. }
  191. };
  192. $('.layui-btn.layuiadmin-btn').on('click', function(){
  193. var type = $(this).data('type');
  194. active[type] ? active[type].call(this) : '';
  195. });
  196. });
  197. </script>