111
沙世明
2022-11-22 928399eceec50e3d37ea08669a12789a9410a9d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!--
     * [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: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();
        }
    }
</script>
 
<apex:form id="allForm">
    <apex:outputPanel id="message">
        <apex:pageMessages />
    </apex:outputPanel>
    <apex:actionFunction name="passToController" action="{!importCSVFile}" rerender="allForm, message, checEventFrame" oncomplete="unblockUI();">
        <apex:param name="csvData" value="" />
    </apex:actionFunction>
    <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">
    <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>
</apex:page>