<?xml version="1.0" encoding="UTF-8"?>
<!--
  create by nyl  2014-12-3 
  for contract context create
-->
<a:screen xmlns:s="leaf.plugin.script" xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <s:server-script import="birt_print_path.js"><![CDATA[
        	$ctx.parameter.birt_print_path = birt_print_path['birt_print_path'];
    	]]></s:server-script>
        <a:model-query fetchAll="true" model="cont.CON620.get_sysdate" rootPath="sysdate"/>
    </a:init-procedure>
    <a:view>
        <a:link id="legal_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con_dunning_letter_cancel_link_id" model="cont.CON628.con_dunning_letter_cancel" modelaction="batch_update"/>
        <a:link id="con628_bp_address_link_id" url="${/request/@context_path}/modules/cont/CON637/con_bp_address.lsc"/>
        <script type="text/javascript"><![CDATA[
            function con628_dunning_letter_cancel() {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_dunning_letter');
                var records = $(ds_id).getSelected();
                var param = new Object();
                var datas = [];
                var data = {};
                if (records.length == 0) {
                    return;
                }
            
                for (var i = 0;i < records.length;i++) {
                    data = records[i].data;
            
                    data['_status'] = 'update';
                    datas.push(data);
                }
            
                param['details'] = datas;
            
            
                Leaf.request({
                    url: $('con_dunning_letter_cancel_link_id').getUrl(),
                    para: datas,
                    success: function(res) {
            
                        Leaf.SideBar.show({
                            msg: '操作成功',
                            duration: 2000
                        });
            
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $(ds_id).query();
                    },
            
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            }
            //作废
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            
                Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认?', function okFun() {
                    con628_dunning_letter_cancel();
                });
            };
            
            //新增和加载时调用(form)
            window['${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
            
                var query_ds_id = '${/parameter/@layout_code}_F_QUERY__ds';
                if (ds.id == query_ds_id) {
            
                    record.set('send_date_from', '${/model/sysdate/record/@first_day}');
                    record.set('send_date_to', '${/model/sysdate/record/@sys_date}');
                }
            };
            
            //导出
            window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
            
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_dunning_letter');
                var grid_id = ds_id.replace('ds', 'layout_grid_id');
            
                $(grid_id)._export();
            
            
            };
            
            function con628_bp_address_print() {
            /* 
                var birt_print_path = '${/parameter/@birt_print_path}';
                var url_1 = birt_print_path + '?__report=reports?__report=reports/bp/' + 'bp_address.rptdesign' + '&&__format=pdf';
                var url_1_param = '&&batch_id=' + ${/session/@session_id};
                window.open(url_1 + url_1_param); */
            
                //bp_address.rptdesign
                var url_l = '${/request/@context_path}/reports?__report=reports/bp/' + 'bp_address.rptdesign' + '&&__format=pdf';
                var url_l_param = '&&batch_id=' + ${/session/@session_id};
                window.open(url_l + url_l_param);
            }
            
            //打印bp_address
            window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
            
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_dunning_letter');
                var records = $(ds_id).getSelected();
                if (records.length < 1) {
                    Leaf.showMessage('提示', '请选择数据！', null, 350);
                    return;
                }
                var param = new Object();
                var datas = [];
                var para = {};
            
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                for (var i = 0;i < records.length;i++) {
                    para = records[i].data;
                    para['batch_id'] = ${/session/@session_id};
                    para['_status'] = 'update';
                    datas.push(para);
                }
            
                Leaf.request({
                    url: $('con628_bp_address_link_id').getUrl(),
                    para: datas,
                    success: function(res) {
            
                        Leaf.SideBar.show({
                            msg: '打印成功',
                            duration: 2000
                        });
            
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        //打印
                        con628_bp_address_print();
                    },
                    sync: true,
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            };
            
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
            
                if (name == 'contract_number') {
                    return '<a href="javascript:open_contract_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
                }
            
                return value;
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
