<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2015-12-02 下午1:29:07  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_contract_cchag_change_req_submit_link_id" model="cont.CON711.con_contract_cchag_change_req_submit" modelaction="update"/>
        <a:link id="con_contract_cchag_change_req_cancel_link_id" model="cont.CON711.con_contract_cchag_change_req_cancel" modelaction="update"/>
        <a:link id="hls_fin_calculator_update_n_link_id" url="${/request/@context_path}/modules/hls/HLS500N/hls_fin_calculator_update_n.lview"/>
        <a:link id="${/parameter/@layout_code}_con500_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_con_contract_cchag_change_price_list_id" url="${/request/@context_path}/modules/cont/CON711/con_contract_cchag_change_price_list.lview"/>
        <a:link id="${/parameter/@layout_code}_con500_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script type="text/javascript"><![CDATA[
            function get_warning_message(msg) {
                var warning_message, duration;
                if (msg) {
                    warning_message = msg;
                    warning_message = '<font color="red">' + warning_message + '</font>';
                    duration = 8000;
                } else {
                    warning_message = '${l:HLS.SUBMIT_SUCCESS}';
                    duration = 2000;
                }
                parent.Leaf.SideBar.enable = true;
                parent.Leaf.SideBar.show({
                    html: '<div style="background-color:#ccfbd5;position:absolute;padding-top:5px;padding-bottom:5px;padding-left:20px;padding-right:20px;border:0px solid #009900"><b>' + warning_message + '</b></div>',
                    duration: duration
                });
            }
            
            function con710_cchag_calc() {
                var contract_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var contract_record = $(contract_ds_id).getCurrentRecord();
                var calc_session_id = contract_record.get('calc_session_id');
                var document_category = contract_record.get('document_category');
                if ($(contract_ds_id).validate()) {
                    if (contract_record.dirty) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                        return;
                    }
                    if (!calc_session_id) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '该合同还未报价，请核查数据！');
                        return;
                    }
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    var win = new Leaf.Window({
                        id: 'hls_fin_calculator_update_n_link_winid',
                        params: {
                            calc_session_id: calc_session_id,
                            document_id: '${/parameter/@contract_id}',
                            document_category: document_category,
                            maintain_type: 'MODIFY',
                            dsId: contract_ds_id,
                            winId: 'hls_fin_calculator_update_n_link_winid',
                            global_flag: 'Y',
                            id_num: 0,
                            calc_type: 'CLASSIC_CALCULATOR'
                        },
                        url: $('hls_fin_calculator_update_n_link_id').getUrl(),
                        title: '${l:HLS.FIN_CALCULATOR}',
                        fullScreen: true,
                        draggable: true
                    });
                    win.on('close', function() {
                        function calc_window_load() {
                            $(contract_ds_id).un('load', calc_window_load);
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        }
                        $(contract_ds_id).on('load', calc_window_load);
                        $(contract_ds_id).query();
                    });
                }
            }
            
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var change_req_load_flag = 'N',
                con_contract_load_flag = 'N';
            
            //新增和加载时调用(form)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
                if (ds.id.match(/con_contract_ds$/)) {
                    con_contract_load_flag = 'Y';
                    var records = ds.getAll();
                    if (!records.length) {
                        return;
                    }
            
                    for (var i = 0;i < records.length;i++) {
                        //已确认的不可编辑
                        if (records[i].data['insured_flag'] == 'Y') {
            
                            records[i].getField('valid_from').setReadOnly(true);
                            records[i].getField('valid_to').setReadOnly(true);
                        }
                    }
                }
                if (ds.id.match(/con_contract_change_req_ds$/)) {
                    if (!record.get('change_req_number')) {
                        record.dirty = true;
                    }
                    change_req_load_flag = 'Y';
                }
                if (change_req_load_flag == 'Y' && con_contract_load_flag == 'Y') {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                }
            };
            
            
            window['${/parameter/@layout_code}_quote_layout_dynamic_click'] = function() {
                Leaf.SideBar.enable = false;
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_SAVE_LAYOUT_DYNAMIC_CLICK'](con710_cchag_calc);
            };
            
            window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
                var ajax_flag = 'N';
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var confirm_win = Leaf.showConfirm('${HLS.PROMPT}', '${l:HLS.ARE_YOU_SURE_TO_SUBMIT}', function() {
                    ajax_flag = 'Y';
                    Leaf.request({
                        url: $('con_contract_cchag_change_req_submit_link_id').getUrl(),
                        para: {
                            change_req_id: '${/parameter/@change_req_id}'
                        },
                        success: function(res) {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            parent.Leaf.SideBar.enable = true;
                            parent.Leaf.SideBar.show({
                                msg: '${l:HLS.SUBMIT_SUCCESS}',
                                duration: 2000
                            });
                            $('${/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
                    });
                }, function() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                });
                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_button2_layout_dynamic_click'] = function() {
                var ajax_flag = 'N';
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var confirm_win = Leaf.showConfirm('${HLS.PROMPT}', '是否确认取消？', function() {
                    ajax_flag = 'Y';
                    Leaf.request({
                        url: $('con_contract_cchag_change_req_cancel_link_id').getUrl(),
                        para: {
                            change_req_id: '${/parameter/@change_req_id}'
                        },
                        success: function(res) {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            parent.Leaf.SideBar.enable = true;
                            parent.Leaf.SideBar.show({
                                msg: '取消成功',
                                duration: 2000
                            });
                            $('${/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
                    });
                }, function() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                });
                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_button1_layout_dynamic_click'] = function() {
                var con_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var con_record = $(con_id).getCurrentRecord();
                var quo_win = new Leaf.Window({
                    id: '${/parameter/@layout_code}_con_contract_cchag_change_price_list_winid',
                    params: {
                        change_req_id: ${/parameter/@contract_id},
                        winid: '${/parameter/@layout_code}_con_contract_cchag_change_price_list_winid',
                        pre_price_list: con_record.get('price_list'),
                        pre_price_list_name: con_record.get('price_list_n'),
                        ds_id: con_id
                    },
                    url: $('${/parameter/@layout_code}_con_contract_cchag_change_price_list_id').getUrl(),
                    width: 750,
                    height: 170
                });
                quo_win.on('close', function() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            
                    function change_ref_calc(ds) {
                        $(con_id).un('load', change_ref_calc);
                        if (con_record.get('change_price_list_flag') == 'Y') {
                            con_record.set('change_price_list_flag', 'N');
                            con710_cchag_calc();
                        }
                    }
                    $(con_id).on('load', change_ref_calc);
                    $(con_id).query();
                });
            };
            
            
            
            //更新时调用
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var con_contract_mortgage_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_mortgage');
                if (ds.id == con_contract_mortgage_id && name == 'mortgage_class') {
                    if (record.get('mortgage_class') == 'SUBSTANTIVE_MORTGAGE') {
                        var mortgage_serial_number = record.getField('mortgage_serial_number');
                        mortgage_serial_number.setRequired(true);
                    }
                }
            };
            
            window['${/parameter/@layout_code}_con500_cdd_attachtment_upload'] = function(id, name, query_only) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
                if (record.get('check_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}_con500_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    } else {
                        url = $('${/parameter/@layout_code}_con500_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: '${/parameter/@layout_code}_con_cdd_uploadFile_screen_id',
                        width: 850,
                        height: 400
                    });
            
                    win.on('close', function() {
                        record.ds.query();
                    });
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                }
            };
            
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
                window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
                var ds_id = record.ds.id;
                if (name == 'attachment') {
                    link_function = '${/parameter/@layout_code}_con500_cdd_attachtment_upload';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                } else if (name == 'attach_file_name') {
                    if (value != null) {
                        var link = '${/request/@context_path}/atm_download.lsc?attachment_id=';
                        var str = value.split(';;');
                        var url = '';
                        for (var i = 0;i < str.length;i++) {
                            var temp = str[i].split('--');
                            if (!Leaf.isEmpty(temp[0])) {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                        return url;
            
                    }
                }
            };
        ]]></script>
    </a:view>
</a:screen>
