{{include "com/inc.html"}}
<!-- Main Header -->
{{include "com/header.html"}}
<!-- Left side column. 权限菜单 -->
{{include "com/menu.html"}}
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            <small></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 用户组管理</a></li>
            <li><a href="/front/group"><i class="fa fa-dashboard"></i> 用户组管理</a></li>
            <li><a href="/front/group/new"><i class="fa fa-dashboard"></i> 用户组新增</a></li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <form class="form-horizontal" onsubmit="return false;">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <i class="fa fa-group"></i>
                    <h3 class="box-title">用户组信息</h3>
                </div>
                <div class="box-body">
                    <div class="form-group" style="text-align: right;margin-right: 20px" >
<!--                        <a class="btn btn-sm btn-success" onclick="addMember()"><i class="fa fa-fw fa-plus fa-lg"></i>添加成员信息</a>-->
                    </div>
                    <div class="form-group margin-bottom">
                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>用户组名称</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="group-name" placeholder="用户组名称" required>
                        </div>
                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>公司名称</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="company-name" placeholder="公司名称" required>
                        </div>
                    </div>
                    <div class="form-group margin-bottom">
                        <label class="col-sm-2 control-label">负责人</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="leader" placeholder="负责人名称">
                        </div>
                        <label class="col-sm-2 control-label">联系方式</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="contract" placeholder="联系方式：电话/邮箱">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">登陆密码</label>
                        <div class="col-sm-2">
                            <input type="password" id="group-pwd" readonly="readonly" class="form-control" placeholder="手动输入密码">
                        </div>
                        <div class="col-sm-2">
                            <label class="col-sm-5 control-label" style="font-size: xx-small;width: auto">默认密码：</label>
                            <input id="group-switch-pwd" name="switch-pwd" type="checkbox">
                        </div>
                        <label class="col-sm-1 control-label">服务时间</label>
                        <div class="col-sm-3">
                            <input type="text" id="stratDate" class="col-sm-2 form-control" readonly="readonly" placeholder="开始日期 - 结束日期">
                        </div>
                    </div>

                    <div class="box-body">
                        <div class="box-header with-border margin-bottom">
                            <i class="fa fa-user"></i>
                            <h3 class="box-title">质检员信息</h3>
                        </div>
                        <h1></h1>
                        <div class="form-group margin-bottom">
                            <label class="col-sm-2 control-label">用户账号</label>
                            <div class="col-sm-2">
                                <input type="text" readonly="readonly" class="form-control" placeholder="默认用户组名称+zj+数字">
                            </div>
                            <label class="col-sm-1 control-label">用户个数(个)</label>
                            <div class="col-sm-1">
                                <input type="number" id="u1-size" class="form-control" value="1" oninput="if(value<0)value=0;if(value>10)value=10">
                            </div>
                            <label class="col-sm-1 control-label">登陆密码</label>
                            <div class="col-sm-2">
                                <input type="password" id="u1-pwd" readonly="readonly" class="form-control" placeholder="手动输入密码">
                            </div>
                            <div class="col-sm-2">
                                <label class="col-sm-5 control-label" style="font-size: xx-small;width: auto">默认密码：</label>
                                <input id="u1-switch-pwd" name="switch-pwd" type="checkbox">
                            </div>
                        </div>
                        <div class="form-group margin-bottom">
                            <label class="col-sm-2 control-label">用户状态</label>
                            <div class="col-sm-3">
                                <input id="u1-switch-state" name="switch-state" type="checkbox">
                            </div>
                        </div>
                    </div>

                    <div class="box-body">
                        <div class="box-header with-border margin-bottom">
                            <i class="fa fa-user"></i>
                            <h3 class="box-title">成员信息</h3>
                        </div>
                        <h1></h1>
                        <div class="form-group margin-bottom">
                            <label class="col-sm-2 control-label">用户账号</label>
                            <div class="col-sm-2">
                                <input type="text" readonly="readonly" class="form-control" placeholder="默认用户组名称+数字">
                            </div>
                            <label class="col-sm-1 control-label">用户个数(个)</label>
                            <div class="col-sm-1">
                                <input type="number" id="u2-size" class="form-control" value="1" oninput="if(value<0)value=0;if(value>30)value=30">
                            </div>
                            <label class="col-sm-1 control-label">登陆密码</label>
                            <div class="col-sm-2">
                                <input type="password" readonly="readonly" id="u2-pwd" class="form-control" placeholder="手动输入密码">
                            </div>
                            <div class="col-sm-2">
                                <label class="col-sm-5 control-label" style="font-size: xx-small;width: auto">默认密码：</label>
                                <input name="switch-pwd" id="u2-switch-pwd" type="checkbox">
                            </div>
                        </div>
                        <div class="form-group margin-bottom">
                            <label class="col-sm-2 control-label">用户状态</label>
                            <div class="col-sm-3">
                                <input id="u2-switch-state" name="switch-state" type="checkbox">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="text-center">
                    <button class="btn btn-lg btn-success" onclick="saveMethod()">保存</button>
                </div>
                <hr>
            </div>
        </form>
    </section>
</div>
{{include "com/footer.html"}}
<script>
    menuActive("group");
    let group = {}
    let user = {}

    $(document).ready(function () {
        $("#group-pwd").val({{.T.pwd}})
        $("#u1-pwd").val({{.T.pwd}})
        $("#u2-pwd").val({{.T.pwd}})
    })

    $("[name='switch-state']").each(function () {
        $(this).bootstrapSwitch({
            onText : "开",      // 设置ON文本
            offText : "关",    // 设置OFF文本
            onColor : "success",// 设置ON文本颜色(info/success/warning/danger/primary)
            offColor : "primary",  // 设置OFF文本颜色 (info/success/warning/danger/primary)
        }).bootstrapSwitch('size', 'small').bootstrapSwitch('state', true);
    })
    $("[name='switch-pwd']").each(function () {
        $(this).bootstrapSwitch({
            onText : "是",
            offText : "否",
            onColor : "success",
            offColor : "warning",
        }).bootstrapSwitch('size', 'small').bootstrapSwitch('state', true);
    })
    // 用户组状态
    $("#group-switch-state").bootstrapSwitch('onSwitchChange', function (event, state){group['state'] = state})
    // 用户组登陆密码
    $("#group-switch-pwd").bootstrapSwitch(
        'onSwitchChange', function (event, state){
            group["default_pwd"] = state
            if (state===true) {
                $("#group-pwd").attr('readonly', 'readonly').val("xxx")
            }else {
                $("#group-pwd").removeAttr('readonly').val("")
            }
        }
    )
    // 用户登陆密码
    $("#u1-switch-pwd").bootstrapSwitch(
        'onSwitchChange', function (event, state){
            user["u1_default_pwd"] = state
            if (state===true) {
                $("#u1-pwd").attr('readonly', 'readonly').val({{.T.pwd}})
            }else {
                $("#u1-pwd").removeAttr('readonly').val("")
            }
        }
    )
    $("#u2-switch-pwd").bootstrapSwitch(
        'onSwitchChange', function (event, state){
            user["u2_default_pwd"] = state
            if (state===true) {
                $("#u2-pwd").attr('readonly', 'readonly').val({{.T.pwd}})
            }else {
                $("#u2-pwd").removeAttr('readonly').val("")
            }
        }
    )
    // 用户状态
    $("#u1-switch-state").bootstrapSwitch('onSwitchChange', function (event, state){user["u1_state"] = state})
    $("#u2-switch-state").bootstrapSwitch('onSwitchChange', function (event, state){user["u2_state"] = state})
    // $("#stratDate").datepicker({
    //     language: 'zh-CN',
    //     autoclose: true,
    //     clearBtn: true,
    //     format: "yyyy-mm-dd"
    // });

    function saveMethod() {

        const gname = $("#group-name").val();
        const company = $("#company-name").val()
        if (gname == null || company == null) {
            return
        }
        group["s_name"] = gname
        group["s_entname"] = company
        group["s_personname"] = $("#leader").val()
        group["s_personcontact"] = $("#contract").val()
        group["s_password"] = $("#group-pwd").val()
        user["u1_size"] = $("#u1-size").val()
        user["u1_pwd"] = $("#u1-pwd").val()
        user["u2_size"] = $("#u2-size").val()
        user["u2_pwd"] = $("#u2-pwd").val()

        console.log(group)
        console.log(user)
        $.ajax({
            url: "/front/group/new",
            type: 'POST',
            data: {"group": JSON.stringify(group), "user": JSON.stringify(user)},
            success: function (r) {
                if (r.rep) {
                    window.location.href="/front/group"
                } else {
                    showTip("保存失败");
                }
            }
        })
    }
</script>
