<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
    </a:init-procedure>
    <a:view>
        <script><![CDATA[
        var header = $jq('meta[name=_csrf_header]').attr('content');
        var token = $jq('meta[name=_csrf]').attr('content');
        $jq(document).ajaxSend(function (e, xhr, options) {
            xhr.setRequestHeader(header, token);
        });

        function saveClick() {
            if (document.getElementById('importFile').value) {
                var fileName = document.getElementById('importFile').value;
                var fileType = fileName.substr(fileName.lastIndexOf("."));
                if (fileType != '.xls' && fileType != '.xlsx') {
                    alert('${l:SELECT_CORRECT_IMPORT_FILE}');
                } else {
                    var formData = new FormData(document.getElementById('importForm'));
                    formData.append("session_id",${/session/@session_id});
                    formData.append("template_code", 'HLCM_SBO_REPLACE');
                    // var formData = new FormData(document.getElementById('importForm'));
                    Leaf.Masker.mask(Ext.getBody(), '正在导入模板。。。');
                    $jq.ajax({
                        url: '${/request/@context_path}/hls/importExcel/import',
                        type: 'post',
                        processData: false,
                        contentType: false,
                        data: formData,
                        success: function (res) {
                            Leaf.Masker.unmask(Ext.getBody());
                            // Leaf.Masker.unmask(Ext.getBody());
                            // $('${/parameter/@winid}').close();
                            if (res.success) {
                                // document.getElementById('importForm').submit();
                                Leaf.SideBar.show({
                                    msg: '保存成功',
                                    duration: 2000
                                });
                                $('${/parameter/@winid}').close();
                            } else {
                                if(res.error){ Leaf.showErrorMessage('提示', res.error.message);}
							else if(res.message){ Leaf.showErrorMessage('提示', res.message);}
                            }
                        },
                        failure: function (res) {
                            Leaf.Masker.unmask(Ext.getBody());
                            Leaf.showErrorMessage('提示', res.message);
                        },
                        error: function (res) {
                            Leaf.Masker.unmask(Ext.getBody());
                            Leaf.showErrorMessage('提示', res.message);
                        }
                    });
                }
            } else {

                Leaf.showMessage('${l:PROMPT}', '未上传数据导入文件！');

            }
        }

        function reInput() {
            //重置修改后的文件
            var file = document.getElementById('importFile');
            file.value = "";
        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="label_ds" autoCreate="true">
                <a:fields>
                    <a:field name="label2" defaultValue="${l:STRICT_IMPORTED_TEMPLATE_DATA}"/>
                    <a:field name="label3" defaultValue="${l:PRODUCT_MASTER_DATA_IMPORT}"/>
                    <a:field name="label4" defaultValue="${l:IMPORTER_ONLY_SUPPORTS}"/>
                    <a:field name="label5" defaultValue="${l:READ_THE_ABOVE_CAREFULLY}"/>
                    <a:field name="label6" defaultValue="${l:THE_IMPORT_IS_COMPLETE}"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:fieldSet style="margin-left:10px;margin-top:10px;" title="IMPORT_CONSIDERATIONS" width="400">
            <a:label name="label2" bindTarget="label_ds" style="margin-left:10px;" width="380"/>
            <a:label name="label3" bindTarget="label_ds" style="margin-left:10px;" width="380"/>
            <a:label name="label4" bindTarget="label_ds" style="margin-left:10px;" width="380"/>
            <a:label name="label5" bindTarget="label_ds" style="color:#055A78;font-weight:bold;margin-left:10px;"
                     width="380"/>
            <a:box column="2" row="1" style="margin-left:-3px;">
                <a:label name="label6" bindTarget="label_ds" style="color:#055A78;font-weight:bold;margin-left:10px;"
                         width="266"/>
                <!--                <input onclick="downloadTemp()" style="width:64px;" type="button" value="模板下载"/>-->

            </a:box>
        </a:fieldSet>
        <a:fieldSet style="margin-left:10px;margin-top:10px;" title="TMPLT_IMPORT_FILE" width="400">

            <form name="upload" id="importForm"
                  action="${/request/@context_path}/modules/hls/HLS301/hls_sbo_import_upload_info.lview?_csrf=${/session/@_csrf.token}"
                  enctype="multipart/form-data" method="post">
                <label style="margin-left:10px;margin-top:10px"><![CDATA[${l:PLEASE_SELECT_A_FILE}]]></label>
                <input name="content" id="importFile" style="margin-bottom:4px;width:160px;height:22px;" type="file"
                       onclick="reInput()"/>
                <input id="hls301_upload_id" onclick="saveClick()" style="margin-left:50px;margin-top:10px;width:60px;"
                       type="button" value="导入"/>
                <!--<input type="hidden" name="bp_id" value=""  id="hiddenField"  />-->
            </form>
        </a:fieldSet>
    </a:view>
</a:screen>
