index.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. {extend name="common/base"/}
  2. <!-- 主体 -->
  3. {block name="body"}
  4. <div class="p-3">
  5. <form class="layui-form gg-form-bar border-t border-x">
  6. <div class="layui-input-inline" style="width:300px;">
  7. <input type="text" name="keywords" placeholder="昵称/真实姓名/手机号" class="layui-input" autocomplete="off" />
  8. </div>
  9. <div class="layui-input-inline" style="width:120px;">
  10. <input type="text" class="layui-input" id="start_time" readonly placeholder="注册开始时间" name="start_time">
  11. </div>
  12. ~
  13. <div class="layui-input-inline" style="width:120px;">
  14. <input type="text" class="layui-input" id="end_time" readonly placeholder="注册结束时间" name="end_time">
  15. </div>
  16. <div class="layui-input-inline">
  17. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">提交搜索</button>
  18. </div>
  19. </form>
  20. <table class="layui-hide" id="user" lay-filter="user"></table>
  21. </div>
  22. <script type="text/html" id="status">
  23. <i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
  24. </script>
  25. {/block}
  26. <!-- /主体 -->
  27. <!-- 脚本 -->
  28. {block name="script"}
  29. <script>
  30. const moduleInit = ['tool'];
  31. function gouguInit() {
  32. var tool = layui.tool, table = layui.table, laydate = layui.laydate, form = layui.form;
  33. laydate.render({
  34. elem: '#start_time',
  35. type: 'date'
  36. });
  37. laydate.render({
  38. elem: '#end_time',
  39. type: 'date'
  40. });
  41. layui.pageTable = table.render({
  42. elem: '#user',
  43. title: '用户列表',
  44. toolbar: '#toolbarDemo',
  45. url: '/admin/user/index', //数据接口
  46. page: true, //开启分页
  47. limit: 20,
  48. cols: [
  49. [ //表头
  50. {
  51. field: 'id',
  52. title: 'ID号',
  53. align: 'center',
  54. width: 90
  55. }, {
  56. field: 'headimgurl',
  57. title: '头像',
  58. align: 'center',
  59. width: 60,
  60. templet: function (d) {
  61. var html = '';
  62. var delBtn = '<img src="' + d.headimgurl + '" width="28" height="28"/>';
  63. return delBtn;
  64. }
  65. }, {
  66. field: 'username',
  67. title: '用户名',
  68. align: 'center',
  69. width: 100
  70. }, {
  71. field: 'level_name',
  72. title: '会员等级',
  73. align: 'center',
  74. width: 90
  75. }, {
  76. field: 'sex',
  77. title: '性别',
  78. align: 'center',
  79. width: 60,
  80. templet: function (d) {
  81. var html = '-';
  82. if (d.sex == 1) {
  83. html = '男'
  84. } else if (d.sex == 2) {
  85. html = '女'
  86. }
  87. return html;
  88. }
  89. }, {
  90. field: 'nickname',
  91. title: '昵称',
  92. align: 'center',
  93. width: 100
  94. }, {
  95. field: 'name',
  96. title: '真实姓名',
  97. align: 'center',
  98. width: 100
  99. }, {
  100. field: 'mobile',
  101. title: '手机号码',
  102. align: 'center',
  103. width: 120
  104. }, {
  105. field: 'email',
  106. title: '电子邮箱',
  107. align: 'center',
  108. minWidth: 150
  109. }, {
  110. field: 'register_time',
  111. title: '注册时间',
  112. align: 'center',
  113. width: 150
  114. }, {
  115. field: 'status',
  116. title: '状态',
  117. toolbar: '#status',
  118. align: 'center',
  119. width: 60
  120. }, {
  121. field: 'right',
  122. fixed: 'right',
  123. title: '操作',
  124. align: 'center',
  125. width: 136,
  126. templet:function(d){
  127. let btn1 = '<span class="layui-btn layui-btn-xs layui-btn-normal" lay-event="view">详情</span><span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>';
  128. let btn2 = '<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">禁用</span>';
  129. let btn3 = '<span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="open">启用</span>';
  130. if(d.status == 1){
  131. return '<div class="layui-btn-group">'+btn1+btn2+'</div>';
  132. }else{
  133. return '<div class="layui-btn-group">'+btn1+btn3+'</div>';
  134. }
  135. }
  136. }
  137. ]
  138. ]
  139. });
  140. //监听行工具事件
  141. table.on('tool(user)', function (obj) {
  142. var data = obj.data;
  143. if (obj.event === 'view') {
  144. tool.side('/admin/user/view?id=' + data.id);
  145. return;
  146. }
  147. else if (obj.event === 'edit') {
  148. tool.side('/admin/user/edit?id=' + data.id);
  149. return;
  150. }
  151. else if (obj.event === 'del') {
  152. layer.confirm('您确定要禁用该用户', {
  153. icon: 3,
  154. title: '提示'
  155. }, function (index) {
  156. let callback = function (e) {
  157. layer.msg(e.msg);
  158. if (e.code == 0) {
  159. layer.close(index);
  160. layui.pageTable.reload()
  161. }
  162. }
  163. tool.post("/admin/user/disable", { id: data.id, status: 0 }, callback);
  164. layer.close(index);
  165. });
  166. } else if (obj.event === 'open') {
  167. layer.confirm('您确定要启用该用户', {
  168. icon: 3,
  169. title: '提示'
  170. }, function (index) {
  171. let callback = function (e) {
  172. layer.msg(e.msg);
  173. if (e.code == 0) {
  174. layer.close(index);
  175. layui.pageTable.reload()
  176. }
  177. }
  178. tool.post("/admin/user/disable", { id: data.id, status: 1 }, callback);
  179. layer.close(index);
  180. });
  181. }
  182. });
  183. //监听搜索提交
  184. form.on('submit(webform)', function (data) {
  185. layui.pageTable.reload({
  186. where: {
  187. keywords: data.field.keywords,
  188. attach: data.field.attach,
  189. start_time: data.field.start_time,
  190. end_time: data.field.end_time
  191. },
  192. page: {
  193. curr: 1
  194. }
  195. });
  196. return false;
  197. });
  198. }
  199. </script>
  200. {/block}
  201. <!-- /脚本 -->