<?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_calc_ccr_fee_link" model="cont.CON731.calc_ccr_fee" modelaction="execute"/>-->
        <a:link id="calc_leasse_amount_link" model="cont.CON731.calc_leasse_date" modelaction="execute"/>
        <a:link id="calc_pay_amount_link" model="cont.CON731.calc_leasse_pay" modelaction="execute"/>
        <a:link id="calc_tenant_amount_link" model="cont.CON733.calc_tenant_change_req" modelaction="execute"/>
        <a:link id="con731_quote_link" url="${/request/@context_path}/modules/hls/HLS500N/hls_fin_calculator_update_n.lview"/>
        <a:link id="con733_quote_calc_change_req_link" model="cont.CON733.calc_change_req" 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"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>
        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_doc_quotation_link_id" url="${/request/@context_path}/modules/hls/HLS500/hls_fin_doc_quotation.lsc"/>
        <script type="text/javascript"><![CDATA[
        Ext.ux.Lightbox.register('a[ref=img]', true);
        Leaf.onReady(function() {
                var ds_con_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_QUOTATION_01', 'con_contract');
                if ($(ds_con_id)) {
                        $(ds_con_id).setQueryParameter('contract_id','${/parameter/@contract_id}');
                        $(ds_con_id).query();
                }
        });
        function open_contract_win(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['function_code'] = 'CON301';
            param['function_usage'] = 'QUERY';
            param['download'] = 'Y';
            param['maintain_type'] = 'UPDATE';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_modify_link', ds_id);
        }
        window['${/parameter/@layout_code}_quote_layout_dynamic_click'] = function() {
                $('${/parameter/@layout_code}_quote').disable(); //按钮不可用
            var req_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_QUOTATION_01', '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 = '${/parameter/@calc_type}';
            var document_category = req_record.get('document_category');
            // 變更起始期數
            var ccr_start_times = req_record.get('ccr_start_times');
            //變更剩餘期數
            var ccr_outstanding_times = req_record.get('ccr_outstanding_times');
            var change_document_type = req_record.get('change_document_type');
            if ($(req_ds_id).validate($('${/parameter/@layout_code}_quote').enable())) {
                if (req_record.dirty) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                    return;
                }
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('con733_quote_calc_change_req_link').getUrl(),
                    para: {
                        change_req_id: ${/parameter/@change_req_id},
                        ccr_start_times: ccr_start_times,
                        ccr_outstanding_times: ccr_outstanding_times,
                        calc_session_id: calc_session_id
                    },
                    success: function(res) {
                            $('${/parameter/@layout_code}_quote').enable();
                        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: '${/parameter/@calc_type}',
                                recreate_L_formula: 'N'
                            },
                            url: $('con731_quote_link').getUrl(),
                            fullScreen: true,
                            draggable: true
                        });
                        quo_win.addListener('close', function() {
                            $(req_ds_id).query();
                            var cf_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'G_QUOTATION_04', 'con_contract_cashflow');
                            $(cf_ds_id).setQueryParameter('contract_id','${/parameter/@contract_id}');
                            $(cf_ds_id).query();
                        });
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function() {
                            $('${/parameter/@layout_code}_quote').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                            $('${/parameter/@layout_code}_quote').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            }
        };


        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                var ds_con_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_QUOTATION_01', 'con_contract');
                if (ds.id == ds_con_id) {
                        // 承租人变更
                        if ('${/parameter/@layout_code}' == 'CON_TENANT_CHANGE_MODIFY') {
                                // 承租人变更日計算應繳金額相關信息
                                if(name == 'ccr_lease_date'){
                                        Leaf.request({
                                                url: $('calc_tenant_amount_link').getUrl(),
                                                para: {
                                                        change_req_id: ${/parameter/@change_req_id},
                                                        ccr_lease_date: record.get('ccr_lease_date')
                                                },
                                                success: function(res) {
                                                        record.set('ccr_lease_rental', res.result.ccr_lease_rental);
                                                        record.set('ccr_lease_principal', res.result.ccr_lease_principal);
                                                        record.set('ccr_lease_interest', res.result.ccr_lease_interest);
                                                        record.set('ccr_lease_penalty', res.result.ccr_lease_penalty);
                                                },
                                                error: function() {
                                                },
                                                failure: function() {
                                                },
                                                sync: true,
                                                scope: this
                                        });
                                }

                        }
                        // 回款賬戶變更
                        if('${/parameter/@layout_code}' == 'CON_ACCOUNT_CHANGE_MODIFY'){
                                if(name == 'BANK_BRANCH_NUM'){
                                        var bank_account_num_s =record.get('bank_account_num_s');
                                        if(bank_account_num_s == value){
                                                Leaf.showMessage('警告', '现扣款账号和原扣款账号不能重复！');
                                                return;
                                        }
                                }
                        }
                        // 租赁计划變更
                        if('${/parameter/@layout_code}' == 'CON_CHANGE_MODIFY'){debugger
                                var lease_times = record.get('lease_times')||0;
                                if(name == 'ccr_start_times'){
                                        var ccr_outstanding_times = record.get('ccr_outstanding_times')||0;
                                        var curr_times = minus(plus(value || 0,ccr_outstanding_times||0),1);
                                        if(curr_times > lease_times){
                                                record.set('extend_flag','Y');
                                                record.set('deflation_flag','N');
                                        }
                                }
                                if(name == 'ccr_outstanding_times'){
                                        var ccr_start_times = record.get('ccr_start_times')||0;
                                        var curr_times = minus(plus(value || 0,ccr_start_times||0),1);
                                        if(curr_times < lease_times){
                                                record.set('extend_flag','N');
                                                record.set('deflation_flag','Y');
                                        }
                                }
                        }
                }
        };

        //新增和加载时调用form
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {

        };

        window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
                $('${/parameter/@layout_code}_submit_approval').disable();
            var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var req_record = $(req_ds_id).getAt(0);
            var case_type = '';
            var document_type = '${/parameter/@document_type}';
            var calc_session_id = req_record.get('calc_session_id');
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                if ($(req_ds_id).validate($('${/parameter/@layout_code}_submit_approval').enable())) {
                    // if (req_record.dirty) {
                    //     Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                    //     window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    //     return;
                    // }
                        $('${/parameter/@layout_code}_submit_approval').disable();
                        $('${/parameter/@layout_code}_save').disable();
                        if('${/parameter/@layout_code}' == 'CON_CHANGE_MODIFY'){
                            $('${/parameter/@layout_code}_quote').disable();
                        }
                        $('${/parameter/@layout_code}_user_button1').disable();
                        $('${/parameter/@layout_code}_user_button2').disable();
                    setTimeout(window['${/parameter/@layout_code}_SAVE_LAYOUT_DYNAMIC_CLICK'](con731_submit), 2000);
                } else {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                }
        };

        function con731_submit() {
            var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var req_record = $(req_ds_id).getAt(0);
            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},
                    layout_code: '${/parameter/@layout_code}'
                },
                success: function(res) {
                    $('${/parameter/@winid}').close();
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                failure: function() {
                        $('${/parameter/@layout_code}_submit_approval').enable();
                        $('${/parameter/@layout_code}_save').enable();
                        if('${/parameter/@layout_code}' == 'CON_CHANGE_MODIFY'){
                                $('${/parameter/@layout_code}_quote').enable();
                        }
                        $('${/parameter/@layout_code}_user_button1').enable();
                        $('${/parameter/@layout_code}_user_button2').enable();
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                error: function() {
                        $('${/parameter/@layout_code}_submit_approval').enable();
                        $('${/parameter/@layout_code}_save').enable();
                        if('${/parameter/@layout_code}' == 'CON_CHANGE_MODIFY'){
                                $('${/parameter/@layout_code}_quote').enable();
                        }
                        $('${/parameter/@layout_code}_user_button1').enable();
                        $('${/parameter/@layout_code}_user_button2').enable();
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                scope: this
            });
        }

        //保存submitsuccess调用
        window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function(ds, record, res, bp_seq) {
            var ca_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_cashflow');
            if (ca_ds_id) {
                $(ca_ds_id).query();
            }
            // var con_contract_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            // var record = $(con_contract_ds_id).getCurrentRecord();
            // Leaf.request({
            //     url: $('con731_calc_ccr_fee_link').getUrl(),
            //     para: {
            //         contract_id: ${/parameter/@change_req_id},
            //         bp_id: record.get('bp_id_tenant'),
            //         lease_item_id: record.get('lease_item_id'),
            //         pattern: record.get('lease_item_id_n'),
            //         machine_number: record.get('machine_number'),
            //         interim_times: record.get('interim_times'),
            //         ccr_start_times: record.get('ccr_start_times'),
            //         ccr_document_type: record.get('ccr_document_type'),
            //         hd_user_col_v04: record.get('hd_user_col_v04'),
            //         btb_payment_date: record.get('btb_payment_date')
            //     },
            //     success: function(res) {
            //         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //     },
            //     failure: function() {
            //         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //     },
            //     error: function() {
            //         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //     },
            //     scope: this
            // });


            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        };


        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                $('${/parameter/@layout_code}_user_button1').disable();
            Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认取消变更？', 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) {
                            $('${/parameter/@layout_code}_user_button1').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $('${/parameter/@winid}').close();
                    },
                    failure: function() {
                            $('${/parameter/@layout_code}_user_button1').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                            $('${/parameter/@layout_code}_user_button1').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            });
        };

        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
                $('${/parameter/@layout_code}_user_button1').disable();

                $('${/parameter/@layout_code}_user_button1').enable();

        };

        //////附件上传
        window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record, bp_seq) {
            var link_function = '';
            window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
            if (name == 'leasse_attachment') {
                link_function = '${/parameter/@layout_code}_leasse_cdd_attachtment_upload';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            } else if (name == 'contract_number' && value) {
                return '<a href="javascript:open_contract_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
            }else if (name == 'leasse_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])) {

                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
                }
            } else if (name == 'e_attachment') {
                link_function = '${/parameter/@layout_code}_e_cdd_attachtment_upload';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            } else if (name == 'e_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])) {

                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
                }
            } else if (name == 'pay_attachment') {
                link_function = '${/parameter/@layout_code}_pay_cdd_attachtment_upload';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            } else if (name == 'pay_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])) {

                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
                }
            } else if (name == 'leasehold_attachment') {
                link_function = '${/parameter/@layout_code}_leasehold_cdd_attachtment_upload';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            } else if (name == 'leasehold_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])) {

                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
                }
            } else if (name == 'dept_attachment') {
                link_function = '${/parameter/@layout_code}_dept_cdd_attachtment_upload';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            } else if (name == 'dept_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])) {

                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
                }
            } else if (name == 'part_attachment') {
                link_function = '${/parameter/@layout_code}_part_cdd_attachtment_upload';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            } else if (name == 'part_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])) {

                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
                }
            } else if (name == 'paydate_attachment') {
                link_function = '${/parameter/@layout_code}_paydate_cdd_attachtment_upload';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            } else if (name == 'paydate_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])) {

                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
                }
            }
            else if (name == 'cut_attachment') {
                link_function = '${/parameter/@layout_code}_cut_cdd_attachtment_upload';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            } else if (name == 'cut_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])) {

                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
                }
            }else if (name == 'description') {
                if (record.get('important_flag') == 'Y') {
                    return '<font color="RED">' + value + '</font>';
                }
                return value;
            }
        };

        window['${/parameter/@layout_code}_leasse_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
            var record = $(ds_id).findById(id);
            if (record.get('contract_attch_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@query_flag}' == 'Y') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_LEASSE_ATTH&header_id=' + record.get('contract_attch_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_LEASSE_ATTH&header_id=' + record.get('contract_attch_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_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}_e_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
            var record = $(ds_id).findById(id);
            if (record.get('contract_attch_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@query_flag}' == 'Y') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_E_ATTH&header_id=' + record.get('contract_attch_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_E_ATTH&header_id=' + record.get('contract_attch_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_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}_pay_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
            var record = $(ds_id).findById(id);
            if (record.get('contract_attch_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@query_flag}' == 'Y') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_PAY_ATTH&header_id=' + record.get('contract_attch_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_PAY_ATTH&header_id=' + record.get('contract_attch_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_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}_leasehold_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
            var record = $(ds_id).findById(id);
            if (record.get('contract_attch_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@query_flag}' == 'Y') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_LH_ATTH&header_id=' + record.get('contract_attch_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_LH_ATTH&header_id=' + record.get('contract_attch_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_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}_dept_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
            var record = $(ds_id).findById(id);
            if (record.get('contract_attch_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@query_flag}' == 'Y') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_DEPT_ATTH&header_id=' + record.get('contract_attch_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_DEPT_ATTH&header_id=' + record.get('contract_attch_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_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}_part_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
            var record = $(ds_id).findById(id);
            if (record.get('contract_attch_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@query_flag}' == 'Y') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_PART_ATTH&header_id=' + record.get('contract_attch_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_PART_ATTH&header_id=' + record.get('contract_attch_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_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}_paydate_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
            var record = $(ds_id).findById(id);
            if (record.get('contract_attch_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@query_flag}' == 'Y') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_PAYDATE_ATTH&header_id=' + record.get('contract_attch_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_PAYDATE_ATTH&header_id=' + record.get('contract_attch_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_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}_cut_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
            var record = $(ds_id).findById(id);
            if (record.get('contract_attch_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@query_flag}' == 'Y') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_CUT_ATTH&header_id=' + record.get('contract_attch_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CCR_UNIVERSAL_CUT_ATTH&header_id=' + record.get('contract_attch_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });

                win.on('close', function() {
                    record.ds.query();
                });
            } else {
                Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
            }
        };

        /// 附件上传 end
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
