<!DOCTYPE html>
<html>
  <head>
    @include('admin.common_bak.header')
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="x-body">
        <form class="layui-form">
          <input type="hidden" name="id" value="{{$manager['id']}}">
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>登录名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" value="{{$manager['name']}}" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为您唯一的登入名
              </div>
          </div>
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  <span class="x-red">*</span>手机
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="phone" name="mobile" value="{{$manager['mobile']}}" required="" lay-verify="phone"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span>邮箱
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="L_email" name="email" value="{{$manager['email']}}" required="" lay-verify="email"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label"><span class="x-red">*</span>角色</label>
              <div class="layui-input-block">
                @foreach($roles as $v)
                <input type="radio" name="role_id" lay-skin="primary" value="{{$v['id']}}" title="{{$v['name']}}" @if(in_array($v['id'],$manager['role'])) checked @endif>
                @endforeach
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" id="sub" lay-filter="add" lay-submit="">
                  增加
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            }
          });

          //监听提交
          form.on('submit(add)', function(data){
            var aa = layer.load(1);
            //发异步，把数据提交给php
            var formdata = new FormData(data.form);
            $('#sub').attr('disabled','disabled').css({'background':'#d4d4d4'});
            fetch_response('POST',"/web/manager_edit/{{$manager['id']}}",formdata).then(function(res){
              if(res.code==200){
                layer.close(aa);
                layer.alert("修改成功", {icon: 6},function () {
                    window.parent.location.reload(); //刷新父页面
                    var index = parent.layer.getFrameIndex(window.name);// 获得frame索引
                    parent.layer.close(index);//关闭当前frame
                });
              }else{
                layer.close(aa);
                layer.msg(res.msg,{icon:5});
                $('#sub').removeAttr('disabled').css('background','#009688');
              }
            });
            return false;
          });
          
        });
    </script>
  </body>

</html>