<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2015-11-13 下午03:23:39  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:view>
        <a:link id="con_batch_calculate_job_link_id" model="cont.CON771.con_batch_calculate_job" modelaction="update"/>
        <a:link id="con_batch_calculate_job_confirm_link_id" model="cont.CON771.con_batch_calculate_job" modelaction="execute"/>
        <a:link id="con_flt_int_rate_batch_hand_delete_link_id" url="${/request/@context_path}/modules/cont/CON771/con_flt_int_rate_hand_detele.lsc"/>
        <a:link id="con_flt_int_rate_req_batch_detail_compare_link_id" url="${/request/@context_path}/modules/cont/CON771/con_flt_int_rate_req_batch_detail_compare.lview"/>
        <a:link id="con_flt_int_rate_batch_add_link_id" url="${/request/@context_path}/modules/cont/CON771/con_flt_int_rate_batch_add.lview"/>
        <a:link id="con_flt_int_rate_batch_logs_link_id" url="${/request/@context_path}/modules/cont/CON771/con_flt_int_rate_batch_logs.lview"/>
        <style><![CDATA[
        	.item-slideBar{
			    top:10px;
			    width:180px;
			    height:20px;
			    border:1px solid #009900;
			    background-color:#CCFBD5;
			    color:#009900;
			    font-weight:bold;
			    font-size:12px;
			    text-align:center;
			    line-height:20px;
			    white-space :nowrap;
			    position:absolute;
			}
			
        ]]></style>
        <script type="text/javascript"><![CDATA[
            //超链接渲染
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record, bp_seq) {
                var link_function = '';
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
                if (name == 'contract_number' && value) {
                    link_function = 'on_batch_compare_window';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + value + '</a>';
                }
            };
            
            function on_batch_compare_window(record_id, name) {
                var record = window['${/parameter/@bp_seq}${/parameter/@layout_code}_hls_link_render_record'][record_id + '---' + name];
                var param = record.data;
                param['function_code'] = 'CON771T';
                param['function_usage'] = 'QUERY';
                param['url_title'] = '利率浮动明细';
                param['screen_width'] = '900';
                param['screen_height'] = '500';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_flt_int_rate_req_batch_detail_compare_link_id', null, '${/parameter/@layout_code}');
            }
            
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var batch_id = '${/parameter/@batch_id}';
                var ajax_flag = 'N';
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var calc_win = Leaf.showConfirm('${l:PROMPT}', '计算将先删除已计算未确认的调息合同，并重新检索满足调息的合同清单，并将合同状态设置为冻结状态，是否继续？', function() {
                    ajax_flag = 'Y';
                    Leaf.request({
                        url: $('con_batch_calculate_job_link_id').getUrl(),
                        para: {
                            batch_id: batch_id
                        },
                        success: function(res) {
                            Leaf.SideBar.enable = true;
                            Leaf.SideBar.show({
                                msg: '已提交计算，请等待结果',
                                duration: 2000
                            });
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            loop_query();
                        },
                        error: function(res) {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        faliure: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                }, function(res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                }, 400, 125);
                calc_win.on('close', function() {
                    if (ajax_flag == 'N') {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    }
                });
            };
            
            window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
                var batch_id = '${/parameter/@batch_id}';
                var ajax_flag = 'N';
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var confirm_win = Leaf.showConfirm('${l:PROMPT}', ' 是否确认该批次所有合同利率浮动计算结果，确认后将更新合同现金流数据，是否继续？', function() {
                    ajax_flag = 'Y';
                    Leaf.request({
                        url: $('con_batch_calculate_job_confirm_link_id').getUrl(),
                        para: {
                            batch_id: batch_id
                        },
                        success: function(res) {
                            Leaf.SideBar.enable = true;
                            Leaf.SideBar.show({
                                msg: '已提交确认，请等待结果',
                                duration: 2000
                            });
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            loop_query();
                        },
                        error: function(res) {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        faliure: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                }, function(res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                }, 400, 125);
                confirm_win.on('close', function() {
                    if (ajax_flag == 'N') {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    }
                });
            };
            
            window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
                var batch_id = '${/parameter/@batch_id}';
                var win = new Leaf.Window({
                    id: 'con_flt_int_rate_batch_logs_link_winid',
                    url: $('con_flt_int_rate_batch_logs_link_id').getUrl(),
                    params: {
                        winid: 'con_flt_int_rate_batch_logs_link_winid',
                        batch_id: batch_id
                    },
                    title: '日志',
                    width: 600,
                    height: 400
                });
            };
            
            
            function loop_query() {
                var head_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_flt_int_rate_req_batch');
                var head_ds = $(head_ds_id);
                head_ds.setQueryParameter('batch_id', '${/parameter/@batch_id}');
                head_ds.query();
            }
            
            var global_batch_status = null;
            
            //新增和加载时调用(form)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
                if (record) {
                    global_batch_status = record.get('batch_status');
                }
                if (global_batch_status == 'IN_CALCULATE' || global_batch_status == 'IN_CONFIRM') {
                    set_status_field_color('yellow');
                }
                setbtnInterval();
            };
            
            //查询时调用(grid,table,gridBox)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) {
                qpara['batch_id'] = '${/parameter/@batch_id}';
            };
            
            window['${/parameter/@layout_code}_CON_DETAIL_RESULT_USER_BUTTON1_layout_dynamic_tab_click'] = function() {
                var line_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_change_req_flt');
                var win = new Leaf.Window({
                    id: 'con_flt_int_rate_batch_add_link_winid',
                    url: $('con_flt_int_rate_batch_add_link_id').getUrl(),
                    params: {
                        winid: 'con_flt_int_rate_batch_add_link_winid',
                        batch_id: '${/parameter/@batch_id}',
                        ds_id: line_ds
                    },
                    title: '合同选择',
                    width: 600,
                    height: 200
                });
                win.on('close', function() {
                    $(line_ds).query();
                });
            };
            
            window['${/parameter/@layout_code}_CON_DETAIL_RESULT_USER_BUTTON2_layout_dynamic_tab_click'] = function() {
                var line_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_change_req_flt');
                var records = $(line_ds).getSelected();
                if (!records.length) {
                    Leaf.showMessage('提示', '请先选择要删除的行');
                    return;
                }
                var batch_id = '${/parameter/@batch_id}';
                var ajax_flag = 'N';
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var confirm_win = Leaf.showConfirm('${l:PROMPT}', ' 是否确认删除？', function() {
                    ajax_flag = 'Y';
                    var params = {};
                    var selectData = [];
                    for (var i = 0;i < records.length;i++) {
                        var record = records[i];
                        record.set('_status', 'delete');
                        selectData.push(record.data);
                    }
                    params['details'] = selectData;
                    Leaf.request({
                        url: $('con_flt_int_rate_batch_hand_delete_link_id').getUrl(),
                        para: params,
                        success: function(res) {
                            Leaf.SideBar.enable = true;
                            Leaf.SideBar.show({
                                msg: '删除成功',
                                duration: 2000
                            });
                            $(line_ds).query();
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        error: function(res) {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        faliure: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                }, function(res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                }, 400, 125);
                confirm_win.on('close', function() {
                    if (ajax_flag == 'N') {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    }
                });
            };
            
            var btncolorInterval = setInterval(function() {
                var batch_status_field_id = '${/parameter/@layout_code}_CON_DETAIL_HEAD_CON_FLT_INT_RATE_REQ_BATCH_BATCH_STATUS';
                var field_color = null;
                if (global_batch_status == 'IN_CALCULATE' || global_batch_status == 'IN_CONFIRM') {
                    field_color = 'yellow';
                } else {
                    if (global_batch_status == 'ERROR_CALCULATE' || global_batch_status == 'ERROR_CONFIRM') {
                        field_color = 'red';
                    } else if (global_batch_status == 'CONFIRM') {
                        field_color = 'green';
                    }
                }
                if (Ext.get(batch_status_field_id)) {
                    Ext.get(batch_status_field_id).child('input').setStyle({
                        background: field_color
                    });
                    clearInterval(btncolorInterval);
                    btncolorInterval = null;
                }
            }, 1000);
            
            function set_status_field_color(field_color) {
                var batch_status_field_id = '${/parameter/@layout_code}_CON_DETAIL_HEAD_CON_FLT_INT_RATE_REQ_BATCH_BATCH_STATUS';
                Ext.get(batch_status_field_id).child('input').setStyle({
                    background: field_color
                });
            }
            
            function setbtnInterval() {
                var btnInterval = setInterval(function() {
                    var field_color = null;
                    if (global_batch_status == 'IN_CALCULATE' || global_batch_status == 'IN_CONFIRM') {
                        field_color = 'yellow';
                        set_status_field_color(field_color);
                        loop_query();
                    } else {
                        if (global_batch_status == 'ERROR_CALCULATE' || global_batch_status == 'ERROR_CONFIRM') {
                            field_color = 'red';
                        } else if (global_batch_status == 'CONFIRM') {
                            field_color = 'green';
                        }
                        set_status_field_color(field_color);
                    }
                    clearInterval(btnInterval);
                    btnInterval = null;
                }, 5000);
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
