edit.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
  2. <form class="layui-form" action="" method="post" >
  3. <div class="layui-form-item">
  4. <label class="layui-form-label">登录账号</label>
  5. <div class="layui-input-inline">
  6. <input type="text" name="login_name" readonly id="login_name" lay-verify="required" autocomplete="off" placeholder="登录账号" class="layui-input" value="{{.admin.login_name}}">
  7. </div>
  8. <div class="layui-form-mid layui-word-aux">*登录不允许修改</div>
  9. </div>
  10. <div class="layui-form-item">
  11. <label class="layui-form-label">真实姓名</label>
  12. <div class="layui-input-inline">
  13. <input type="text" name="real_name" id="real_name" lay-verify="required" autocomplete="off" placeholder="真实姓名" class="layui-input" value="{{.admin.real_name}}">
  14. </div>
  15. <div class="layui-form-mid layui-word-aux">*</div>
  16. </div>
  17. <div class="layui-form-item">
  18. <label class="layui-form-label">手机号码</label>
  19. <div class="layui-input-inline">
  20. <input type="text" name="phone" lay-verify="phone|required" autocomplete="off" placeholder="手机号码" class="layui-input" value="{{.admin.phone}}">
  21. </div>
  22. <div class="layui-form-mid layui-word-aux">*</div>
  23. </div>
  24. <div class="layui-form-item">
  25. <label class="layui-form-label">电子邮箱</label>
  26. <div class="layui-input-inline">
  27. <input type="text" name="email" id="email" lay-verify="email" autocomplete="off" placeholder="电子邮箱" class="layui-input" value="{{.admin.email}}">
  28. </div>
  29. <div class="layui-form-mid layui-word-aux">*</div>
  30. </div>
  31. <div class="layui-form-item">
  32. <label class="layui-form-label">重置密码</label>
  33. <div class="layui-input-inline">
  34. <input type="radio" name="reset_pwd" value="1" title="重置">
  35. <input type="radio" name="reset_pwd" value="2" title="不重置" checked>
  36. </div>
  37. <div class="layui-form-mid layui-word-aux">默认密码:george518</div>
  38. </div>
  39. <div class="layui-form-item">
  40. <label class="layui-form-label">选择角色</label>
  41. <div class="layui-input-block">
  42. {{range $k, $v := .role}}
  43. <input type="checkbox" name="role_ids" lay-filter="role_ids" title="{{$v.role_name}}" value="{{$v.id}}" {{if $v.checked}}checked{{end}}>
  44. {{end}}
  45. </div>
  46. <div class="layui-form-mid layui-word-aux">*</div>
  47. </div>
  48. <input type="hidden" id="roleids" name="roleids" value="{{.admin.role_ids}}">
  49. <input type="hidden" id="id" name="id" value="{{.admin.id}}">
  50. <div class="layui-form-item">
  51. <div class="layui-input-block">
  52. <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
  53. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  54. </div>
  55. </div>
  56. </form>
  57. </div>
  58. <script>
  59. var $;
  60. layui.config({
  61. base : "js/"
  62. }).use(['form','element','layer','jquery'],function(){
  63. var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
  64. var $ = layui.jquery;
  65. var role_ids_str = "{{.admin.role_ids}}"
  66. var role_ids = role_ids_str.split(",");
  67. form.on('checkbox(role_ids)', function(data){
  68. if(data.elem.checked==true){
  69. role_ids.push(data.value)
  70. }else{
  71. $.each(role_ids,function(index,item){
  72. // index是索引值(即下标) item是每次遍历得到的值;
  73. if(item==data.value){
  74. role_ids.splice(index,1);
  75. }
  76. });
  77. }
  78. $("#roleids").val(role_ids.join(","));
  79. });
  80. form.on('submit(sub)', function(data){
  81. var form_data = $("form").serialize();
  82. $.post('{{urlfor "AdminController.AjaxSave"}}', form_data, function (out) {
  83. if (out.status == 0) {
  84. layer.msg("操作成功",{icon: 1},function () {
  85. window.location.reload()
  86. })
  87. } else {
  88. layer.msg(out.message)
  89. }
  90. }, "json");
  91. return false;
  92. });
  93. //但是,如果你的HTML是动态生成的,自动渲染就会失效
  94. //因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
  95. form.render();
  96. });
  97. </script>