JQuery 修改用戶信息

JQuery 修改用戶信息,多項選擇,賦值,框架: https://www.h-ui.net/v3.shtml

$(data.data.roleList).each(function (i, val) {
    $('input[type="checkbox"][name="doctorRole"]').each(function () {
        if (this.value == val.roleCode) {
            this.checked = true;
        }
    });
})
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>添加醫生</title>
</head>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-doctor-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>工號:</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="doctorNo" name="doctorNo">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>姓名:</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="doctorName" name="doctorName">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">性別:</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input type="radio" name="sex" value="1" id="sex-1" checked>
                    <label for="sex-1">男</label>
                </div>
                <div class="radio-box">
                    <input type="radio" name="sex" value="2" id="sex-2">
                    <label for="sex-2">女</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">手機:</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="phone" name="phone">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色:</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="check-box">
                    <input type="checkbox" id="chkAnalysis" name="doctorRole" value="analysis">
                    <label for="chkAnalysis">分析員</label>
                </div>
                <div class="check-box">
                    <input type="checkbox" id="chkAudit" name="doctorRole" value="audit">
                    <label for="chkAudit">審覈員</label>
                </div>
                <div class="check-box">
                    <input type="checkbox" id="chkReview" name="doctorRole" value="review">
                    <label for="chkReview">複覈員</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                <input type="hidden" id="hidId" value=""/>
            </div>
        </div>
    </form>
</article>

<!--_footer 作爲公共模版分離出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="style/js/config.js"></script>
<script type="text/javascript" src="style/js/common.js"></script>
<!--/_footer 作爲公共模版分離出去-->

<!--請在下方寫此頁面業務相關的腳本-->
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function () {
        if ($.cookie('LoginUser') === undefined) {
            top.location = 'login.html';
        }
 
        var queryString = window.location.search;
        var params = {};

        if (queryString) {
            var pairs = queryString.split('&');
            for (var i = 0; i < pairs.length; i++) {
                var pair = pairs[i].split('=');
                if(pair.length>0){
                    params[pair[0].replace('?','')] = pair[1];
                }
            }
        }
        if (params.doctorNo != null) {
            getDoctorInfo(params);
        }

        function getDoctorInfo(params) {
            var mask;
            $.ajax({
                url: GLOBAL_CONFIG.HOST + "/admin/getUser",
                type: 'post',
                dataType: 'json',
                contentType: "application/json;charset=utf-8",
                headers: {
                    'SecretKey': GLOBAL_APPCONFIG.AppId
                },
                data: JSON.stringify(params),
                beforeSend: function (XMLHttpRequest) {
                    mask = layer.msg("數據獲取中....", {icon: 16, time: 60000, shade: 0.1});
                },
                success: function (data) {
                    $("#hidId").val(data.data.id);
                    $("#doctorNo").val(data.data.doctorNo);
                    $("#doctorName").val(data.data.doctorName);
                    $("#phone").val(data.data.phoneNo);
                    $("input:radio[name='sex'][value='" + data.data.sex + "']").attr('checked', true);
                    //if (data.data.sex == 1) {
                    //    $("#sex-1").attr("checked", true);
                    //}
                    //else {
                    //    $("#sex-2").attr("checked", true);
                    //}
                    $(data.data.roleList).each(function (i, val) {
                        $('input[type="checkbox"][name="doctorRole"]').each(function () {
                            if (this.value == val.roleCode) {
                                this.checked = true;
                            }
                        });
                    })
                    layer.close(mask);
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    layer.msg('error!', {icon: 1, time: 1000});
                }
            });
        }

        //這個要去掉,不然修改時選不中
        //$('.skin-minimal input').iCheck({
        //    checkboxClass: 'icheckbox-blue',
        //   radioClass: 'iradio-blue',
        //   increaseArea: '20%'
        //});

        $("#form-doctor-add").validate({
            rules: {
                doctorNo: {
                    required: true,
                    minlength: 3,
                    maxlength: 16
                },
                doctorName: {
                    required: true,
                    minlength: 2,
                    maxlength: 16
                },
                doctorRole: {
                    required: true,
                },
                phone: {
                    isPhone: true,
                },
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function (form) {
                var userRoleList = new Array();
                $('input[type="checkbox"][name="doctorRole"]').each(function () {
                    if (this.checked) {
                        var userRole = {}
                        var val = $(this).val();
                        userRole.roleCode = val;
                        userRoleList.push(userRole);
                    }
                });

                var obj = {};
                obj.id = $("#hidId").val().trim();
                obj.doctorNo = $("#doctorNo").val().trim();
                obj.doctorName = $("#doctorName").val().trim();
                obj.sex = $("input[name='sex']:checked").val();
                obj.phoneNo = $("#phone").val().trim();
                obj.roleList = userRoleList;

                //$(form).ajaxSubmit({
                $.ajax({
                    url: GLOBAL_CONFIG.HOST + "/admin/addDoctor",
                    type: 'post',
                    dataType: 'json',
                    contentType: "application/json;charset=utf-8",
                    headers: {
                        'SecretKey': GLOBAL_APPCONFIG.AppId
                    },
                    data: JSON.stringify(obj),
                    beforeSend: function (XMLHttpRequest) {
                        layer.msg("數據提交中....", {icon: 16, time: 60000, shade: 0.1});
                    },
                    success: function (data) {
                        if (data.code != 1) {
                            layer.msg(data.message, {icon: 2, time: 2000});
                        }
                        else{
                            layer.msg('保存成功!', {icon: 1, time: 3000});
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.list_doctor(); //調用父頁的 刷新列表方法
                            parent.layer.close(index); //關閉當前彈框
                        }
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        layer.msg('error!', {icon: 1, time: 1000});
                    }
                });
            }
        });
    });
</script>
<!--/請在上方寫此頁面業務相關的腳本-->
</body>
</html>
{
  "id": "25465bcb-a9b4-4785-9caf-8ca9561fd61e",
  "doctorNo": "123",
  "pwd": "b095c7cfa04f19a9c8bce5f2590a035c",
  "doctorName": "456",
  "sex": 2,
  "phoneNo": "13666666",
  "deptName": null,
  "jobTitle": null,
  "isSuperAdmin": 0,
  "remark": null,
  "createTime": "2023-12-25T07:36:05.000+00:00",
  "updateTime": null,
  "isDeleted": 0,
  "status": 1,
  "roleList": [
    {
      "id": "a9994936-c06d-4ed5-ae72-0cfa91270a59",
      "doctorNo": "123",
      "roleId": null,
      "roleCode": "analysis",
      "roleName": "分析員",
      "remark": null,
      "createTime": "2023-12-25T07:37:06.000+00:00",
      "updateTime": null,
      "isDeleted": 0,
      "status": 1
    },
    {
      "id": "ea33f4bd-08ae-4eb5-b497-f18c1fa8c802",
      "doctorNo": "123",
      "roleId": null,
      "roleCode": "review",
      "roleName": "複覈員",
      "remark": null,
      "createTime": "2023-12-25T07:37:06.000+00:00",
      "updateTime": null,
      "isDeleted": 0,
      "status": 1
    }
  ],
  "newPwd": null
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章