<apex:page controller="RentalApplySplitController" action="{!init}" showHeader="false" id="allPage" lightningStylesheets="true">
    <head>
      <title>备品借出申请分单</title>
      <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
      <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
      <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
      <apex:stylesheet value="{!URLFOR($Resource.StyleUtilCss)}"/><!-- 20230619 ljh lightning -->
    </head>
    <style type="text/css">
        .hideDropdown select{
            display: none
        }
        .modal {
           display:none;
           position: fixed; /* Stay in place */
           z-index: 10; /* Sit on top */
           left: 0;
           top: 0;
           width: 100%; /* Full width */
           height: 100%; /* Full height */
           overflow: auto; /* Enable scroll if needed */
           background-color: rgb(0,0,0); /* Fallback color */
           background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
        }
        span.dateFormat {
            display: none;
        }

        /* Modal Content/Box */
        .modal-content {
           background-color: #fefefe;
           margin-left: 6px;
           margin-top: 100px;
           padding: 20px;
           border: 1px solid #888;
           right: 5%;
           position: absolute;
           width: 200px;
        }
        .modal-content-cancel {
           background-color: #fefefe;
           margin-left: -150px;
           margin-top: 100px;
           padding: 20px;
           border: 1px solid #888;
           left: 50%;
           position: absolute;
           width: 300px;
        }
        body .slds-vf-data-table thead th{
            background: none;
        }
        /*table.list td{
            width:100px;
            border-width: 1px;
        }
        table.list td.col_chk {
            width:30px;
        }
        body .pbBody table.list tr.headerRow td, body .pbBody table.list tr.headerRow th {
            border-width: 1px;
        }*/
        /* 20230613 ljh lightning start */
        body .detailList .dataCol input[type="text"],body .detailList .dataCol select{
            min-width: 180px;
        }
        .pbBody{
            width:600px;
        }
        /* 20230613 ljh lightning start */
    </style>
    <apex:form id="allForm">
        <script type="text/javascript">
            function back() {
                // window.opener.parent.location.href = "/{!ra.Id}";
                // top.window.close();
                window.close();
            }

            function checkSaveStatus() {
                var saveStatus = document.getElementById('{!$Component.allForm.saveStatus}').value;
                if (saveStatus == 'ok') {
                    //20210609 ljh update 1732  start
                    var temp = '{!cloneRas.Id}';
                    console.log(temp);
                    if( temp == null || temp == '' ){
                        window.open("/{!ra.Id}");
                    }else{
                        window.open("/{!cloneRas.Id}");    
                    }
                    //20210609 ljh update 1732 end
                    top.window.close();
                }
            }
            //现地管理分单 202100609 ljh update 1732
            function changeSplitApplyReason(){
                var reason = j$(escapeVfId('allPage:allForm:searchBlock:split:split0:Split_Apply_Reason')).value();
                console.log(reason);
                var RecordTypeIsAgency = j$(escapeVfId('allPage:allForm:RecordTypeIsAgency')).value();
                if(reason != null && (reason == '现地管理分单' 
                    || (eval(RecordTypeIsAgency) && reason == '到货NG分单'))
                    ){
                    //办事处必须填写
                    j$(escapeVfId('allPage:allForm:searchBlock:split:ToAgency0:ToAgency')).attr('disabled',false);
                    j$(escapeVfId('allPage:allForm:searchBlock:split:ToAgency0:ToAgency')).attr('required',true);
                }else{
                    if(!(eval(RecordTypeIsAgency) && reason != null && reason == '到货NG分单')){
                        //办事处清空 只读
                        j$(escapeVfId('allPage:allForm:searchBlock:split:ToAgency0:ToAgency')).val(null);
                        j$(escapeVfId('allPage:allForm:searchBlock:split:ToAgency0:ToAgency')).attr('disabled',true);
                    } 
                }
            }
            function allSplitShow(){
                var allSplitShow = j$(escapeVfId('allPage:allForm:allSplitShow')).value();
                if(eval(allSplitShow)){
                    j$('#AllSplitModal').show();
                }
            }
        </script>
        <apex:pageMessages />
        <apex:inputHidden value="{!saveStatus}" id="saveStatus"/>
        <!-- 20210609 ljh add 1732  start-->
        <apex:inputHidden value="{!allSplitShow}" id="allSplitShow"/>
        <apex:inputHidden value="{!RecordTypeIsAgency}" id="RecordTypeIsAgency"/> 
        <div id="AllSplitModal" class="modal">
            <div class="modal-content-cancel">
                <table>
                    <tr>
                        <td colspan="2"> 
                        是否要整单分{!IF(SplitNum == 1,'回备品中心？',IF(SplitNum == 2,'给其他办事处？',IF(SplitNum == 3,'给办事处？','')))}                     
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center">
                            <apex:commandButton style="margin: 0 20px;" value="确定"  action="{!saveSplitAll}" oncomplete="checkSaveStatus();unblockUI();" onclick="j$('#AllSplitModal').hide();blockme();" rerender="allForm"
                            />
                            <apex:commandButton style="margin: 0 20px;" value="取消" onclick="j$('#AllSplitModal').hide();return false;"/>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <!-- 20210609 ljh add 1732  end-->
        <apex:pageBlock id="searchBlock" tabStyle="Report">
            <apex:pageBlockSection title="备品借出申请分单" collapsible="false" id="split">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="{!$ObjectType.Rental_Apply__c.fields.Name.label}" for="Name"/>
                    <apex:outputField value="{!ra.Name}" id="Name"/>
                </apex:pageBlockSectionItem>
                <!-- 20201119 ljh update start -->
                <apex:pageBlockSectionItem id="split0">
                    <apex:outputLabel value="{!$ObjectType.Rental_Apply__c.fields.Split_Apply_Reason__c.label}" for="Split_Apply_Reason"/>
                    <apex:inputField value="{!cloneRas.Split_Apply_Reason__c}" id="Split_Apply_Reason" required="true"  onchange="changeSplitApplyReason();"/>
                </apex:pageBlockSectionItem>
                <!-- 20201117 ljh add start --> 
                <apex:pageBlockSectionItem id="ToAgency0">
                    <apex:outputLabel value="{!$ObjectType.Rental_Apply__c.fields.ToAgency__c.label}" for="Name"/>
                    <apex:inputField value="{!cloneRas.ToAgency__c}" id="ToAgency"  />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem html-style="display: none;">
                <apex:inputField value="{!cloneRas.SalesdeptSelect__c}" id="SalesdeptSelect" style="display: none;" />
              </apex:pageBlockSectionItem>
                <!-- 20201117 ljh add end -->
            </apex:pageBlockSection>
            
            <apex:dataTable value="{!raesList}" var="raes" id="raesLists" border="allPage" cellpadding="5">
              <apex:column >
                <apex:facet name="header">借出备品配套一览No.</apex:facet>
                <apex:outputText value="{!raes.Name}" />
              </apex:column>
              <apex:column >
                <apex:facet name="header">借出配套型号</apex:facet>
                <apex:outputText value="{!raes.Loaner_code_F__c}" />
              </apex:column>
              <apex:column >
                <apex:facet name="header">借出备品配套一览状态</apex:facet>
                <apex:outputText value="{!raes.RAES_Status__c}" />
              </apex:column>
            </apex:dataTable>
            <div style="height: 15px"></div>
            <input type="hidden" name="hide"/>
            <apex:commandButton value="确认分单" action="{!saveSplit}" oncomplete="allSplitShow();checkSaveStatus();unblockUI();" onclick="blockme();" rerender="allForm" />
            <apex:commandButton value="返回" onclick="back(); return false;" rerender="allForm" oncomplete="unblockUI();" />
          </apex:pageBlock>
        </apex:form>
</apex:page>