<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: duzhihong  
    $Date: 2015-1-14 下午3:01:09  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:view>
        <a:link id="batch_adjust_detail_link" url="${/request/@context_path}/modules/cont/CON115/con_batch_adjust_interest_detail.lview"/>
        <a:link id="batch_adjust_detail_query_link" url="${/request/@context_path}/modules/cont/CON115/con_batch_adjust_detail_for_query.lview"/>
        <a:link id="batch_adjust_interest_test_link" model="cont.CON115.con_batch_adjust_interest_hd" modelaction="execute"/>
        <a:link id="fnd_base_rate_link" url="${/request/@context_path}/modules/cont/CON115/fnd_base_rate.lview"/>
        <script type="text/javascript"><![CDATA[
            function lock_list_window() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            }
            
            function unlock_list_window() {
                Leaf.Masker.unmask(Ext.getBody());
            }
            
            function query_bacth_adjust_hd() {
                $('bacth_adjust_hd_ds').query();
            }
            
            function submitsuccess(ds, res) {
                ds.query();
            }
            
            function open_detail(value, record, name) {
                if (record.isNew) {
                    return '';
                } else {
                    if (name == 'base_rate') {
                        return '<a href="javascript:base_reate(' + record.get('batch_hd_id') + ');">' + '基准利率定义' + '</a>';
                    } else {
            
                        return '<a href="javascript:batch_adjust(\'' + record.get('batch_hd_id') + '\',\'' + record.get('approval_status') + '\');">' + '调息' + '</a>';
                    }
                }
            
            }
            
            function base_reate(batch_hd_id) {
                var url = $('fnd_base_rate_link').getUrl();
                var win = new Leaf.Window({
                    id: 'fnd_base_rate_detail_winid',
                    url: url,
                    params: {
                        batch_hd_id: batch_hd_id,
                        currency: 'CNY',
                        win_id: 'fnd_base_rate_detail_winid'
                    },
                    title: '${l:FND251.LINK.RATE_DETAIL}',
                    width: 800,
                    height: 400
                });
                win.on('close', function() {
                    $('bacth_adjust_hd_ds').query();
                });
            }
            
            function batch_adjust(batch_hd_id, approval_status) {
                
                // lock_list_window();
                // Leaf.request({
                // url: $('batch_adjust_interest_test_link').getUrl(),
                // para: {
                // batch_hd_id: batch_hd_id
                // },
                // success: function(args) {
                // unlock_list_window();
                var url;
                //if (approval_status == 'APPROVED' || approval_status == 'APPROVING') {
                //  url = $('batch_adjust_detail_query_link').getUrl();
                //} else {
                url = $('batch_adjust_detail_link').getUrl();
                //}
            
                var win = new Leaf.Window({
                    id: 'batch_adjust_detail_winid',
                    url: url,
                    params: {
                        batch_hd_id: batch_hd_id,
                        approval_status: approval_status,
                        win_id: 'batch_adjust_detail_winid'
                    },
                    title: '调息明细界面',
                    fullScreen: true
                });
                win.on('close', function() {
                    $('bacth_adjust_hd_ds').query();
                });
                // },
                // scope: this,
                // sync: true
                // });
            }
            
            
            function batch_adjust_test_cal() {
                var record = $('bacth_adjust_hd_ds').getCurrentRecord();
                var batch_hd_id = record.get('batch_hd_id');
            
                if (record.get('approval_status') == 'APPROVED') {
                    Leaf.showMessage('提示', '当前无法计算');
                    return;
                }
                if (batch_hd_id) {
            
                    Leaf.showConfirm('提示', '确定要调息测算吗？', function() {
                        var now_date = new Date();
                        var description = '调息测算' + Leaf.formatDate(now_date);
                        lock_list_window();
                        setTimeout(function() {
            
                            Leaf.request({
                                url: $('batch_adjust_interest_test_link').getUrl(),
                                para: {
                                    batch_hd_id: batch_hd_id
                                },
                                success: function(args) {
                                    unlock_list_window();
            
                                    $('bacth_adjust_hd_ds').query();
                                },
                                failure: function() {
                                    unlock_list_window();
                                },
                                error: function() {
                                    unlock_list_window();
                                },
                                scope: this
                            });
                        }, 1000);
                    }, function() {
                        unlock_list_window();
                    });
                }
            }
            
            
            function grid_editorFunction(record, name) {
                if (record.isNew) {
                    if (name == 'adjust_date') {
                        return 'grid_dataPicker';
                    }
                }
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=BATCH_ADJUST_REQ"/>
        <a:dataSets>
            <a:dataSet id="approval_status_ds" lookupCode="CON_WFL_STATUS"/>
            <a:dataSet id="bacth_adjust_hd_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="batch_num"/>
                    <a:field name="approval_status_n" displayField="code_value_name" options="approval_status_ds" returnField="code_value" valueField="approval_status"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="bacth_adjust_hd_ds" autoQuery="true" model="cont.CON115.con_batch_adjust_interest_hd" queryDataSet="bacth_adjust_hd_query_ds" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="batch_num"/>
                    <a:field name="description" required="true"/>
                    <a:field name="approval_status_n" displayField="code_value_name" options="approval_status_ds" returnField="code_value" valueField="approval_status"/>
                    <a:field name="batch_hd_id"/>
                    <a:field name="adjust_date" required="true"/>
                </a:fields>
                <a:events>
                    <a:event name="submitsuccess" handler="submitsuccess"/>
                    <a:event name="query" handler="aut_authority_list_validate_query"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton bind="batch_adjust_grid" type="add"/>
                <a:gridButton bind="batch_adjust_grid" type="save"/>
                <a:gridButton bind="batch_adjust_grid" type="delete"/>
                <a:gridButton click="batch_adjust_test_cal" text="测算"/>
                <!-- <a:gridButton click="" text="批量调息"/> -->
                <!-- <a:gridButton bind="batch_adjust_grid" type="save"/> -->
                <a:gridButton click="query_bacth_adjust_hd" text="HLS.QUERY"/>
            </a:screenTopToolbar>
            <a:form column="2" labelWidth="100" title="查询">
                <a:textField name="batch_num" bindTarget="bacth_adjust_hd_query_ds" prompt="测算编号"/>
                <a:textField name="description" bindTarget="bacth_adjust_hd_query_ds" prompt="说明"/>
            </a:form>
            <a:grid id="batch_adjust_grid" bindTarget="bacth_adjust_hd_ds" marginHeight="150" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="batch_num" prompt="批量调息编号" width="150"/>
                    <a:column name="description" editor="bacth_ta" prompt="说明" width="250"/>
                    <a:column name="adjust_date" editorFunction="grid_editorFunction" prompt="预测时间" renderer="Leaf.formatDate"/>
                    <a:column name="base_rate" align="center" prompt="基准利率定义" renderer="open_detail"/>
                    <a:column name="batch_hd_id" align="center" prompt="测算详细" renderer="open_detail"/>
                    <a:column name="approval_status_n" prompt="状态"/>
                </a:columns>
                <a:editors>
                    <a:textArea id="bacth_ta"/>
                    <a:datePicker id="grid_dataPicker"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
