index.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. {include file="common/header"/}
  2. <div class="LM-container">
  3. <div class="LM-main">
  4. <fieldset class="layui-elem-field layui-field-title">
  5. <legend>{:lang('user')}{:lang('list')}</legend>
  6. <blockquote class="layui-elem-quote">
  7. <div class="LM-table">
  8. <div class="layui-inline">
  9. <input type="text" id='keys' name="keys" lay-verify="required"
  10. placeholder="{:lang('pleaseEnter')}" autocomplete="off" class="layui-input">
  11. </div>
  12. <a href="javascript:;" class="layui-btn data-add-btn layui-btn-sm" lay-submit="" lay-filter="add" id="search">
  13. {:lang('search')}
  14. </a>
  15. <a href="{:url('add')}" class="layui-btn layui-btn-sm layui-btn-warm">{:lang('add')}{:lang('user')}</a>
  16. <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-danger" id="delAll">{:lang('delete checked')}</a>
  17. </div>
  18. </blockquote>
  19. </fieldset>
  20. <table class="layui-table" id="list" lay-filter="list"></table>
  21. </div>
  22. </div>
  23. <script type="text/html" id="action">
  24. <a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-xs" lay-event="edit">{:lang('edit')}</a>
  25. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
  26. </script>
  27. <script type="text/html" id="status">
  28. <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
  29. </script>
  30. <script type="text/html" id="sex">
  31. {{# if(d.sex==1){ }}
  32. {{# }else if( d.sex==2){ }}
  33. {{# }else{ }}
  34. 保密
  35. {{# } }}
  36. </script>
  37. <script type="text/html" id="avatar">
  38. {{d.avatar}}<img src="/static/admin/images/image.gif" onmouseover="layer.tips('<img src={{d.avatar}}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();">
  39. </script>
  40. <script type="text/html" id="last_login">
  41. {{layui.util.toDateString(d.last_login*1000, 'yyyy-MM-dd HH:mm:ss')}}
  42. </script>
  43. <script type="text/html" id="create_time">
  44. {{layui.util.toDateString(d.create_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
  45. </script>
  46. <script type="text/html" id="update_time">
  47. {{layui.util.toDateString(d.update_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
  48. </script>
  49. <script type="text/html" id="toolbar">
  50. <div class="layui-btn-container">
  51. <!-- <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>-->
  52. <!-- <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
  53. <!-- <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
  54. </div>
  55. </script>
  56. {include file="common/footer"/}
  57. <script>
  58. layui.use(['form', 'table'], function () {
  59. var $ = layui.jquery,
  60. form = layui.form,
  61. table = layui.table;
  62. var tableIn = table.render({
  63. elem: '#list',
  64. url: '{:url("index")}',
  65. method: 'post',
  66. title: '用户数据表',
  67. toolbar: '#toolbar', //开启头部工具栏,并为其绑定左侧模板
  68. defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可
  69. title: '提示'
  70. ,layEvent: 'LAYTABLE_TIPS'
  71. ,icon: 'layui-icon-tips' }],
  72. cols: [[
  73. {checkbox: true, fixed: true},
  74. {field: 'id', title: 'ID', width: 80, fixed: true, sort: true},
  75. {field: 'username', title: '名字', width: 120,},
  76. {field: 'email', title: '邮箱', width: 120, },
  77. {field: 'mobile', title: '手机', width: 120, },
  78. {field: 'sex', title: '性别', width: 120, templet:"#sex"},
  79. {field: 'level_name', title: '会员等级', width: 120, },
  80. {field: 'avatar', title: '头像', width: 120,templet:"#avatar" },
  81. // {field: 'store_id', title: '店铺id', width: 120,sort: true},
  82. {field: 'status', title: '状态', width: 180, templet:'#status'},
  83. {field: 'create_time', title: '注册时间', width: 180,templet:'#create_time'},
  84. {field: 'update_time', title: '更新时间', width: 180,templet:'#update_time'},
  85. {field: 'last_login', title: '最后登录时间', width: 180,templet:'#last_login'},
  86. {title:'操作',width:150, toolbar: '#action',align:"center"},
  87. ]],
  88. limits: [10, 15, 20, 25, 50, 100],
  89. limit: 15,
  90. page: true
  91. });
  92. table.on('tool(list)', function(obj){
  93. var data = obj.data;
  94. if(obj.event === 'del'){
  95. layer.confirm('{:lang("Are you sure you want to delete it")}', function(index){
  96. loading =layer.load(1, {shade: [0.1,'#fff']});
  97. $.post("{:url('delete')}",{id:data.id},function(res){
  98. layer.close(loading);
  99. layer.close(index);
  100. if(res.code>0){
  101. layer.msg(res.msg,{time:1000,icon:1});
  102. obj.del();
  103. }else{
  104. layer.msg(res.msg,{time:1000,icon:2});
  105. }
  106. });
  107. });
  108. }
  109. });
  110. form.on('switch(status)', function(data){
  111. loading =layer.load(1, {shade: [0.1,'#fff']});
  112. $.post("{:url('state')}",{id:data.value},function(res){
  113. layer.close(loading);
  114. if(res.code>0){
  115. layer.msg(res.msg,{time:1000,icon:1});
  116. }else{
  117. layer.msg(res.msg,{time:1000,icon:2});
  118. }
  119. });
  120. });
  121. $('#search').click(function () {
  122. var $keys = $('#keys').val();
  123. if(!$keys){
  124. return layer.msg('请输入关键词');
  125. }
  126. tableIn.reload({ page: {page: 1},where: {keys: $keys}});
  127. })
  128. $('#delAll').click(function(){
  129. layer.confirm("{:lang('Are you sure you want to delete it')}", {icon: 3}, function(index) {
  130. layer.close(index);
  131. var checkStatus = table.checkStatus('list'); //test即为参数id设定的值
  132. var ids = [];
  133. console.log(checkStatus.data)
  134. $(checkStatus.data).each(function (index, item) {
  135. ids.push(item.id);
  136. });
  137. if(ids==''){
  138. layer.msg("{:lang('please choose data')}", {time: 1000, icon: 2});
  139. return false;
  140. }
  141. var loading = layer.load(1, {shade: [0.1, '#fff']});
  142. $.post("{:url('delAll')}", {ids: ids}, function (res) {
  143. layer.close(loading);
  144. if (res.code > 0) {
  145. layer.msg(res.msg, {time: 1000, icon: 1});
  146. tableIn.reload();
  147. } else {
  148. layer.msg(res.msg, {time: 1000, icon: 2});
  149. }
  150. });
  151. });
  152. })
  153. });
  154. </script>