mydata.html 5.8 KB
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>我要问诊</title>
    <script src="__TMPL__/public/assets/js/fontsize.js"></script>
    <script src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script>
    <link rel="stylesheet" href="__TMPL__/public/assets/css/init.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/swiper-3.4.2.min.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_793738_d49fodige36.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/weui.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/myweui.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/myData.css">
    <link rel="stylesheet" href="__TMPL__/public/assets/css/comment.css">
</head>
<body style="background-color: #F5F6FA">
<div class="banner_box">
    <div class="head_img">
        <img class="" id="pic"  src="{:cmf_get_image_url($user.avatar)}" onclick="chargeImg()">
        <input id="upload" name="file" accept="image/*" type="file" style="display: none">
        <div class="iconfont icon-zhaoxiangji" id="pic_mask" onclick="chargeImg()"></div>
    </div>
</div>
<div class="content_box">
    <div class="item_list">
        <div class="list_title">姓名</div>
        <div class="list_input"><input type="text" value="{$user.user_login}" placeholder="请填写姓名" id="user_name"></div>
    </div>
    <div class="item_list">
        <div class="list_title">手机号</div>
        <div class="list_input"><input type="text" value="{$user.mobile}" placeholder="请填写手机号" id="phone_num"></div>
    </div>
    <div class="item_list">
        <div class="list_title">医院</div>
        <div class="list_input"><input readonly type="text" placeholder="{$user.hospital}" id="hospital"></div>
    </div>
    <div class="item_list">
        <div class="list_title">科室</div>
        <div class="list_input"><input readonly type="text" placeholder="{$user.office}" id="department"></div>
    </div>
</div>
<div class="bottom_btn">
    <div class="edit_btn">修改</div>
</div>
<!--表单判断弹窗-->
<div class="form_popup_box">
    <text></text>
</div>
</body>

<script>
    //上传头像
    function chargeImg() {
        $("#upload").click(); //隐藏了input:file样式后,点击头像就可以本地上传
        $("#upload").on("change", function () {
            var objUrl = getObjectURL(this.files[0]); //获取图片的路径,该路径不是图片在本地的路径
            if (objUrl) {
                $("#pic").attr("src", objUrl); //将图片路径存入src中,显示出图片
                $('#pic_mask').hide()
                upimg();
            }
        });
    }

    //建立一?可存取到?file的url
    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }

    //上传头像到服务器
    function upimg() {
        var pic = $('#upload')[0].files[0];
        var file = new FormData();
        file.append('image', pic);
        $.ajax({
            url: "{:url('uploadAvatar')}",
            type: "post",
            data: file,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                console.log(data);
                var res = data;
                $("#resimg").append("<img src='/" + res + "'>")
            }
        });
    }
    //form判断
    $('.form_popup_box').hide()
    $('.edit_btn').click(function () {
            var user_name = $('#user_name').val()
            var phone_num = $('#phone_num').val()
            var hospital = $('#hospital').val()
            var department = $('#department').val()

            if (user_name == '') {
                $('.form_popup_box').show()
                $('.form_popup_box').text('姓名不能为空')
                $('.form_popup_box').delay(1000).hide(0);
            } else if (phone_num == '') {
                $('.form_popup_box').show()
                $('.form_popup_box').text('手机号不能为空')
                $('.form_popup_box').delay(1000).hide(0);
            } /*else if (hospital == '') {
                $('.form_popup_box').show()
                $('.form_popup_box').text('医院不能为空')
                $('.form_popup_box').delay(1000).hide(0);
            } else if (department == '') {
                $('.form_popup_box').show()
                $('.form_popup_box').text('科室不能为空')
                $('.form_popup_box').delay(1000).hide(0);
            } */ else {
                $.ajax({
                    url:'{:url('editInfo')}',
                    type:'POST',
                    data:{
                      name:user_name,
                      mobile:phone_num,
                    },
                    success:function (res) {
                        if (res.code==1){
                            $('.form_popup_box').show()
                            $('.form_popup_box').text('修改成功!')
                            $('.form_popup_box').delay(1000).hide(0);
                            window.location.href='{:url('')}';
                        }else {
                            $('.form_popup_box').show()
                            $('.form_popup_box').text('修改失败!')
                            $('.form_popup_box').delay(1000).hide(0);
                        }
                    }
                })
            }
        }
    )
</script>
</html>