let form;
layui.use(['element', 'form', 'table', 'layer', 'laydate', 'tree', 'dict', 'dtree'], function () {
    let layDate = layui.laydate;
    form = layui.form;
    layui.dict.setData('dict-secret-level', current_user);

    //日期选择器
    layDate.render({
        elem: '#expiredTimeDate',
        format: "yyyy-MM-dd HH:mm:ss"
    });
})




/**
 * 提交保存
 */
function save() {
    let userForm = $("#userForm").serializeObject();
    if(userForm.userId === user.userId){
        layer.alert('该操作包含数据权限等危险操作，所以您不能直接修改自己的用户数据，请联系您的上级主管', {icon:2})
        return false;
    }
    if(userForm.secretLevel > user.secretLevel){
        layer.alert('无法为用户设置超过自身涉密等级的权限，您的涉密等级为【'+ DICT.getText('secret_level', user.secretLevel) +'】', {icon:2})
        return;
    }
    form.on('submit(userForm)', function(){
        $.post(ctx + "/sys/sysUser/save", userForm, function (data) {
            if (!data.flag) {
                layer.msg(data.msg, {icon: 2, time: 2000}, function () {
                });
                return;
            }
            layer.msg("保存成功", {icon: 1, time: 2000}, function () {
                let index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            });
        });
        return false; //阻止表单跳转。使用下面的post方式提交
    });

    $("#btn_submit").click();
}