编辑代码

/*
Name: fnGetInvoiceNumber
Function: get the invoice of the 
Param: window.objGlobalParam.objReservationDetails
Return: 
        if there are over 1 invoice , post the message with error description
future: be able to cancel all the invoices in the account
 */

function fnGetInvoiceNumber( objReservationDetails)
{
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST","https://app9.rmscloud.cn/api/TaxInvoice/TaxInvoiceScreenData",true);
    xmlhttp.onreadystatechange=function()
      {
        if (xmlhttp.readyState==4)
            {
                if(xmlhttp.status==200){
                    console.log(xmlhttp.responseText);

                    if(JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices.length ==1)
                    {
                        let objParam = {
                            "strName": "fnCallBackGetInvoiceNumber",
                            "objValue": '',
                            "bIfContinue":true
                        }
                        window.objGlobalParam.nInvoiceNumber= JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices[0].InvoiceNo;
                        window.postMessage(objParam);
                    }
                    else if(JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices.length ==0 )
                    {
                    //JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices[0].InvoiceNo;
                    

                        let objParam = {
                            "strName": "fnCallBackGetInvoiceNumber",
                            "objValue": null,
                            "bIfContinue":true,
                            "strErrorDescription":"无账单号"
                        }
                        window.postMessage(objParam);
                    }
                    else (JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices.length >1)
                    {
                    //JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices[0].InvoiceNo;
                    

                        let objParam = {
                            "strName": "fnCallBackGetInvoiceNumber",
                            "objValue": null,
                            "bIfContinue":true,
                            "strErrorDescription":"多余一个账单号,请手动操作"
                        }
                        window.postMessage(objParam);
                    }
                }
                

            }
            
    }
      

    let objParam = {
        "AccNo": objReservationDetails.ResScreenData.AccountId,
        "AccType":1,
        "PropertyId":JSON.parse(window.localStorage.getItem('RM_Property')).data.split('_')[0],
        "ResId":objReservationDetails.ResScreenData.ResId
    };
    xmlhttp.setRequestHeader('content-Type','application/json; charset=utf-8');
    xmlhttp.send(JSON.stringify(objParam));  

}