<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:view>
        <a:link id="con731_quote_link" url="${/request/@context_path}/modules/hls/HLS500N/hls_fin_calculator_update_n.lview"/>
        <a:link id="con731_quote_calc_link" model="cont.CON731.calc_change_req" modelaction="execute"/>
        <a:link id="con731_calc_change_data_link" model="cont.CON731.calc_ccr_data" modelaction="execute"/>
        <a:link id="con731_calc_change_data_et_link" model="cont.CON731.calc_ccr_et_data" modelaction="execute"/>
        <a:link id="con731_submit_link" model="cont.CON731.submit_change_req" modelaction="execute"/>
        <a:link id="con731_cancel_link" model="cont.CON731.cancel_change_req" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
            window['${/parameter/@layout_code}_quote_layout_dynamic_click'] = function() {
                var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var req_record = $(req_ds_id).getAt(0);
                var calc_session_id = req_record.get('calc_session_id');
                var quo_win;
                var calc_type = 'CLASSIC_CALCULATOR';
                var document_category = req_record.get('document_category');
                if ($(req_ds_id).validate()) {
                    if (req_record.dirty) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                        return;
                    }
                    if (!calc_session_id) {
                        Leaf.request({
                            url: $('con731_quote_calc_link').getUrl(),
                            para: {
                                change_req_id: ${/parameter/@change_req_id},
                                calc_session_id: calc_session_id
                            },
                            success: function(res) {
                                req_record.set('calc_session_id', res.result.calc_session_id);
                                req_record.dirty = false;
                                quo_win = new Leaf.Window({
                                    id: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                                    params: {
                                        document_id: ${/parameter/@change_req_id},
                                        document_category: document_category,
                                        maintain_type: 'UPDATE',
                                        calc_session_id: res.result.calc_session_id,
                                        quotation_id: null,
                                        dsId: req_ds_id,
                                        winId: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                                        global_flag: 'Y',
                                        id_num: 0,
                                        calc_type: calc_type,
                                        recreate_L_formula: 'N'
                                    },
                                    url: $('con731_quote_link').getUrl(),
                                    fullScreen: true,
                                    draggable: true
                                });
                                quo_win.addListener('close', function() {
                                    $(req_ds_id).query();
                                });
                            },
                            failure: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            error: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            scope: this
                        });
                    } else {
                        quo_win = new Leaf.Window({
                            id: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                            params: {
                                document_id: ${/parameter/@change_req_id},
                                document_category: document_category,
                                maintain_type: 'UPDATE',
                                calc_session_id: calc_session_id,
                                quotation_id: null,
                                dsId: req_ds_id,
                                winId: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                                global_flag: 'Y',
                                id_num: 0,
                                calc_type: calc_type,
                                recreate_L_formula: 'N'
                            },
                            url: $('con731_quote_link').getUrl(),
                            fullScreen: true,
                            draggable: true
                        });
                        quo_win.addListener('close', function() {
                            $(req_ds_id).query();
                        });
                    }
                }
            };
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                var req_type = '${/parameter/@document_type_2nd}';
                if (name == 'ccr_start_times') {
                    if (value && req_type != 'ET') {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                        Leaf.request({
                            url: $('con731_calc_change_data_link').getUrl(),
                            para: {
                                contract_id: ${/parameter/@change_req_id},
                                ccr_start_times: value
                            },
                            success: function(res) {
                                record.set('ccr_outstanding_prin_tax_incld', res.result.ccr_outs_prin_tax_incld);
                                record.set('ccr_outstanding_prin_ti_total', res.result.ccr_outs_prin_ti_total);
                                record.set('ccr_overdue_rental', res.result.ccr_overdue_rental);
                                record.set('ccr_penalty', res.result.ccr_penalty);
                                record.set('ccr_outstanding_times', res.result.ccr_outstanding_times);
                                record.set('ccr_outstanding_rental', res.result.ccr_outstanding_rental);
                                record.set('ccr_fee', res.result.ccr_fee);
                                record.set('parameter', res.result.parameter);
                                record.set('et_interest', res.result.et_interest);
                                record.set('legal_fee', res.result.legal_fee);
                                record.set('ccr_deposit_balance', res.result.ccr_deposit_balance);
            
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            failure: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            error: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            scope: this
                        });
                    }
                } else if (name == 'et_date') {
            
                    if (req_type == 'ET' && value) {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                        Leaf.request({
                            url: $('con731_calc_change_data_et_link').getUrl(),
                            para: {
                                contract_id: ${/parameter/@change_req_id},
                                et_date: value
                            },
                            success: function(res) {
                                record.set('ccr_outstanding_prin_tax_incld', res.result.ccr_outs_prin_tax_incld);
                                record.set('ccr_outstanding_prin_ti_total', res.result.ccr_outs_prin_ti_total);
                                record.set('ccr_overdue_rental', res.result.ccr_overdue_rental);
                                record.set('ccr_penalty', res.result.ccr_penalty);
                                record.set('ccr_outstanding_times', res.result.ccr_outstanding_times);
                                record.set('ccr_outstanding_rental', res.result.ccr_outstanding_rental);
                                record.set('ccr_start_times', res.result.ccr_start_times);
                                record.set('ccr_fee', res.result.ccr_fee);
                                record.set('parameter', res.result.parameter);
                                record.set('et_interest', res.result.et_interest);
                                record.set('legal_fee', res.result.legal_fee);
                                record.set('ccr_deposit_balance', res.result.ccr_deposit_balance);
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            failure: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            error: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            scope: this
                        });
                    }
                }
            };
            window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
                var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var req_record = $(req_ds_id).getAt(0);
                if ($(req_ds_id).validate()) {
                    if (req_record.dirty) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                        return;
                    }
                    Leaf.showConfirm('${l:HLS.PROMPT}', '${l:HLS.ARE_YOU_SURE_TO_SUBMIT}', function() {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                        Leaf.request({
                            url: $('con731_submit_link').getUrl(),
                            para: {
                                change_req_id: ${/parameter/@change_req_id}
                            },
                            success: function(res) {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                $('${/parameter/@winid}').close();
                            },
                            failure: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            error: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            scope: this
                        });
                    });
                }
            };
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                Leaf.showConfirm('${l:HLS.PROMPT}', '${l:CON731.CANCEL_CHANGE_CONFIRM}', function() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    Leaf.request({
                        url: $('con731_cancel_link').getUrl(),
                        para: {
                            change_req_id: ${/parameter/@change_req_id}
                        },
                        success: function(res) {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $('${/parameter/@winid}').close();
                        },
                        failure: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        error: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                });
            }; /*加载时调用*/
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
                var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                if (ds.id == req_ds_id) {
                    var price_list = '${/parameter/@price_list}';
                    if (price_list && !$(req_ds_id).getAt(0).get('price_list')) {
                        $(req_ds_id).getAt(0).set('price_list', price_list);
                    }
                }
            };
        ]]></script>
    </a:view>
</a:screen>
