编辑代码

/*
    Name: fnGetEventHandler
    Function: get event handler
    Param: null
    Return: store event handler into window.objGlobalParam.strEventHandler
 */

function fnGetEventHandler() {
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            console.log("fnGetEventHandler: ");
            console.log(xmlhttp.responseText);
            //objParam.objReservationDetails= rtn.responseJSON.ResScreenData.ResRows;
            //fnTasksLoop("fnGetReservationDetails",xmlhttp.responseText);
            let objParam = {
                "strName": "fnCallBackGetEventHandler",
                "objValue": null,
                "bIfContinue": true,
                "strErrorDescription": ""
            }
            window.objGlobalParam.strEventHandler = xmlhttp.responseText;
            window.postMessage(objParam);
        }
    }
    xmlhttp.open("GET", "https://app9.rmscloud.cn/api/UtilitiesService/InitEventHandler" +
        "?placeholder=" + Math.random());
    xmlhttp.setRequestHeader('content-Type', 'application/json; charset=utf-8');
    xmlhttp.send();
}

/*
    Name: fnEventStatusAsync
    Function: get event resault
    Param: null
    Return: if return value is null recall itself
        it will run itself up to 9 times,otherwise it return with error
    future: 2025
 */

function fnEventStatusAsync(strEventId) {
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            console.log("fnEventStatusAsync: ");
            console.log(xmlhttp.responseText);
            //objParam.objReservationDetails= rtn.responseJSON.ResScreenData.ResRows;
            //fnTasksLoop("fnGetReservationDetails",xmlhttp.responseText);
            
            if (xmlhttp.responseText.toLowerCase() == 'null') {
                setTimeout(function () {
                    window.objGlobalParam.nExpireCounter = parseInt(window.objGlobalParam.nExpireCounter) + 1;
                    if (parseInt(window.objGlobalParam.nExpireCounter) >= 9) {
                        window.objGlobalParam.nExpireCounter = 0;
                        let objParam = {
                            "strName": "fnCallBackEventStatusAsync",
                            "objValue": null,
                            "bIfContinue": false,
                            "strErrorDescription": "创建失败,请重试"
                        }
                        window.postMessage(objParam);
                        alert('请重试');
                        fnClearEventHandler(strEventId);
                    }
                    else
                        fnEventStatusAsync(strEventId);
                }, 1000)
            }
            else {
                fnOnTaskReady(xmlhttp);
                fnClearEventHandler(strEventId);
            }
            
        }
    }
    xmlhttp.open("GET", "https://app9.rmscloud.cn/api/UtilitiesService/EventStatusAsync?" +
        "EventId=" + strEventId);
    xmlhttp.setRequestHeader('content-Type', 'application/json; charset=utf-8');
    xmlhttp.send();
}


/*
    Name: fnClearEventHandler
    Function: clear event 
    Param: null
    Return: if return value is null recall itself
 */

function fnClearEventHandler(strEventId) {
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            console.log("fnClearEventHandler: ");
            console.log(xmlhttp.responseText);
            let objParam = {
                "strName": "fnCallBackClearEventHandler",
                "objValue": null,
                "bIfContinue": true,
                "strErrorDescription": ""
            }
            //window.objGlobalParam.objReservationDetails = JSON.parse(xmlhttp.responseText).ResScreenData;
            //window.postMessage(objParam);
        }
    }
    xmlhttp.open("GET", "https://app9.rmscloud.cn/api/UtilitiesService/ClearEventHandler?" +
        "EventId=" + strEventId);
    xmlhttp.setRequestHeader('content-Type', 'application/json; charset=utf-8');
    xmlhttp.send();
}

function fnOnCreateReservationSuccess(xmlhttp)
{
    let objParam = {
                    "strName": "fnCallBackEventStatusAsync",
                    "objValue": null,
                    "bIfContinue": true,
                    "strErrorDescription": ""
                }
                window.objGlobalParam.objReservationDetails = JSON.parse(xmlhttp.responseText).ResScreenData;
                window.postMessage(objParam);
                alert('预订成功,订单确认号: ' + JSON.parse(xmlhttp.responseText).ResScreenData.ResId);
                fnClearEventHandler(strEventId);
}