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

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

//读取身份证
function readIdInfo() {
    var sxID = GetQuery('sxID');//事项ID
    // logger('读取身份证');
    send_command(
        "idReaderReadInfo",
        "nothing",
        function (receivedData) {
            var idInfo = JSON.parse(receivedData);
            if (idInfo.status==100){
            function saveInfo(){
                m_info = receivedData;
                //检索是否已登记
                var user = JSON.parse(m_info);
                var KeyValue = user.idCardNo;
                $.ajax({
                    url: "/IdCardInfo/ZzsbDj",
                    type: "post",
                    data: { KeyValue: KeyValue },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        if (!data.isExit) {
                            save_info(m_info);
                            //logger(m_info);
                            window.location.href = "/Zzsb/SFZsmInfo?dj=f&sxID=" + sxID;
                        }
                        else {
                            m_info = m_info.substr(0, m_info.length - 1) + ',"phoneNum":"' + data.user.PhoneNum + '","ID":' + data.user.ID + '}';
                            //logger(m_info);
                            save_info(m_info);
                            window.location.href = "/Zzsb/SFZsmInfo?dj=t&sxID=" + sxID;
                        }
                    },
                    error: function (data) {
                        alert("扫描身份证失败");
                    }
                });
            }
            saveInfo();
            }
            else if (idInfo.status==200){
                window.location.href = "/";
            }
        });
}

readIdInfo();

function GetQuery(key) {
    var search = location.search.slice(1); //得到get方式提交的查询字符串
    var arr = search.split("&");
    for (var i = 0; i < arr.length; i++) {
        var ar = arr[i].split("=");
        if (ar[0] == key) {
            if (unescape(ar[1]) == 'undefined') {
                return "";
            } else {
                return unescape(ar[1]);
            }
        }
    }
    return "";
}


