<apex:page action="{!init}" controller="ChoiceAssetController" id="allPage" showHeader="false" sidebar="false" title="选择保有设备" lightningStylesheets="true" >
    <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"></apex:stylesheet>
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"></apex:includeScript>
    <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"></apex:includeScript>
    <apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
    <apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
    <style type="text/css"></style>
    <script>
        function searchProductJs() {
            searchAsset();
        }

        function saveJs(){
            save();
        }
        //XLIU-CJM7Z9 【委托】新建修理提示信息（停产及非修理对象品）LY 20221012 start
        function checkPartSupplyFinishDateJs(){
            var today = new Date();
            var targetDate = (today.getFullYear()+1) + '/' + (today.getMonth()+1) + '/' + today.getDate();
            var todayNew = today.toLocaleDateString();
            var check;
            var num = 100000;
            for (var i = 0; i < 100; i++) {
                check = j$(escapeVfId('allPage:allForm:allBlock:ConsumableorderdetailsSection:ConsumableorderdetailsTable:'+i+':consumablesCountproRowCheckbox')).attr('checked');
                if (check == 'checked'){
                    num = i;
                }
            }
            if (num != 100000){
                var partSupplyFinishDate = new Date(j$(escapeVfId('allPage:allForm:allBlock:ConsumableorderdetailsSection:ConsumableorderdetailsTable:' + num + ':partSupplyFinishDate')).value());
                if (partSupplyFinishDate != 'Invalid Date'){
                    var partSupplyFinishDateNew = partSupplyFinishDate.toLocaleDateString();
                    if (partSupplyFinishDateNew > todayNew && partSupplyFinishDateNew <= targetDate){
                        alert('预计'+ partSupplyFinishDateNew +'零件即将停产，请送修前与工厂及RC联络');
                    }
                    if (partSupplyFinishDateNew <= todayNew){
                        alert('该型号零件已经停产，有特殊需求，请送修前与工厂RC联络');
                    }
                }
            }
        }
        //XLIU-CJM7Z9 【委托】新建修理提示信息（停产及非修理对象品）LY 20221012 end

        function ClearJs(){
            blockme();
            document.getElementById("allPage:allForm:allBlock:searchBlock:FuselageNumber").value = "";
            document.getElementById("allPage:allForm:allBlock:searchBlock:AssetModel").value = "";
            document.getElementById("allPage:allForm:allBlock:searchBlock:HospitalName").value = "";
            searchAsset();
            
            // searchConsumableorderdetails();
        }
    </script>
    <apex:form id="allForm">
    <apex:actionFunction name="searchAsset" action="{!searchAsset}" rerender="ConsumableorderdetailsSection, message" onComplete="unblockUI();CheckStatusAfter();SumCompute()">
    </apex:actionFunction>
    <apex:actionFunction name="save" action="{!save}" rerender="ConsumableorderdetailsSection, message" onComplete="unblockUI();CheckStatusAfter();SumCompute()">
    </apex:actionFunction>
    

    <apex:outputPanel id="allPanel">
        <apex:pageBlock id="allBlock">
            <apex:pageBlock id="searchBlock" >
                    <table>
                        <colgroup>
                            
                            <col width="9%"/>
                            <col width="9%"/>
                            <col width="9%"/>
                            <col width="9%"/>
                            <col width="8%"/>
                            <col width="8%"/>
                            <col width="8%"/>
                            <col width="8%"/>
                            <col width="8%"/>
                            <col width="8%"/>
                            <col width="8%"/>
                            <col width="8%"/>
                            
                        </colgroup>

                        <tr>
                            
                            <td colspan="2"/>
                            <td colspan="4">机身编码：
                                <apex:inputText value="{!FuselageNumber}" id="FuselageNumber"/>
                            </td>                           
                             
                            <td align="right"></td>
                            <td><apex:commandButton value="保有设备搜索"  onclick="searchProductJs('0');return false;" /></td>
                            <td><input type="button" value="清空"  onclick="ClearJs();return false;" class="btn"/><apex:commandButton onclick="saveJs();" value="确定" rerender="dummy"  /></td>
                           <!--  <td>
                            <apex:commandButton onclick="saveJs();" value="确定" rerender="dummy"  />
                            </td> -->
                            
                            
                        </tr>
                        <!-- <td>
                            </td>
                            <td align="right"></td>
                            <td><apex:commandButton value="保有设备搜索" style="width: 80px;" onclick="searchProductJs('0');return false;" /></td>
                            <td><input type="button" value="清空" style="width: 80px;" onclick="ClearJs();return false;" class="btn"/></td>
                            <td>
                            <apex:commandButton onclick="saveJs();"           value="确定" style="width:80px" rerender="dummy"  />
                            </td> -->
                        <tr>
                            <td colspan="2"/>
                            <td colspan="4">设备型号：
                                <apex:inputText value="{!AssetModel}" id="AssetModel"/>
                            </td>
                            
                        </tr>
                        <tr>
                            <td colspan="2"/>
                            <td colspan="4">医院名称：
                                <apex:inputText value="{!HospitalName}" id="HospitalName"/>
                            </td>
                            
                        </tr>
                    </table>
                </apex:pageBlock>
                <apex:outputPanel id="message">
                    <apex:pageMessages />
                 </apex:outputPanel>
                <apex:pageBlock title="保有设备查找" id="ConsumableorderdetailsSection">
                    <table class="list" border="0" cellpadding="0" cellspacing="0">
                        <tr class="headerRow">
                            <!-- <apex:variable var="v" value="" rendered="{!editAble}"> -->
                                <!-- <th><input type='checkbox' onClick='checkAll()' id='checker'/>选择</th> -->
                            <!-- </apex:variable> -->
                            
                            <th>选择</th>
                            <th>保有设备名称</th>
                            <!-- 20220927 ljh XLIU-CJN62G update start-->
                            <!-- <th>状态</th> -->
                            
                            <th>机身编码</th>
                            <th>医院</th>
                            <th>战略科室</th>
                            <th>科室</th>
                            <th>发货日</th>
                            <th>多年保修期至</th>
                            <th>最近一期维修合同结束日</th>
                            <!-- <th>集中管理库存</th> -->
                            <!-- 20220927 ljh XLIU-CJN62G update end-->
                        </tr>
                            <apex:repeat value="{!choiceAssetInfoRecordsview}" var="records" id="ConsumableorderdetailsTable">
                                <tr class="dataRow">
                                    <td>
                                    <apex:inputCheckbox value="{!records.check}" onclick="CheckSize(this);" id="consumablesCountproRowCheckbox" onchange="checkPartSupplyFinishDateJs(); return false;" disabled="{!!records.canSelect}"/>
                                    </td>

                                    <!-- <apex:variable var="v" value="" rendered="{!editAble}" id="variableinfo">
                                        <td>
                                        <apex:inputCheckbox value="{!records.check}" onclick="CheckSize(this);" id="consumablesCountproRowCheckbox" disabled="{!!records.canSelect}"/>
                                         <apex:inputCheckbox value="{!records.oldCheck}" id="proRowOldCheckbox" style="display:none"/></td>
                                     </apex:variable> -->
                                    <td class="dataCell">
                                        <apex:outputText value="{!records.ast.Name}"/>
                                    </td>
                                    <!-- <td class="dataCell">
                                        <apex:outputText value="{!records.ast.Status}"/>
                                    </td> -->
                                    
                                    <td class="dataCell">
                                        <apex:outputText value="{!records.ast.SerialNumber}"/>
                                    </td>
                                    <td class="dataCell">
                                        <apex:outputText value="{!records.ast.Hospital__r.Name}"/>
                                    </td>   
                                    <td class="dataCell">
                                        <apex:outputText value="{!records.ast.Department_Class__r.Name}"/>
                                    </td>   
                                    <td class="dataCell">
                                        <apex:outputText value="{!records.ast.Account.Name}"/>
                                    </td>
                                    <!-- <td class="dataCell">
                                        <apex:outputText value="{!records.ast.Product2.Asset_Model_No__c}"/>
                                    </td> -->
                                    <td class="dataCell">
                                        <apex:outputField value="{!records.ast.Posting_Date__c}"/>
                                    </td>
                                    <td class="dataCell">
                                        <apex:outputField value="{!records.ast.Extend_Gurantee_DateTo__c}"/>
                                    </td>
                                    <td class="dataCell">
                                        <apex:outputField value="{!records.ast.CurrentContract_End_Date__c}"/>
                                    </td>
                                    <!--XLIU-CJM7Z9 【委托】新建修理提示信息（停产及非修理对象品）LY 20221012 start -->
                                    <td>
                                        <apex:inputField value="{!records.ast.NoPartRiskDate_F__c}" id="partSupplyFinishDate" style="display: none" showDatePicker="false"/>
                                    </td>
                                    <!--XLIU-CJM7Z9 【委托】新建修理提示信息（停产及非修理对象品）LY 20221012 end  -->
                                    
                                </tr>
                            </apex:repeat>
                    </table>
                </apex:pageBlock>
        </apex:pageBlock>
    </apex:outputPanel>
</apex:form>
</apex:page>