<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: copy from hec  
    $Date: 2011-7-29 下午04:08:50  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query
                defaultWhereClause="TABLE_NAME=&apos;T_GOODS_BATCH&apos; and TABLE_PK_VALUE = ${/parameter/@batch_id}"
                model="cont.CON810.fnd_atm_attachment_multi" rootPath="con810_counts"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con810_atm_attachment_link" model="cont.CON810.fnd_atm_attachment_multi" modelaction="query"/>


        <script type="text/javascript"><![CDATA[
        function saveClick() {
            var detail_mask = $('goods_batch_import_upload_winid').wrap;
            if (document.getElementById('importFile').files.length === 0) {
                Leaf.showMessage("消息","文件没有上传！");
                return;
            }
            Leaf.Masker.mask(detail_mask, '导入中。。。。');


            var con810_formData = new FormData();
            con810_formData.append('sequence', ${/model/con810/record/counts} +1);
            con810_formData.append('fileToUpload', document.getElementById('importFile').files[0]);
            con810_formData.append('pkvalue', '${/parameter/@batch_id}');
            con810_formData.append('source_type', 'T_GOODS_BATCH');

            var record_id;

            $jq.ajax({
                url: '${/request/@context_path}/atm_upload.lsc?_csrf=${/session/@_csrf.token}',
                type: "post",
                data: con810_formData,
                cache: false,
                processData: false,
                contentType: false,
                async: false,
                success: function (res) {
                    var previewUrl = '';
                    Leaf.request({
                        url: $('con810_atm_attachment_multi_query').getUrl(),
                        para: {
                            table_name: 'T_GOODS_BATCH',
                            table_pk_value: '${/parameter/@batch_id}'
                        },
                        success: function (res) {

                            if (res.result.record && res.result.record.record_id) {

                                record_id = res.result.record.record_id;
                                previewUrl = encodeURIComponent('${/request/@context_path}/sys/office/view?_csrf=${/session/@_csrf.token}&sourceTypeCode=fnd_atm_attachment_multi&sourcePkValue=' + res.result.record.record_id);
                                // window.open('${/request/@context_path}/sys/office/view?sourceTypeCode=fnd_atm_attachment_multi&sourcePkValue=' + res.result.record.record_id);
                            }
                            if (document.getElementById('importFile').value) {
                                var fileName = document.getElementById('importFile').value;
                                var fileType = fileName.substr(fileName.lastIndexOf("."));
                                if (fileType != '.xls' && fileType != '.xlsx') {
                                    alert('请选择正确的导入文件！');
                                    Leaf.Masker.unmask(detail_mask);
                                } else {
                                    $jq('#importForm').attr('action',
                                        '${/request/@context_path}/modules/cont/CON810/goods_batch_import_trans_upload.lview?_csrf=${/session/@_csrf.token}&batch_id=${/parameter/@batch_id}&preview=' +
                                        previewUrl + '&record_id=' + record_id);
                                    document.getElementById('importForm').submit();
                                }
                            } else {
                                Leaf.Masker.unmask(detail_mask);

                            }

                        },
                        failure: function() {
                            Leaf.Masker.unmask(detail_mask);
                        },
                        error: function() {
                            Leaf.Masker.unmask(detail_mask);
                        },
                    });


                }

            })


        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="label_ds" autoCreate="true">
                <a:fields>
                    <!--<a:field name="label1" defaultValue="注意："/>-->
                    <a:field name="label2" defaultValue="1、  严格按照导入模板整理数据，检查必输事项是否缺少数据。"/>
                    <a:field name="label3" defaultValue="2、  关闭Excel文件后，方可进行产品主数据导入。"/>
                    <a:field name="label4" defaultValue="3、  本导入程序只支持Office Excel。"/>
                    <a:field name="label5" defaultValue="仔细阅读上述事项，并检查确认无误。"/>
                    <a:field name="label6" defaultValue="导入完毕后，请在系统内核实数据是否导入成功。"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:fieldSet style="margin-left:10px;margin-top:10px;" title="导入注意事项" width="400">
            <!--<a:label name="label1" bindTarget="label_ds" width="380"/>-->
            <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:label name="label6" bindTarget="label_ds" style="color:#055A78;font-weight:bold;margin-left:10px;"
                     width="380"/>
        </a:fieldSet>
        <a:fieldSet style="margin-left:10px;margin-top:10px;" title="导入文件" width="400">
            <form name="upload" id="importForm"
                  action="${/request/@context_path}/modules/cont/CON810/goods_batch_import_trans_upload.lview?batch_id=${/parameter/@batch_id}&amp;_csrf=${/session/@_csrf.token}"
                  enctype="multipart/form-data" method="post">
                <label style="margin-left:10px;margin-top:10px;"><![CDATA[请选择文件:]]></label>
                <input name="CONTENT" id="importFile" style="margin-bottom:4px;width:160px;height:22px;" type="file"/>
                <input onclick="saveClick()" style="margin-left:50px;margin-top:10px;width:60px;" type="button"
                       value="导入"/>
            </form>
        </a:fieldSet>
    </a:view>
</a:screen>
