From 3dcb4e0ebfd43190957f556d886917b2a2ffa064 Mon Sep 17 00:00:00 2001
From: zhaoxiaohao <913652501@qq.com>
Date: Wed, 12 Aug 2020 18:45:30 +0800
Subject: [PATCH] 修改上传图片的接口

---
 kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/doctor_form.html |  291 +++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 166 insertions(+), 125 deletions(-)

diff --git a/kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/doctor_form.html b/kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/doctor_form.html
index ece5883..51edbe0 100644
--- a/kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/doctor_form.html
+++ b/kidgrow-web/kidgrow-web-manager/src/main/resources/static/pages/opration/doctor_form.html
@@ -8,6 +8,7 @@
                     <input name="hospitalName" id="hospitalName" placeholder="请输入医院名称" type="text" class="layui-input"
                         maxlength="50" lay-verify="required" required style="width: 150px;" />
                     <input type="hidden" name="hospitalId" id="hospitalId" />
+                    <input type="hidden" name="id" id="id" />
                 </div>
             </div>
             <div class="layui-inline">
@@ -31,14 +32,6 @@
                     </select>
                 </div>
             </div>
-
-            <!-- </div>
-        <div class="layui-form-item"> -->
-
-            <!-- </div>
-
-        <div class="layui-form-item"> -->
-
         </div>
     </div>
     <div style="display:flex">
@@ -61,19 +54,12 @@
                 </div>
             </div>
             <div class="layui-inline">
-                <label class="layui-form-label">角色</label>
+                <label class="layui-form-label">Email</label>
                 <div class="layui-input-block" style="width: 150px;">
-                    <select name="roleId" xm-select="roleId" lay-verify="required">
-                    </select>
+                    <input name="doctorEmail" type="text" class="layui-input" maxlength="20" lay-verify="required|email"
+                        required />
                 </div>
             </div>
-
-            <!-- </div>
-        <div class="layui-form-item"> -->
-
-            <!-- </div>
-        <div class="layui-form-item"> -->
-
         </div>
     </div>
     <div style="display:flex">
@@ -91,11 +77,11 @@
                     <input name="doctorOtherLink" type="text" class="layui-input" maxlength="20" />
                 </div>
             </div>
-            <div class="layui-inline">
-                <label class="layui-form-label">Email</label>
+            <div class="layui-inline" id="roleId_div">
+                <label class="layui-form-label">角色</label>
                 <div class="layui-input-block" style="width: 150px;">
-                    <input name="doctorEmail" type="text" class="layui-input" maxlength="20" lay-verify="required|email"
-                        required />
+                    <select name="roleId" xm-select="roleId">
+                    </select>
                 </div>
             </div>
         </div>
@@ -143,27 +129,24 @@
             </div>
         </div>
     </div>
-    <div style="display:flex">
+    <div style="display:flex" class="account">
         <div class="layui-form-item">
             <div class="layui-inline">
                 <label class="layui-form-label">登录帐号</label>
                 <div class="layui-input-block" style="width: 150px;">
-                    <input name="username" id="username" readonly type="text" class="layui-input" maxlength="20"
-                        lay-verify="required" required />
+                    <input name="username" id="username" readonly type="text" class="layui-input" maxlength="20" />
                 </div>
             </div>
-            <div class="layui-inline">
+            <div class="layui-inline" id="password_div">
                 <label class="layui-form-label">登录密码</label>
                 <div class="layui-input-block" style="width: 150px;">
-                    <input name="password" type="password" lay-verify="required" class="layui-input" maxlength="20"
-                        lay-verify="required|phone" required />
+                    <input name="password" type="password" id="password" class="layui-input" maxlength="20" />
                 </div>
             </div>
-            <div class="layui-inline">
+            <div class="layui-inline" id="passwordSure_div">
                 <label class="layui-form-label">确认密码</label>
                 <div class="layui-input-block" style="width: 150px;">
-                    <input name="passwordSure" type="password" lay-verify="required|confirmPass" class="layui-input"
-                        maxlength="20" />
+                    <input name="passwordSure" type="password" id="passwordSure" class="layui-input" maxlength="20" />
                 </div>
             </div>
 
@@ -228,8 +211,11 @@
         var formSelects = layui.formSelects;
         var $ = layui.jquery;
 
+
+        //医生管理员
+        var guanliyuan_role = undefined;
         //获取角色
-        var get_role = function () {
+        var get_role = function (flag) {
             admin.req('api-user/findByMap?tenant_id=hospital', {}, function (data) {
                 layer.closeAll('loading');
                 if (0 == data.code) {
@@ -241,29 +227,33 @@
                             value: data.data[i].id
                         });
                     }
+                    guanliyuan_role = data.data[0].id;
                     formSelects.data('roleId', 'local', {
                         arr: roleSelectData
                     });
-
                     // 回显user数据
-                    var user = admin.getTempData('t_user');
-                    $('#user-form').attr('method', 'POST');
-                    if (user) {
-                        form.val('user-form', user);
-                        $('#user-form').attr('method', 'POST');
-                        var rds = new Array();
-                        for (var i = 0; i < user.roles.length; i++) {
-                            rds.push(user.roles[i].id);
-                        }
-                        formSelects.value('roleId', rds);
+                    var doctor = admin.getTempData('t_doctor');
+                    if (doctor!=null&&doctor.roles) {
+                        formSelects.value('roleId', doctor.roles);
                     }
+
                 } else {
                     layer.msg('获取角色失败', {
                         icon: 2,
-                        time: 500
+                        time: 2000
                     });
                 }
             }, 'GET');
+        }
+        /*
+        * 验证手机号码
+        */
+        function validatorTel(content) {
+
+            // 正则验证格式
+            eval("var reg = /^1[34578]\\d{9}$/;");
+            var flag = RegExp(reg).test(content)
+            return flag;
         }
         //判断用户名是否被使用
         var username_is_usered = function (username_id) {
@@ -274,100 +264,53 @@
                 if (data.code == 0) {
                     if (data.data > 0) {
                         $("#" + username_id).val("")
-                        layer.msg("该登录帐号已经使用", {
+                        layer.msg("该手机号已经使用", {
                             icon: 2,
-                            time: 500
+                            time: 2000
                         })
                     }
                 } else {
                     layer.msg(data.msg, {
                         icon: 2,
-                        time: 500
+                        time: 2000
                     });
                 }
             }, 'post');
         }
-        // // 显示编辑弹窗
-        // var showEditModel = function (data, flag) {
-        //     var title = "";
-        //     if (flag == 1) {
-        //         title = "查看详情";
-        //     } else if (flag == 2) {
-        //         title = "新增";
-        //     } else if (flag == 3) {
-        //         title = "编辑";
-        //     }
 
-        //     layer.open({
-        //         type: 1,
-        //         title: title,
-        //         area: '650px',
-        //         offset: '120px',
-        //         content: $('#app-model').html(),
-        //         success: function () {
-        //             $('#app-form')[0].reset();
-        //             $('#app-form').attr('method', 'POST');
-        //             //将医院的数据保存到下拉表
-        //             let selected = false;
-        //             //将科室的数据绑定到里面
-        //             if (flag != 2) {
-        //                 getdepartment(data.hospitalId);
-        //             }
-        //             if (data) {
-        //                 if (data.isAnswer) {
-        //                     $("#isAnswer-shi").attr('checked', true);
-        //                 } else {
-        //                     $("#isAnswer-fou").attr('checked', true);
-        //                 }
 
-        //                 if (data.isSigning) {
-        //                     $("#isSigning-shi").attr('checked', true);
-        //                 } else {
-        //                     $("#isSigning-fou").attr('checked', true);
-        //                 }
-
-        //                 if (data.isTop) {
-        //                     $("#isTop-shi").attr('checked', true);
-        //                 } else {
-        //                     $("#isTop-fou").attr('checked', true);
-        //                 }
-
-        //                 if (data.doctorState) {
-        //                     $("#doctorState-shi").attr('checked', true);
-        //                 } else {
-        //                     $("#doctorState-fou").attr('checked', true);
-        //                 }
-        //                 form.val('app-form', data);
-        //                 if (flag == 1) {
-        //                     //将确定隐藏  doctorState-shi
-        //                     $("#sure").hide();
-        //                     $("#phonto").hide();
-        //                     //将所有的设置为只读
-        //                     $('#app-form').find('input').attr('readonly', true);
-        //                     $('#app-form').find('select,input[type="radio"]').attr('disabled',
-        //                         true);
-        //                 } else {
-        //                     $("#sure").show();
-        //                     $('#app-form').attr('method', 'POST');
-        //                 }
-        //             }
-        //         }
-        //     });
-        // };
         // 表单提交事件
         form.on('submit(user-form-submit)', function (data) {
             layer.load(2);
-            data.field.hospitalId = parseInt($("#hospitalId").val());
+            data.field.hospitalId = $("#hospitalId").val();
             if (data.field.roleId != null && data.field.roleId != "") {
                 data.field.roles = data.field.roleId.split(',');
             }
-            data.field.hospitalId = ""+data.field.hospitalId;
+            if ($("#doctorType").val() == 2) {
+                //将关于密码的的去掉
+                data.field.username = "";
+                data.field.password = "";
+                data.field.passwordSure = "";
+            } else {
+                if (data.field.roles.length == 0) {
+                    layer.msg("请选择角色");
+                    return
+                }
+                if (data.field.roles.includes(guanliyuan_role)) {
+                    data.field.isAdminUser = true;
+                } else {
+                    data.field.isAdminUser = false;
+                }
+            }
+            // guanliyuan_role
+            // data.field.hospitalId = ""+data.field.hospitalId;
             data.field.roleId = null;
-            debugger
+
             admin.req('api-user/sysdoctor', JSON.stringify(data.field), function (data) {
                 layer.closeAll('loading');
                 if (data.code == 0) {
                     layer.closeAll();
+                    parent.layui.table.reload('app-table', {});
                 } else {
                     layer.msg(data.msg, {
                         icon: 2,
@@ -415,7 +358,7 @@
                 } else {
                     layer.msg(data.msg, {
                         icon: 2,
-                        time: 500
+                        time: 2000
                     });
                 }
             }, 'get');
@@ -423,7 +366,7 @@
         //职称添加数据
         var getZhiCheng = function () {
             admin.req('api-user/sysdictionaries/findAll', JSON.stringify({
-                dictionariesClassId: "1248150699682988034"
+                dictionariesClassId: "DOCTOR_RANK"
             }), function (data) {
                 layer.closeAll('loading');
                 if (0 === data.code) {
@@ -442,14 +385,14 @@
                 } else {
                     layer.msg(data.msg, {
                         icon: 2,
-                        time: 500
+                        time: 2000
                     });
                 }
             }, 'Post');
         }
         //获取销售代表
         var getXiaoShouDaiBiao = function () {
-            admin.req('api-user/users/getThisUserOrganizationUser', {}, function (data) {
+            admin.req('api-user/users/getAppointUser', {type:0}, function (data) {
                 layer.closeAll('loading');
                 if (0 === data.code) {
                     user = data.data;
@@ -461,7 +404,7 @@
                 } else {
                     layer.msg(data.msg, {
                         icon: 2,
-                        time: 500
+                        time: 2000
                     });
                 }
             }, 'get');
@@ -507,16 +450,38 @@
                     layer.closeAll('loading');
                 }
             });
+            //将密码隐藏
+            $(".account").hide();
+            //将密码置空 
+            $("#password").val("");
             form.render();
             $("#username").blur(function () {
                 username_is_usered("username");
             })
-            $("#doctorTel-add").blur(function () {
-                $("#username").val($("#doctorTel-add").val())
-                username_is_usered("username");
-            })
+
+            //医生类型的选择事件
+            // form.on('select(doctorType)', function (data) {
+            //     // console.log("eeeeeeeeeeeeeeeee");
+            //     // var doctor = admin.getTempData('t_doctor');
+            //     // debugger
+            //     // console.log("doctordoctordoctordoctordoctor",doctor);
+            //     var doctorType = $('#doctorType').val();
+            //     //将密码项取消
+            //     if (doctorType == 2) {
+            //         $(".account").hide();
+            //     } else {
+            //         $(".account").show();
+            //     }
+            // })
         };
-        loadEditData();
+        $("#doctorTel-add").blur(function () {
+            $("#username").val($("#doctorTel-add").val())
+            var doctorTel_add = $("#doctorTel-add").val();
+            if (!validatorTel(doctorTel_add)) {
+                layer.msg("请输入正确的手机号");
+            }
+            username_is_usered("username");
+        })
         //自动完成-医院名称
         autocomplete.render({
             elem: $('#hospitalName')[0],
@@ -525,10 +490,86 @@
             template_val: '{{d.hospitalName}}', //选择后文本框显示的数据字段
             template_txt: "<div class='layui-table-cell'>{{d.hospitalName}}</div>", //下拉列表模板
             onselect: function (resp) {
+
                 $("#hospitalId").val(resp.id);
                 //重新装载科室
                 getdepartment(resp.id);
             }
         });
+        //医生类型的选择事件
+        form.on('select(doctorType)', function (data) {
+            var doctor = admin.getTempData('t_doctor');
+            var doctorType = $('#doctorType').val();
+            if (doctor == null) {
+                if (doctorType != 2) {
+                    $(".account").show();
+                    $("#password_div").show();
+                    $("#passwordSure_div").show();
+                    $("#roleId_div").show()
+                }else{
+                    $(".account").hide();
+                    $("#roleId_div").hide()
+                }
+            } else {
+                if (doctor.doctorType == 2 && doctorType == 2) {
+                    $(".account").hide();
+                    $("#roleId_div").hide()
+                } else if (doctor.doctorType == 2 && doctorType != 2) {
+                    $(".account").show();
+                    $("#password_div").show();
+                    $("#passwordSure_div").show();
+                    $("#roleId_div").show()
+                    if (doctor.username == null) {
+                        $("#username").val(doctor.doctorTel);
+                        form.render();
+                    }
+                } else if (doctor.doctorType != 2 && doctorType != 2) {
+                    $(".account").show();
+                    $("#password_div").hide();
+                    $("#passwordSure_div").hide();
+                    $("#roleId_div").show()
+                } else if (doctor.doctorType != 2 && doctorType == 2) {
+                    $(".account").hide();
+                    $("#roleId_div").hide()
+                }
+            }
+        })
+        //数据的回显
+        var doctor = admin.getTempData('t_doctor');
+        $('#app-form-add').attr('method', 'POST');
+        if (doctor) {
+            //重新装载科室
+            getdepartment(doctor.hospitalId);
+            //获取职称的
+            getZhiCheng();
+            //获取销售代表
+            getXiaoShouDaiBiao();
+            //获取角色
+            get_role(doctor.isAdminUser);
+
+            form.val('app-form-add', doctor);
+            $("#hospitalId").val(doctor.hospitalId);
+            $("#password_div").hide();
+            $("#passwordSure_div").hide();
+
+            //将密码项取消
+            if (doctor.doctorType == 2) {
+                $(".account").hide();
+                $("#roleId_div").hide()
+            } else {
+                $(".account").show();
+                $("#roleId_div").show()
+            }
+            $('#demo2').append('<img src="' + doctor.doctorLogo +
+                '" width="50px" height="50px" alt="' + "name" +
+                '" class="layui-upload-img">')
+            $("#password").removeAttr("lay-verify")
+            $("#password").removeAttr("required")
+            $("#passwordSure").removeAttr("lay-verify")
+
+            form.render();
+        } else {
+            loadEditData();
+        }
     });
 </script>
\ No newline at end of file

--
Gitblit v1.8.0