
function logger(msg) {
    document.getElementById("logger").innerHTML = msg;
}

//离开关闭身份证读卡器
function stopIdCard() {
    send_command(
        "stopRead",
        "nothing",
        function (receivedData) {
            //logger(receivedData);
        });
}

var bsid = GetQuery('bsid');
var rytype = '';
rytype = decodeURI(escape(GetQuery('rytype')));
var qytype = getUrlParam("qytype");
//获取传递的参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
//读取身份证
function readIdInfo() {
    // logger('读取身份证');

    send_command(
        "idReaderReadInfo",
        "nothing",
        function (receivedData) {
            var idInfo = JSON.parse(receivedData);
            if (idInfo.status==100){
                // alert(idInfo);
            function saveInfo(){
                m_info=receivedData;
                save_info(m_info);
                delete m_info;
                delete receivedData;
                window.location.href = "/Ytj/qygsdz/ryPaizhao?bsid=" + bsid + "&rytype=" + encodeURI(rytype)+"&qytype="+qytype;
                $.ajax({
                    "cache":false,
                    "url": "/Ytj/GsYw/CheckRz?card=" + idInfo.idCardNo+"&name="+encodeURI(idInfo.name),
                    "type": "get",
                    "dataType": "json",
                    "success": function (json) {
                        if(json.code==0) {
                            var data = json.data;
                            if (data[5]!=("成功")) {

                                $("#code").css("display", "block");
                                $(".Animation").css("display", "none");

                                $("#name").text(data[0])
                                $("#sfzh").text(data[1])
                                $("#sfsm").text(data[2])
                                $("#zcbj").text(data[3])
                                $("#jzrq").text(data[4])
                                $("#cxjg").text(data[5])
                            } else {
                                window.location.href = "/Ytj/qygsdz/ryPaizhao?bsid=" + bsid + "&rytype=" + encodeURI(rytype)+"&qytype="+qytype;
                            }
                        }else {
                            alert('身份证读取错误,请联系工作人员!');
                            return false;
                        }
                    }
                });

            }
            saveInfo();
            }
            else if (idInfo.status==200){
                alert('身份证连接错误！请重试！');
                return false;
            }
        });
}

readIdInfo();


