var wzh = {};
var address = "";
var appSecret = "30b5c231a8ea42c09c87f75d22ebc9ea"; // appId对应的加密密钥
var appId = "1035";
var nonce = "jfoiiuylkjljpohi";
var business = "{'areaCode':'020','busiSerial':'12345','channelCode':'2001','clientIP':'','deviceModel':'llllllllsdfsdffsdfjka  sdfjfsdfsdfsddddddddddd','deviceSerial':'','osType':'','srcSystem':'CRM','staffCode':'110011','teminalType':'PC'}";
var host = "http://127.0.0.1:18889"

wzh.getBase64PdfT = function (filePath) {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/getBase64file?time=" + time;
    var dataInfo = "{\"filePath\":\"" + filePath + "\"}";
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        data: dataInfo,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;
}
wzh.getStatusT = function () {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/getMutiStatus?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;
}

wzh.previewT = function (fileStr, filetype) {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/preview?time=" + time
    var dataInfo = "{\"fileStr\":\"" + fileStr + "\",\"filetype\":\"" + filetype + "\"}";
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        timeout: 10000, //超时时间设置，单位毫秒
        data: dataInfo,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        },
        complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
            if (status == 'timeout') { //超时,status还有success,error等值的情况
                //ajaxTimeoutTest.abort();
                wzh.closeSIGNT();
            }
        }
    })
    return resultInfo;
}

wzh.previewSyncT = function (fileStr, filetype) {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/previewSync?time=" + time
    var dataInfo = "{\"fileStr\":\"" + fileStr + "\",\"filetype\":\"" + filetype + "\"}";
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        timeout: 10000, //超时时间设置，单位毫秒
        data: dataInfo,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        },
        complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
            if (status == 'timeout') { //超时,status还有success,error等值的情况
                //ajaxTimeoutTest.abort();
                wzh.closeSIGNT();
            }
        }
    })
    return resultInfo;
}

wzh.setDialogTimeOutT = function (timeout) {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/setDialogTimeOut?time=" + time
    var dataInfo = "{\"timeout\":\"" + timeout + "\"}";
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        timeout: 10000, //超时时间设置，单位毫秒
        data: dataInfo,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        },
        complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
            if (status == 'timeout') { //超时,status还有success,error等值的情况
                //ajaxTimeoutTest.abort();
                wzh.closeSIGNT();
            }
        }
    })
    return resultInfo;
}

wzh.getCameraT = function () {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/getCamera?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;
}
wzh.previewSignT = function (fileStr, filetype = 'pdf', location = '0,1,50,50,1', ifPreview = '1') {
    jQuery.support.cors = true;
    
    return new Promise((resolve, reject) => {
        $.ajax({
            type: "post",
            async: false,
            url: host + "/api/previewSign?time=" + (new Date()),
            timeout: 5000, //超时时间设置，单位毫秒
            data: "{\"fileStr\":\"" + fileStr + "\",\"filetype\":\"" + filetype + "\",\"location\":\"" + location + "\",\"ifPreview\":\"" + ifPreview + "\"}",
            jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
            success: function (result) {
                if (result.indexOf("jsonpCallback") != -1) {
                    resolve(JSON.parse(result.substring(14, result.length - 1)).resultEntity)
                } else {
                    resolve(result)
                }
            },
            error: function () {
                reject({resultFlag: -1, errorMsg: '网络问题,请确认服务是否存在'})
            },
            complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
                if (status == 'timeout') { //超时,status还有success,error等值的情况
                    //ajaxTimeoutTest.abort();
                    wzh.closeSIGNT();
                }
            }
        })
    });
}


wzh.signFileT = function (fileStr, filetype, location, ifPreview) {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/signFile?time=" + time
    var dataInfo = "{\"fileStr\":\"" + fileStr + "\",\"filetype\":\"" + filetype + "\",\"location\":\"" + location + "\",\"ifPreview\":\"" + ifPreview + "\"}";
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        timeout: 10000, //超时时间设置，单位毫秒
        data: dataInfo,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        },
        complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
            if (status == 'timeout') { //超时,status还有success,error等值的情况
                //ajaxTimeoutTest.abort();
                wzh.closeSIGNT();
            }
        }
    })
    return resultInfo;
}
var getParam;
wzh.signPoll = function () {
    var resultInfo;
    if (address == "") {
        json = eval('(' + wzh.getSystemIPT() + ')');
        address = json.IP;
    }
    var time = new Date();
    var tes = host + "/api/intervalSign?time=" + time
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result == "") {
                return result;
            }
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;
}

wzh.closeSIGNT = function () {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/closeSIGN?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;
}
wzh.closeVideoT = function () {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/closeVideo?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;
}
wzh.toMainScanT = function () {
    var resultInfo;
    var dataInfo = "{\"param\":\"1600X1200;1; ;-1;0;0;0;0;-1;-1;Main;\"}";
    var time = new Date();
    var tes = host + "/api/toScan?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        data: dataInfo,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;
}


wzh.toSecScanT = function () {
    var resultInfo;
    var dataInfo = "{\"param\":\"640X480;0; ;-1;0;0;0;0;-1;-1;Sec;\"}";
    var time = new Date();
    var tes = host + "/api/toScan?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        data: dataInfo,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;
}



wzh.getParam = function (param) {
    getParam = param;
    return getParam;
}


wzh.toScanPollT = function () {
    var resultInfo;

    var time = new Date();
    var tes = host + "/api/toSurePoll?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        //data:dataInfo,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
                json = eval('(' + resultInfo + ')');
                if (json.errorCode != 99) {
                    //alert(resultInfo)
                    clearInterval(getParam);
                }
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;
}



wzh.GetICCIDT = function () {
    var time = new Date();
    var tes = host + "/api/getCCID?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        //dataType : "jsonp",//数据类型为jsonp  
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;

}

wzh.keyBoardPasswordT = function (limitLen, timeOut) {
    var time = new Date();
    var dataInfo = "{\"limitLen\":" + limitLen + ",\"timeOut\":" + timeOut + "}";
    var tes = host + "/api/keyBoardPassword?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        data: dataInfo,
        //dataType : "jsonp",//数据类型为jsonp  
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;

}

wzh.startSelectNumT = function (url, data, timeout) {
    var resultInfo;

    var time = new Date();
    var dataInfo = {}
    dataInfo.url = url
    dataInfo.phone_numbers = data
    dataInfo.timeout = timeout
    dataInfo = JSON.stringify(dataInfo)

    var tes = host + "/api/StartSelectNum?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        data: dataInfo,
        //dataType : "jsonp",//数据类型为jsonp  
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;

}

wzh.getSelectedNumT = function (callback) {
    var resultInfo;
    var time = new Date();
    var tes = host + "/api/GetSelectedNum?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        //dataType : "jsonp",//数据类型为jsonp  
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
            callback(resultInfo)
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
            callback(resultInfo)

        }
    })
    return resultInfo;

}

wzh.cancelSelectNumT = function () {
    var time = new Date();
    var tes = host + "/api/CancelSelectNum?time=" + time;
    jQuery.support.cors = true;
    $.ajax({
        type: "post",
        async: false,
        url: tes,
        jsonp: "jsonpCallback", //服务端用于接收callback调用的function名的参数  
        success: function (result) {
            if (result.indexOf("jsonpCallback") != -1) {
                resultInfo = result.substring(14, result.length - 1);
            } else {
                resultInfo = result;
            }
        },
        error: function () {
            resultInfo = "{\"resultFlag\":-1,\"errorMsg\":\"网络问题,请确认服务是否存在\"}";
        }
    })
    return resultInfo;

}

export default wzh