<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>user-add</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
        <link rel="stylesheet" href="{*cdn*}css/font.css">
        <link rel="stylesheet" href="{*cdn*}css/xadmin.css">
        <script type="text/javascript" src="{*cdn*}lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="{*cdn*}js/xadmin.js"></script>
        <!-- 让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="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                  <div class="layui-form-item">
                      <label for="name" class="layui-form-label">
                          <span class="x-red">*</span>{*locale['dashboard.menu.user_manage.form.user_edit.name']*}
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" name="name" value="{*user.name*}" lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>{*locale['dashboard.menu.user_manage.form.user_edit.name.notice']*}
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>{*locale['dashboard.menu.user_manage.form.user_edit.username']*}
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" name="username" value="{*user.username*}" lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>{*locale['dashboard.menu.user_manage.form.user_edit.username.notice']*}
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="password" class="layui-form-label">
                          <span class="x-red">*</span>{*locale['dashboard.menu.user_manage.form.user_edit.password']*}
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" name="password" lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>{*locale['dashboard.menu.user_manage.form.user_edit.password.notice']*}
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label">
                        <span class="x-red">*</span>{*locale['dashboard.menu.user_manage.form.user_edit.role']*}</label>
                      <div class="layui-input-inline">
                        <select lay-verify="required" name="role">
                          <option value=""></option>
                          {% if roles and type(roles) == 'table' then%}
                            {% for _, role in ipairs(roles) do %}
                              {% if user.role ~= role.id  then%}
                                <option value="{*role.id*}">{*role.name*}</option>
                              {% else %}
                                <option value="{*role.id*}" selected="">{*role.name*}</option>
                              {% end %}
                            {% end %}
                          {% end %}
                        </select>
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="phone" class="layui-form-label">
                          <span class="x-red">*</span>{*locale['dashboard.menu.user_manage.form.user_edit.phone']*}
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" name="phone" value="{*user.phone*}" lay-verify="required|phone" autocomplete="off" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="email" class="layui-form-label">
                          <span class="x-red">*</span>{*locale['dashboard.menu.user_manage.form.user_edit.email']*}
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" name="email" value="{*user.email*}" lay-verify="required|email" autocomplete="off" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item layui-hide">
                      <div class="layui-input-inline">
                          <input type="text" name="action" value="edit">
                      </div>
                  </div>
                  <div class="layui-form-item layui-hide">
                      <div class="layui-input-inline">
                          <input type="text" name="token" value="{*token*}">
                      </div>
                  </div>
                  <div class="layui-form-item layui-hide">
                      <div class="layui-input-inline">
                          <input type="text" name="id" value="{*user.id*}">
                      </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <button id="submit" class="layui-btn" lay-filter="edit" lay-submit="">{*locale['dashboard.menu.user_manage.form.submit']*}</button>
                  </div>
              </form>
            </div>
        </div>
        <script>
        layui.use(['jquery', 'form', 'layer'], function() {
            var $ = layui.jquery;
            var form  = layui.form;
            var layer = layui.layer;
            //监听提交
            form.on('submit(edit)', function(data) {
              if (!$('#submit').is(":hidden")) {
                $('#submit').hide();
                $.ajax({
                  url: "{*api_url*}", type: "POST", headers: {token:"{*token*}"}, data: data.field,
                  error: function (res) {
                    return layer.msg('请求失败', {time:2000}, function () {
                      $('#submit').show();
                    });
                  },
                  success: function (res) {
                    if (res.code != 0) {
                      return layer.msg(res.msg, {time:2000}, function () {
                        $('#submit').show();
                      });
                    }
                    return layer.msg(res.msg, {time:1000}, function () {
                      xadmin.close();
                      xadmin.father_reload();
                    });
                  },
                })
              }
              return false;
            });
        });
          </script>
    </body>

</html>
