<!--
	 * [FrameNumUploadController description]
	 * @Author   lijinhuan
	 * @DateTime 2022-11-04T18:31:03+0800
	 * @return   [进口单证上传]
-->
<apex:page controller="FrameNumUploadController"   showHeader="false"   sidebar="false" id="allPage"  title="进口单证上传">
<!-- action="{!init}"  -->
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<script type="text/javascript">
	// var popupBox;
	// popupBox = new SimpleDialog("CSVImportDialogId", false);  // 不可拖动
	// popupBox.createDialog();
	// function openPopupCSV() {
 //        popupBox.setTitle("导入CSV文件");
 //        popupBox.importContentNode(document.getElementById("{!$Component.allForm.popupBox}"));
 //        popupBox.show(document.getElementById("{!$Component.allForm.popupBox}"));
 //    }
    // 显示文件名
  //   function show(){
		// var fbody = document.getElementById("file_input").files[0];
  //       if (typeof fbody === "undefined") {
  //           alert("请选择CSV文件");
		// }else{
		// 	document.getElementById('uploadFile').placeholder = fbody.name;
  //           popupBox.hide();
		// }
		
  //   }
    // 取消
  //   function cancle(){
		// var obj = document.getElementById('file_input');
		// obj.outerHTML = obj.outerHTML;
		// document.getElementById('uploadFile').placeholder = '请选择文件...';
		// popupBox.hide();
  //   }

    function remoteLocationPost() {
        var fbody = document.getElementById("file_input").files[0];
        if (typeof fbody === "undefined") {
            alert("请选择CSV文件");
            return;
        }
        else {
        	var reader = new FileReader();
        	reader.readAsText(fbody,"gb2312");//在前台改乱码问题
            reader.onload = function(val) {
                if(this.result.split("\n").length - 1 > {!detailCountLimit}){
                    alert("文件不可超过" + {!detailCountLimit} + "行");
                    return;
                }
                // 判断CSV文件BOM，若包含BOM，则删除。
                if (this.result.charCodeAt(0) === 0xFEFF) {  // 如果第一个字符的编码为utf8
                    this.result = this.result.substr(1);  // 在utf-8编码中，三个隐藏的字节 0xEF 0xBB 0xBF被视为一个字符 EFBBBF(UTF8) FEFF(unicode) 65279
                }
                blockme();
                passToController(this.result);
            }
            // popupBox.hide();
        }
    }
    function showErr(){
        var flag = j$("#haveErr").val();
        if(flag == 'true'){
            j$("#ErrFile").css("display", "");
        } 
    }
    function exportJs(){
        exportcsv();
        j$("#ErrFile").css("display", "none");
    }
</script>
<div style="margin:50px auto;width: 350px;">
<!-- Replace parentId attribute with Id of an object that supports attachments -->
<!-- parentId 机身号管理表名 用来视图、匹配 -->
<c:fileUpload parentId="FrameNumManage"/>
<apex:form id="allForm">
	<apex:outputPanel id="message">
        <apex:pageMessages />
    </apex:outputPanel>
	<apex:actionFunction name="passToController" action="{!importCSVFile}" rerender="allForm, message, checEventFrame" oncomplete="showErr(),unblockUI();">
        <apex:param name="csvData" value="" />
    </apex:actionFunction>
    <apex:actionFunction name="exportcsv" action="{!exportBycsv}"/>
	<!-- <apex:outputPanel style="display:none">
		<apex:outputPanel id="popupBox" layout="block">
		    <input type="file" id="file_input" name="attFile" accept=".csv" /><br/>
		    <center>
		        <apex:commandButton value="确认" onclick="show();return false;" style="width: 20%; margin: 20px 10px 0px 10px" />
		        <apex:commandButton value="取消" onclick="cancle();return false;" style="width: 20%; margin: 20px 10px 0px 10px" />
		    </center>
		</apex:outputPanel>
	</apex:outputPanel> -->
	<apex:outputPanel id="pageallPanel">
    <input type="hidden" id="haveErr" name="haveErr" value="{!haveErr}" />
    <div style="
        background-color: #F8F8F8;
        border: 1px solid #EAEAEA;
        border-radius: 4px 4px 4px 4px;
        color: #333333;
        font-size: 12px;
        padding: 6px;
        width: 400px;
    ">
        <table cellpadding="0" cellspacing="0" class="uploadTable">
            <tbody>
            <tr>
                <td style="padding-right:5px;">数据导入</td>
                <td>
                    <input type="file" id="file_input" name="attFile" accept=".csv" />
                </td>
                <td class="buttonTD">
                    <apex:commandButton onclick="remoteLocationPost(); return false;" value="导入" rerender="allForm,checEventFrame"/>
                </td>
                <td class="buttonTD">
                    <apex:commandButton value="导入"  style="pointer-events: none; cursor: default; opacity: 0;" /><!--为了样式统一好看 -->
                </td>
            </tr>
            <tr id="ErrFile" style="display:none" >
                <td colspan="4">
                   <apex:commandbutton onclick="exportJs();return false;" value="查看"/>
                </td>
            </tr>
        </tbody></table>
    </div>
	<!-- <table style="margin-left: 10px;">
		<tr><th colspan="4" >&nbsp;</th></tr>
        <tr>
		<td>数据导入</td>
        <td>
        	<input name="suitDepartment"  id="uploadFile" size="20" type="text" placeholder = "请选择文件..." onclick="openPopupCSV(); return false;" />
        </td>
        <td>
        	<apex:commandButton onclick="remoteLocationPost(); return false;" value="导入" rerender="allForm,checEventFrame"/>
        </td>
        </tr>
    </table> -->
    </apex:outputPanel>
</apex:form>
</div>
</apex:page>