white_list_index.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. {extend name="public/layout"}
  2. {block name="body"}
  3. <style>
  4. html,body {
  5. background-color: #fff;
  6. }
  7. .layui-table thead tr,
  8. .layui-table-header {
  9. background-color: #D8E6F1 !important;
  10. }
  11. .layui-table-tool {
  12. background-color: #F6FAFD;
  13. }
  14. .layui-btn-xs,.layui-btn-xs:hover {
  15. border: 1px solid #249EFB;
  16. background-color: #fff;
  17. color: #249EFB;
  18. padding: 0px 10px;
  19. }
  20. .layui-btn-danger,.layui-btn-danger:hover{
  21. color: #FF5722;
  22. background-color: #fff;
  23. border: 1px solid #FF5722;
  24. padding: 0px 10px;
  25. }
  26. </style>
  27. <body>
  28. <div class="layui-fluid">
  29. <div class="layui-row layui-col-space15">
  30. <div class="layui-col-md12" style="background-color:#ffffff">
  31. <div class="tplay-body-div">
  32. <div class="layui-card-body">
  33. <table class="layui-hide" id="user" lay-filter="user"></table>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. {/block}
  40. {block name="js"}
  41. <script src="__STATIC__/js/jquery.min.js"></script>
  42. <script id="img" type="text/html">
  43. <img src="{{ d.headimgurl }}" style="height: 30px;width: 30px" class="show">
  44. </script>
  45. <script type="text/html" id="result">
  46. {{# if(d.state==1){ }}
  47. <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">移除</a>
  48. {{# }else{ }}
  49. <a class="layui-btn layui-btn-xs" lay-event="join">通过</a>
  50. <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">拒绝</a>
  51. {{# } }}
  52. </script>
  53. <script type="text/html" id="sex">
  54. {{# if(d.sex==1){ }}
  55. {{# }else if(d.sex==2){ }}
  56. {{# }else{ }}
  57. 未知
  58. {{# } }}
  59. </script>
  60. <script type="text/html" id="toolbar">
  61. <div class="layui-btn-container">
  62. <button class="layui-btn layui-btn-sm" lay-event="join">通过</button>
  63. <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="refresh">刷新</button>
  64. </div>
  65. </script>
  66. <script>
  67. var indexurl = '{:url("white_list_index")}';
  68. var joinurl = '{:url("white_list_join")}';
  69. var delurl = '{:url("white_list_del")}';
  70. var t;
  71. layui.use(['table'], function () {
  72. var form = layui.form,
  73. table = layui.table,
  74. $ = layui.jquery,
  75. t;
  76. active = {
  77. reload: function () {
  78. var name = $('#name');
  79. //执行重载
  80. table.reload('userTable', {
  81. page: {
  82. curr: 1 //重新从第 1 页开始
  83. },
  84. where: {
  85. name: name.val()
  86. }
  87. });
  88. },
  89. join: function () {
  90. var id = this.data.id;
  91. $.ajax({
  92. type: 'post',
  93. url: joinurl + '?id=' + id,
  94. data: {
  95. id: id
  96. },
  97. success: function (res) {
  98. var rs = JSON.parse(res);
  99. layer.msg(rs.msg);
  100. if (rs.code == 0) {
  101. t.reload();
  102. }
  103. }
  104. });
  105. },
  106. del: function () {
  107. var id = this.data.id;
  108. msg = '确定拒绝该白名单申请么?';
  109. if (this.data.state == 1) {
  110. msg = '确定移除该白名单用户么?';
  111. }
  112. layer.confirm(msg,{title: ['信息', 'color:#333333;background-color:#D8E6F1;'],}, function () {
  113. $.post(delurl, {
  114. id: id
  115. }, function (resp) {
  116. var res = JSON.parse(resp);
  117. if (res.code == 0) {
  118. layer.msg(res.msg, {
  119. anim: 0
  120. }, function () {
  121. t.reload();
  122. });
  123. } else {
  124. layer.msg(res.msg, {
  125. anim: 6
  126. });
  127. }
  128. });
  129. });
  130. }
  131. };
  132. //展示已知数据
  133. t = table.render({
  134. elem: '#user',
  135. url: indexurl,
  136. page: true,
  137. autoSort: true,
  138. toolbar: '#toolbar',
  139. defaultToolbar:[],
  140. cols: [
  141. [ //标题栏
  142. {
  143. type: 'checkbox',
  144. fixed: 'left',
  145. width: 50
  146. }, {
  147. type: 'numbers',
  148. title: '序号',
  149. fixed: 'left',
  150. width: 50
  151. }, {
  152. field: 'nickname',
  153. title: '昵称',
  154. }, {
  155. templet: '#img',
  156. title: '头像',
  157. width: 80
  158. }, {
  159. templet: '#sex',
  160. title: '性别',
  161. width: 80
  162. }, {
  163. field: 'addtime',
  164. title: '添加时间',
  165. width: 180,
  166. sort: true
  167. }, {
  168. fixed: 'right',
  169. title: '操作',
  170. toolbar: '#result',
  171. width: 150
  172. }
  173. ]
  174. ]
  175. });
  176. table.on('tool(user)', function (obj) {
  177. var type = obj.event;
  178. active[type] ? active[type].call(obj) : '';
  179. });
  180. table.on('toolbar(user)', function(obj){
  181. if(obj.event == 'join'){
  182. var checkStatus = table.checkStatus(obj.config.id);
  183. var data = checkStatus.data;
  184. var ids = [];
  185. for(i in data) ids.push(data[i]['id']);
  186. if(ids.length == 0) {
  187. layer.msg('请选择要通过的用户');
  188. return false;
  189. }
  190. $.ajax({
  191. type:'post',
  192. url:joinurl,
  193. data:{id:ids},
  194. success: function(res){
  195. var rs = JSON.parse(res);
  196. layer.msg(rs.msg);
  197. if (rs.code == 0) {
  198. t.reload();
  199. }
  200. }
  201. });
  202. }else{
  203. t.reload();
  204. }
  205. });
  206. });
  207. </script>
  208. {/block}