<?xml version="1.0" encoding="UTF-8"?>

<!--
    $Author: sf
$Date: 2019/09/24 21:19
$Revision: 1.0
$Purpose: 商业伙伴授信维护
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="basic.get_sys_default_time" rootPath="sys_default_time"/>
    </a:init-procedure>
    <a:view>
        <a:link id="credit_enhance_detail_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="hls361N_update_credit_link_id" model="hls.HLS361N.hls_bp_master_credit_update_status" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
        Leaf.onReady(function() {
            var credit_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_credit_hd');
            $(credit_ds).setQueryParameter('bp_credit_hd_id', ${/parameter/@bp_credit_hd_id});
            $(credit_ds).query();

        })
        var  dirty_flag='N';
        //更新时调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
            dirty_flag='Y';
        };
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var credit_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_credit_hd');
            var record =$(credit_ds).getCurrentRecord();
            var credit_date_from=Leaf.formatDate(record.get('credit_date_from'))
            var credit_date_to=Leaf.formatDate(record.get('credit_date_to'));
            var total_amount=record.get('credit_total_amount');
            var used_credit_amount=record.get('used_amount');
            if (dirty_flag=='Y'){
                if(credit_date_from>credit_date_to){
                    $L.showErrorMessage("错误",'终止日需大于生效日',null,null);
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    return false;
                }
                if(credit_date_to<Leaf.formatDate(new Date())){
                    $L.showErrorMessage("错误",'终止日早于当前时间',null,null);
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    return false;
                }
                Leaf.request({
                    url: $('hls361N_update_credit_link_id').getUrl(),
                    para: {
                        bp_credit_hd_id    :   record.get('bp_credit_hd_id'),
                        credit_total_amount:   total_amount,
                        credit_date_from   :   credit_date_from,
                        credit_date_to     :   credit_date_to,
                        used_amount: record.get('used_amount'),
                        bp_id:record.get('bp_id')
                    },
                    success: function ()  {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $('${/parameter/@winid}').close();
                        //$('credit_ds').query();

                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this,
                    sync:true
                });
             }else{
                if('${/parameter/@credit_status}'=='APPROVED'){
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    $('${/parameter/@winid}').close();
                    // $('credit_ds').query();
                }
                else if('${/parameter/@credit_status}'=='REJECT'){

                    Leaf.request({
                        url: $('hls361N_update_credit_link_id').getUrl(),
                        para: {
                            bp_credit_hd_id    :   record.get('bp_credit_hd_id'),
                            credit_total_amount:   total_amount,
                            credit_date_from   :   credit_date_from,
                            credit_date_to     :   credit_date_to,
                            used_amount: record.get('used_amount'),
                            bp_id:record.get('bp_id')
                        },
                        success: function ()  {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $('${/parameter/@winid}').close();
                        },
                        error: function() {

                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        failure: function() {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                }
            }
        }


]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>