<apex:page id="Page" standardController="Product2" extensions="OrderSearchProductController" sidebar="false" showHeader="false" >
	<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
    <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
    <head>
    	<script type="text/javascript">
	    	function selectAll() {
	            var checklist = j$("input[name='checklist']");
	            var all = j$(escapeVfId("checkAll"));
	            for(var i = 0; i < checklist.length; i++){
	                if (all[0].checked == true) {
	                    checklist[i].checked = true;
	                } else {
	                    checklist[i].checked = false;
	                }
	            }
	        }
	        function searchHospitalJs() {
			    blockme();
			    searchHospital();
			}
			var QuoteEntryMaxLine = 200;
			function setProductList() {

	            var nextLine = top.window.opener.getLastLineNoNext(window.opener.document);
	            //alert('nextLine'+nextLine);
	            var hasCheckedCnt = 0;
	            var checklist = j$("input[name='checklist']");
				
	            for(var i=0; i<checklist.length; i++){
	                if (checklist[i].checked) {
                        hasCheckedCnt++;
                        if (nextLine < QuoteEntryMaxLine) {
                            SetProductId(nextLine, i);
							//alert(i);
                            nextLine++;
                        } else {
                            alert('Over Max Line ' + QuoteEntryMaxLine);
                            return false;
                        }
                    }
	            }
	            if (hasCheckedCnt == 0) {
	                alert('请至少选择一个产品进行追加。');
	                return false;
	            }
	            // window.opener.addrowJS();
				// window.opener.location.reload();
				// window.opener.top.location.SaveJs();
            	top.window.close();
	        }
	        function SetProductId(lineno, i) {

				var Asset_Model_No = j$(escapeVfId("Page:mainForm:SearchResult:productInfoList:"+ i +":Asset_Model_No")).text();
	        	var Name = j$(escapeVfId("Page:mainForm:SearchResult:productInfoList:"+ i +":Name")).text();
	        	var SFDA_Expiration_Date = j$(escapeVfId("Page:mainForm:SearchResult:productInfoList:"+ i +":SFDA_Expiration_Date")).text();
	        	var Packing_list_manual = j$(escapeVfId("Page:mainForm:SearchResult:productInfoList:"+ i +":Packing_list_manual")).text();
	        	var ProIdHidden1 = j$(escapeVfId("Page:mainForm:SearchResult:productInfoList:"+ i +":ProIdHidden")).value();

	        	// alert(SFDA_Expiration_Date);
	        	var strDateTime = SFDA_Expiration_Date;
				var myDate = new Date(strDateTime);
				var myDateStr = myDate.toLocaleString().substring(0, 8);
				// alert(myDate.toLocaleString());

	        	// fxk
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":NameHidden")).attr('value',Name);
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":SFDAHidden")).attr('value',myDateStr);
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":PackingHidden")).attr('value',Packing_list_manual);
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":ProIdHidden")).attr('value',ProIdHidden1);

				// fxk

				//lt 20211029 start
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":proModel")).text(Asset_Model_No);
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":Name")).text(Name);
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":SFDA_Expiration_Date")).text(SFDA_Expiration_Date);
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":Packing_list_manual")).text(Packing_list_manual);

				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":proModel")).attr('value',Asset_Model_No);
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":Name")).attr('value',Name);
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":SFDA_Expiration_Date")).attr('value',SFDA_Expiration_Date);
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":Packing_list_manual")).attr('value',Packing_list_manual);

				//No  //20211103 lt
				window.opener.j$(escapeVfId("Page:mainForm:productInfoList:"+ lineno +":indexNo")).text(parseInt(lineno)+1);

				//lt 20211029 end
	        }

    	</script>
    	<style type="text/css">
	        div#iframelike {
	            color: #fff;
	            height: 200px;
	            overflow-y: auto;
	            overflow-x: hidden;
	        }
	        .pure-table {
				border-collapse: collapse; 
				border-spacing: 0; 
				empty-cells: show;
				border: 1px solid #cbcbcb;
				width: 100%;
			}
			.pure-table-horizontal th,.pure-table-horizontal td {
				border-width: 0 0 1px 0;
				border-bottom: 1px solid #cbcbcb;
			}
	
			.pure-table-horizontal tbody>tr:last-child>td {
				border-bottom-width: 0;
			}
	    </style>
    </head>

    <body>
	    <apex:form id="mainForm">
	    	<apex:outputPanel id="message">
            	<apex:pageMessages ></apex:pageMessages>
        	</apex:outputPanel>

	    	<apex:actionFunction name="searchHospital" action="{!searchHospital}" rerender="SearchResult" onComplete="unblockUI();">
        	</apex:actionFunction>

	    	<apex:outputPanel id="listsTable">
	    		<apex:pageBlock id="idSearchSetProduct" title="产品检索">
	    			<table style="width:900px;" border="0">
	    				<tr>
			               	<th>{!$Label.Asset_No}</th>
							   <td><apex:inputText id="ProModel" value="{!ProModel}" style="width:200px" required="false"/></td>
							<td>
								<apex:commandButton value="检索" action="{!searchHospital}" style="width:100px;height:30px;" />
								&nbsp;&nbsp;&nbsp;
								<!-- disabled="{!Hascl}" lt add 没有产品时 不可点击追加按钮 -->
								<apex:commandButton value="追加" style="width:100px;height:30px;" disabled="{!Hascl}" rerender="dummy" onclick="setProductList();return false;"/>
							</td>
			            </tr>
	    			</table>
	    		</apex:pageBlock>
	    		<apex:pageBlock id="SearchResult" title="检索结果">
		            	<table id="theTable_header" class="pure-table pure-table-horizontal" border="1" style=" border-collapse:collapse; table-layout:fixed;">
			                <tr>
			                    <th style="text-align:left;width:5%;"><input type="checkbox" id="checkAll" onclick="selectAll()" style="width:10px;"/>{!$Label.Selected}</th>
								<!-- 20211029 lt add start -->
								<th style="text-align:left;width:20%;">产品型号</th>
			                    <th style="text-align:left;width:45%;">产品名称</th>
			                    <th style="text-align:left;width:20%;">效期</th>
								<!-- 20211029 lt add end -->

			                    <th style="text-align:left;width:10%;">{!$ObjectType.Product2.fields.Packing_list_manual__c.label}</th>
			                </tr>
			            </table>
			        <div id="iframelike">
			            <table id="theTable_body" class="pure-table pure-table-horizontal" border="1" style=" border-collapse:collapse; table-layout:fixed;">
			            		<apex:repeat value="{!productInfoList}" var="pros" id="productInfoList">
				                	<tr>
					                    <td class="dataCell" style="width:5%;text-align:left;">
					                        <input type="checkbox" name="checklist" style="width:10px"/>
					                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					                    </td>
				                		<td class="dataCell" style="text-align:left;width:20%;">
				                			<apex:inputHidden id="ProIdHidden" value="{!pros.pro.Id}"/>
				                           <apex:outputField id="Asset_Model_No" value="{!pros.pro.Asset_Model_No__c}"/>
				                        </td>
				                        <td class="dataCell" style="text-align:left;width:45%;">
				                           <apex:outputField id="Name" value="{!pros.pro.Name}"/>
				                        </td>
				                        <td class="dataCell" style="text-align:left;width:20%;">
				                           <apex:outputField id="SFDA_Expiration_Date" value="{!pros.pro.SFDA_Expiration_Date__c}"/>
				                        </td>
					                    <td class="dataCell" style="text-align:left;width:10%;">
				                           <apex:outputField id="Packing_list_manual" value="{!pros.pro.Packing_list_manual__c}"/>
				                        </td>
				                	</tr>
				            	</apex:repeat>
			        	</table>
			        </div>
		        </apex:pageBlock>
		    </apex:outputPanel>
		</apex:form>
	</body>
</apex:page>