contact.js 11.5 KB
// get code
console.log(111)
window.downHttpContact = 'https://ieva.lianxinzhiping.com'//'https://ieva.lianxinzhiping.com';


function draw() {
    $('#code1 img').attr('src', window.location.origin + '/api' + "/web/businessUser/getKaptchaImage")
}

//切换验证码
$('#code1').on('click', function () {
    draw()
})

//删除名片
$(".img_box1").on("click", "#deleImg1", function () {
    var textHtml = '<img src="img/addCard.png" alt=""><input type="file" value="上传文件" id="upload1" class="uploader-file"  accept="image/*" onchange="getImgURL1(this)">';
    $(".img_box1").html(textHtml);
})

//验证码倒计时
var interval1;
var c1=60
function timeDown1(id) {
    $("#" + id).attr("disabled", "disabled"); //点击一次不可再点
    interval1 = setInterval(function () { //定义定时器
        $("#" + id).val(c1 + "s之后重试");
        c1--;
        if (c1 == 0) {
            clearInterval(interval1); //清除定时器
            $("#" + id).val("重新获取验证码");
            $("#" + id).removeAttr("disabled"); //删除这个属性
            c1 = 60;
        }
    }, 1000);
}

//申请账号获取验证码
$("#getCode1").on('click', function () {
    console.log($("#setTel1").val())
    if ($("#setTel1").val() == '') {
        $("#register1 .jiaoyan").text('手机号码不能为空')
        return false
    }
    if (!(/^1[3456789]\d{9}$/.test($("#setTel1").val()))) {
        $("#register1 .jiaoyan").text('请输入正确的手机号')
        return false
    }
    console.log($("#register1 .jiaoyan").text())
    var obj = {
        phone: $("#setTel1").val(),
        type: 3 //1
    }
    $.ajax({
        url: window.downHttpContact + '/api' + "/web/register/sendSms",
        data: obj,
        type: "POST",
        dataType: "json",
        success: function (res) {
            if (res.code == 2000) {
                $("#register1 .jiaoyan").text('')
                timeDown1('getCode1')
            } else {
                $("#register1 .jiaoyan").text(res.msg)
            }
        }
    });
})

//申请账号下一步
$("#applyNext1").on('click', function () {

    if ($("#setTel1").val() == '') {
        $("#register1 .jiaoyan").text('手机号码不能为空')
        return false
    }
    if (!/^1[0-9]{10}$/.test($("#setTel1").val())) {
        $("#register1 .jiaoyan").text('请输入正确的手机号')
        return false
    }
    if ($("#setCode1").val() == '') {
        $("#register1 .jiaoyan").text('验证码不能为空')
        return false
    }
    if ($("#setName1").val() == '') {
        $("#register1 .jiaoyan").text('姓名不能为空')
        return false
    }
    if ($("#setEmail1").val() == '') {
        $("#register1 .jiaoyan").text('邮箱不能为空')
        return false
    }


    if (!/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test($("#setEmail1").val())) {
        $("#register1 .jiaoyan").text('请输入正确的邮箱')
        return false
    }
    if ($("#setCompany1").val() == '') {
        $("#register1 .jiaoyan").text('公司名称不能为空')
        return false
    }
    if ($("#setPost1").val() == '') {
        $("#register1 .jiaoyan").text('职务不能为空')
        return false
    }
    if ($("#cardImg1").data('url') == "" || $("#cardImg1").data('url') == undefined) {
        $("#register1 .jiaoyan").text('名片不能为空')
        return false
    }
    apply1()
})

 // 获取地址栏参数
 function GetRequest1() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
          var str = url.substr(1);
          strs = str.split("?");
          console.log(strs)
          for (var i = 0; i < strs.length; i++) {
              theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
          }
      }
      return theRequest;
  }

function apply1() {
    var a = GetRequest1();
    var userSource = a['userSource'];
    let applyForm = {
        city: $("#setCity1").val(),
        code: $("#setCode1").val(),
        companyName: $("#setCompany1").val(),
        dept: $("#setDpartment1").val(),
        email: $("#setEmail1").val(),
        job: $("#setPost1").val(),
        phone: $("#setTel1").val(),
        qq: "",
        userName: $("#setName1").val(),
        wx: "",
        remark: $("#setMessage1").val(),
        // password:$("#intoPassword").val(),
        cardPath: $("#cardImg1").data('url'),
        userSource: "gw"
    }

    $.ajax({
        url: window.downHttpContact + '/api' + "/web/userApplyAccount/UserApplyRegister",
        data: applyForm,
        type: "POST",
        dataType: "json",
        success: function (res) {
            if (res.code == 2000) {
                $("#register1 .jiaoyan").text('');
                var textHtml = '<img src="img/addCard.png" alt=""><input type="file" value="上传文件" id="upload1" class="uploader-file"  accept="image/*" onchange="getImgURL1(this)">';
                $(".img_box1").html(textHtml);
                // $("#zhanghao").text('您的账号为:'+res.data)
                // $('#setPassword').hide()

                $("#setTel1").val('')
                $("#setCode1").val('')
                $("#setName1").val('')
                $("#setEmail1").val('')
                $("#setCompany1").val('')
                $("#setDpartment1").val('')
                $("#setPost1").val('')
                $("#setCity1").val('')
                $("#setMessage1").val('')


                $('#black').show()
                $('#registerSuccess').show()
                closeSuccese1();

            } else {
                $("#register1 .jiaoyan").text(res.msg)
            }
        }
    });
}

//申请账号取消
$("#applyCancle1").on('click', function () {
    $("#register1 .jiaoyan").text('')
    var textHtml = '<img src="img/addCard.png" alt=""><input type="file" value="上传文件" id="upload1" class="uploader-file"  accept="image/*" onchange="getImgURL1(this)">';
    $(".img_box1").html(textHtml);
    // $("#zhanghao").text('您的账号为:'+res.data)
    // $('#setPassword').hide()

    $("#setTel1").val('')
    $("#setCode1").val('')
    $("#setName1").val('')
    $("#setEmail1").val('')
    $("#setCompany1").val('')
    $("#setDpartment1").val('')
    $("#setPost1").val('')
    $("#setCity1").val('')
    $("#setMessage1").val('')
})
//申请成功关闭
$("#successClose").on('click', function () {
    setTimeout(function () {
        $('#black').hide()
        $('#registerSuccess').hide()
        clearInterval(interval1); //清除定时器
        $("#getCode1").val("重新获取验证码");
        $("#getCode1").removeAttr("disabled"); //删除这个属性
        c1 = 60;
    }, 1000)
})

function kp1(txt, len) {
    var v = txt.value;
    console.log('v',v)
    if (len == 12) {
        var reg = /^[a-zA-Z\d`~@#\$%\^&\*\(\)\-_=\+\[\]\{\}\\\|;\:'",<\.>\/\?]{0,12}$/;
    } else if (len == 20) {
        var reg = /^[a-zA-Z\d`~@#\$%\^&\*\(\)\-_=\+\[\]\{\}\\\|;\:'",<\.>\/\?]{0,20}$/;
    } else if (len == 40) {
        var reg = /^[a-zA-Z\d`~@#\$%\^&\*\(\)\-_=\+\[\]\{\}\\\|;\:'",<\.>\/\?]{0,40}$/;
    } else if (len == 200) {
        var reg = /^[a-zA-Z\d`~@#\$%\^&\*\(\)\-_=\+\[\]\{\}\\\|;\:'",<\.>\/\?]{0,200}$/;
    }

    var vv = v.replace(/[^\x00-\xff]/g, "aa");
    if (!reg.test(vv)) {
        txt.value = txt.pv ? txt.pv : "";
    } else {
        txt.pv = v;
    }
}

function closeSuccese1() {
    var count = 3;
    $("#setPassword .jiaoyan").text('')

    $('#registerSuccess').show()
    var intervalBox = setInterval(() => {
        count--
        $("#registerSuccess .one").text('申请信息提交成功,请耐心等待' + " " + count)
        $('#setPassword').hide()
        if (count == 0) {
            clearInterval(intervalBox)
            clearInterval(interval1); //清除定时器
            $("#getCode1").val("重新获取验证码");
            $("#getCode1").removeAttr("disabled"); //删除这个属性
            c1 = 60;
            $('#black').hide()
            $('#registerSuccess').hide()
        }
    }, 1000);
}

//上传名片
function isAssetTypeAnImage1(ext) {
    return [
        'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'
    ].
    indexOf(ext.toLowerCase()) !== -1;
}

function getImgURL1(node) {
    var imgURL = "";
    try {
        var file = null;
        if (node.files && node.files[0]) {
            file = node.files[0];

        } else if (node.files && node.files.item(0)) {
            file = node.files.item(0);
        }
        //Firefox 因安全性问题已无法直接通过input[file].value 获取完整的文件路径
        try {
            //Firefox7.0
            imgURL = file.getAsDataURL();
            //alert("//Firefox7.0"+imgRUL);
        } catch (e) {
            //Firefox8.0以上
            imgRUL = window.URL.createObjectURL(file);
            //alert("//Firefox8.0以上"+imgRUL);
        }
    } catch (e) { //这里不知道怎么处理了,如果是遨游的话会报这个异常
        //支持html5的浏览器,比如高版本的firefox、chrome、ie10
        if (node.files && node.files[0]) {

            var reader = new FileReader();
            reader.onload = function (e) {
                imgURL = e.target.result;
            };
            reader.readAsDataURL(node.files[0]);
        }
    }
    console.log(node.files[0])
    var index = node.files[0].name.lastIndexOf(".");
    //获取后缀
    var imgType = node.files[0].name.substr(index + 1);
    if (!isAssetTypeAnImage1(imgType)) {
        $("#register1 .jiaoyan").text('名片只能选择图片格式')
        return false
    }
    if ($("#register1 .jiaoyan").text() == "名片只能选择图片格式") {
        $("#register1 .jiaoyan").text("")
    }
    if (node.files[0].size >= 1024 * 1024 * 20) {
        $("#register1 .jiaoyan").text('图片请限制在20M以内')
        return false
    } else {
        if ($("#register1 .jiaoyan").text() == "图片请限制在20M以内") {
            $("#register1 .jiaoyan").text("")
        }
    }
    var obj = new FormData();
    obj.append("file", node.files[0])
    $.ajax({
            url: window.downHttpContact + '/api' + '/web/oss/uploadFile',
            type: 'post',
            // dataType: 'json',
            data: obj,
            contentType: false,
            processData: false
        })
        .done(res => {
            if (res.code == "2000") {
                window.fileUrl = res.data.rows[0].url;
                var textHtml = "<div class='deleImg' id='deleImg1'>×</div> <img id='cardImg1' data-url='" + res.data.rows[0].url + "' src='" + res.data.rows[0].path + "'/>";
                $(".img_box1").html(textHtml);

                if ($("#register1 .jiaoyan").text() == '名片不能为空') {
                    $("#register1 .jiaoyan").text('');
                }
            } else {
                $("#services1 .contact_error_box").text('上传失败,请重新上传')
            }
        })
        .fail(res => {
            $("#services1 .contact_error_box").text('上传失败,请重新上传')
        });


    // return imgURL;
}

function creatImg(imgRUL) { //根据指定URL创建一个Img对象
    var textHtml = "<img src='" + imgRUL + "'/>";
    $(".img_box1").html(textHtml);
}