<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query model="cont.CON114.get_sys_import_head_id" rootPath="header"/>
        <a:import-excel header_id="${/model/header/record/@header_id}" separator="," status_field="/parameter/@ImportSuccess" template_code="WH_IMPORT" user_id="${/session/@user_id}"/>
        <a:model-query defaultWhereClause="header_id=${/model/header/record/@header_id} and TEMPLATE_CODE = &apos;WH_IMPORT&apos;" model="cont.CON114.get_import_status" rootPath="status"/>
    </a:init-procedure>
    <a:view>
        <a:link id="import_link" url="${/request/@context_path}/modules/cont/CON114/con_contract_adj_detail.lview"/>
        <a:link id="import_save_data_link" url="${/request/@context_path}/modules/cont/CON114/import_save_data.lsc"/>
        <script type="text/javascript"><![CDATA[
            function view() {
                window.location.href = $('import_link').getUrl() + '?contract_id=${/parameter/@contract_id}';
                window.close();
            }
            
            function success() {
            
                Leaf.showInfoMessage('${l:HLS.PROMPT}', '导入成功', function callback() {
                    window.location.href = $('import_link').getUrl() + '?contract_id=${/parameter/@contract_id}';
                });
            
            }
            
            function back() {
             	window.location.href = $('import_link').getUrl() + '?contract_id=${/parameter/@contract_id}';
            }
            
            function loadComplete() {
                if ('${/model/status/record/@status}' == 'NEW') {
                    var param = {};
                    param['batch_id'] = '${/parameter/@batch_id}';
                    param['adj_start_times'] = '${/parameter/@adj_start_times}';
                    param['header_id'] = '${/model/header/record/@header_id}';
                    param['contract_id'] = '${/parameter/@contract_id}';
            
                    Leaf.request({
                        url: $('import_save_data_link').getUrl(),
                        para: param,
                        success: function() {
                            Leaf.SideBar.show({
                                msg: '导入成功!',
                                duration: 2000
                            });
                            success();
                        },
                        failure: function() {
                            
                        },
                        error: function() {
                            
                        },
                        scope: this
                    });
            
                } else {
                    Ext.get('success_form').setStyle('display', 'none');
                    Ext.get('failure_form').setStyle('visibility', 'visible');
                }
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="error_ds">
                <a:fields>
                    <a:field name="import_field_1" prompt="import_field_1"/>
                    <a:field name="import_field_2" prompt="import_field_2"/>
                    <a:field name="import_field_3" prompt="import_field_3"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:form id="success_form" style="visibility:hidden" title="IMPORT_SUCCESS" width="400">
                <a:button click="view" text="PROMPT.VIEW"/>
            </a:form>
            <a:hBox>
                <a:button click="back" text="HAP_BACK"/>
            </a:hBox>
            <a:form id="failure_form" height="400" style="visibility:hidden" title="ERROR_MESSAGE" width="980">
                <a:grid bindTarget="error_ds" height="340" navBar="true" width="980">
                    <a:columns>
                        <a:column name="import_field_1"/>
                        <a:column name="import_field_2"/>
                        <a:column name="import_field_3"/>
                    </a:columns>
                </a:grid>
            </a:form>
        </a:screenBody>
        <script type="text/javascript"><![CDATA[
	  		loadComplete();
	  	]]></script>
    </a:view>
</a:screen>
