<?xml version="1.0" encoding="UTF-8"?>
<!--
  create by nyl  2014-12-3 
  for contract context create
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <a:model-query model="cus.CUS100.cus_default_values" rootPath="cus_default_value"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con643_submit_link" model="cont.CON640.submit_rpt" modelaction="execute"/>
        <a:link id="con643_get_control_id_link" model="db.rpt_report_control_pkg.checkin_rpt" modelaction="execute"/>
        <a:link id="con643_refresh_link" model="db.rpt_report_control_pkg.refresh_rpt" modelaction="execute"/>
        <a:link id="con638_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
            var g_control_id;
            var g_calc_date;
            
            function eg_rpt100_detail_query() {
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            
                $(ds_id).query();
            }
            
            function eg_rpt100_head_query() {
                var rpt_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'rpt_report_control');
                // var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                $(rpt_ds_id).setQueryParameter('control_id', g_control_id);
                $(rpt_ds_id).query();
                // $(ds_id).query();
            }
            
            function eg_rpt100_status_find(control_id) {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                Leaf.request({
                    url: $('con643_refresh_link').getUrl(),
                    para: {
                        'control_id': control_id
                    },
                    success: function(res) {
                        Leaf.Masker.unmask(Ext.getBody());
                        if (res.result.job_stauts == 'FINISH') {
                            eg_rpt100_head_query();
                            eg_rpt100_detail_query();
                        }
                        eg_rpt100_head_query();
                    },
                    failure: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });
            }
            
            function eg_rpt100_submit(control_id) {
                var rpt_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'rpt_report_control');
                var calc_date = $(rpt_ds_id).getAt(0).get('calc_date');
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                Leaf.request({
                    url: $('con643_submit_link').getUrl(),
                    para: {
                        'control_id': control_id,
                        'calc_date': calc_date
                    },
                    success: function(res) {
                        Leaf.Masker.unmask(Ext.getBody());
                        eg_rpt100_head_query();
                    },
                    failure: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });
            }
            
            //计算
            window['${/parameter/@layout_code}_quote_layout_dynamic_click'] = function() {
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                eg_rpt100_submit(g_control_id);
            
            };
            
            //更新时调用
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                var rpt_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'rpt_report_control');
                if (ds.id == rpt_ds_id && name == 'calc_date') {
                    g_calc_date = record.get('calc_date');
                }
            };
            
            //查询
            window['${/parameter/@layout_code}_print_layout_dynamic_click'] = function() {
                var rpt_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'rpt_report_control');
            
                var status = $(rpt_ds_id).getAt(0).get('status');
                var control_id = g_control_id;
                if (status == 'FINISH') {
                    eg_rpt100_detail_query();
                } else {
                    eg_rpt100_status_find(control_id);
                }
                //  eg_rpt100_detail_query();
            };
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
                if (name == 'contract_number') {
                    return '<a   href="javascript:con620n_open_contract_win(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
                }
                if (name == 'risk_flag_n' && value) {
                    //return  '<font color="red" >'+value+'</font>';
                    return '<a style="color:red"  href="#">' + value + '</a>';
                }
                if (name == 'status' && value) {
                    return '<a style="color:red"  href="#">' + value + '</a>';
                }
                if (name == 'last_submit_date' && value) {
                    return '<a style="color:red"  href="#">' + value + '</a>';
                }
                return value;
            };
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
            
                var rpt_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'rpt_report_control');
                if (ds.id == rpt_ds_id) {
                    if (record.get('calc_date')) {
            
                       } else {
                        var calc_date;
                        if (!g_calc_date) {
                            g_calc_date = '${/model/cus_default_value/record/@sys_date}';
                        }
                        $(rpt_ds_id).getAt(0).set('calc_date', g_calc_date);
                    }
            
                }
            };
            
            
            //导出
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var grid_id = ds_id.replace('ds', 'layout_grid_id');
                $(grid_id)._export();
            
            
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <script type="text/javascript"><![CDATA[
        	    Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                Leaf.request({
                    url: $('con643_get_control_id_link').getUrl(),
                    para: {'report_name':'${/parameter/@function_code}' },
                    success: function(res) {
                        Leaf.Masker.unmask(Ext.getBody());

                       g_control_id =res.result.control_id;
                    },
                    failure: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                }); 
		]]></script>
    </a:view>
</a:screen>
