<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zlf 
    $Date: 2014-11-10 下午5:42:24  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script"
          customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <s:server-script import="contract_print_path.js"><![CDATA[
            $ctx.parameter.file_path = con_print_path['con_print_path'];
            $ctx.parameter.tomcat_source = con_print_path['tomcat_source'];
            ]]>
        </s:server-script>
        <a:model-query fetchAll="true" model="cont.CON500.con_contract_get_guid_file_name" rootPath="file_name_path"/>
        <s:server-script import="con_print_path.js"><![CDATA[
            set_parameter_file_path();
            ]]>
        </s:server-script>
    </a:init-procedure>
    <a:view>
        <a:link id="${/parameter/@layout_code}_hls_bp_master_modify_link"
                url="${/request/@context_path}/modules/hls/HLS214N/hls_bp_master_modify.lview"/>
        <!--报价-->
        <a:link id="${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_calc_quotation_header_link_id"
                url="${/request/@context_path}/modules/hls/HLS500/hls_fin_calc_quotation_header.lview"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_calculator_update_link_id"
                url="${/request/@context_path}/modules/hls/HLS500N/hls_fin_calculator_update_n.lview"/>
        <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"/>
        <a:link id="wfl_readonly_pageLink_projectQueryScreen_update_project"
                url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_maintain_readonly.lview"/>
        <a:link id="${/parameter/@layout_code}_con_contract_get_layout_code_link_id"
                model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="contract_lease_item_query_link"
                url="${/request/@context_path}/modules/cont/CON505/con_lease_item_query.lview"/>
        <a:link id="con505_hls_bp_master_query_link"
                url="${/request/@context_path}/modules/hls/HLS215N/hls_bp_master_query.lview"/>
        <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"/>
        <a:link id="${/parameter/@layout_code}_con_contract_inception_execute_id"
                model="cont.CON1100.con_contract_for_excute" modelaction="execute"/>

        <a:link id="${/parameter/@layout_code}_con_contract_inception_update_id"
                model="cont.CON1100.con_contract_for_excute" modelaction="update"/>
        <a:link id="con_contract_bp_delete" model="cont.CON1100.con_contract_bp_delete" modelaction="batch_update"/>

        <a:link id="${/parameter/@layout_code}_con_contract_cashflow_date_update_id"
                model="cont.CON1100.con_contract_excuted" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_con_contract_info_update_id"
                model="cont.CON1100.con_contract_info_update" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_con_contract_info_update_link"
                model="cont.CON1100.con_contract_excuted" modelaction="execute"/>
        <a:link id="${/parameter/@layout_code}_update_content_type_link"
                model="cont.CON1100.con_update_content_type" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_con_contract_score_id"
                model="cont.CON302N.get_if_self_definition" modelaction="update"/>
        <a:link id="con1100_check_agent_credit_amount_link" model="cont.CON1100.check_agent_credit_amount" modelaction="update"/>
        <script src="${/request/@context_path}/javascripts/hap/hlap-all-hty.js" type="text/javascript"/>

        <a:link id="${/parameter/@layout_code}_con_cashflow_wirte_off_detail_link" url="${/request/@context_path}/modules/cont/CON302N/con_cashflow_wirte_off_detail.lview"/>

        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>

        <!--add by chenlingfeng-->
        <a:link id="${/parameter/@layout_code}_con_checklist_content_create_link" model="cont.CON302N.con_checklist_content_create" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_file_copy_from_template_link_id" url="${/request/@context_path}/modules/cont/CON505/file_copy_from_template.lsc"/>
        <a:link id="con_atm_batch_download_pdf_link_id" url="${/request/@context_path}/modules/cont/CON500/con_atm_batch_download_pdf.lsc"/>
        <a:link id="${/parameter/@layout_code}_creat_con_contract_content_link_id" model="cont.CON302N.con_checklist_content_create" modelaction="execute"/>
        <a:link id="${/parameter/@layout_code}_con_batch_dl_link_id" url="${/request/@context_path}/modules/cont/CON500/con_atm_batch_dl.lsc"/>
        <a:link id="${/parameter/@layout_code}_con_batch_pdf_dl_link_id" url="${/request/@context_path}/modules/cont/CON500/con_atm_batch_download_pdf.lsc"/>

        <a:link id="${/parameter/@layout_code}_contract_status_query_link" model="cont.CON302N.con_check_status" modelaction="execute"/>
        <!--end-->

        <!--打印使用-->
        <!-- <a:link id="${/parameter/@layout_code}_calc_quotation_transfer_for_deron_link_id" model="hls.HLS500.hls_fin_calc_quotation_transfer_for_deron" modelaction="update"/> -->
        <script type="text/javascript"><![CDATA[

        Ext.ux.Lightbox.register('a[ref=img]', true);
        //锁屏
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window'] = function () {
            var detail_mask;
            if ('${/parameter/@winid}') {
                if (parent.$L.CmpManager.get('${/parameter/@winid}')) {
                    detail_mask = parent.$('${/parameter/@winid}').wrap;
                    parent.Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                } else {
                    detail_mask = $('${/parameter/@winid}').wrap;
                    Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                }
            } else {
                detail_mask = Ext.getBody();
                Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
            }
        };
        //解屏
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window'] = function () {
            var detail_mask;
            if ('${/parameter/@winid}') {
                if (parent.$L.CmpManager.get('${/parameter/@winid}')) {
                    detail_mask = parent.$('${/parameter/@winid}').wrap;
                    parent.Leaf.Masker.unmask(detail_mask);
                } else {
                    detail_mask = $('${/parameter/@winid}').wrap;
                    Leaf.Masker.unmask(detail_mask);
                }
            } else {
                detail_mask = Ext.getBody();
                Leaf.Masker.unmask(detail_mask);
            }
            if (Ext.get(document.documentElement)) {
                $L.Masker.unmask(Ext.get(document.documentElement));
            }
        };


        //保存前调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function(ds, record) {
            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var check_flag = false;
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var hd_record = $(ds_id).getCurrentRecord();
            var contract_id = hd_record.get('contract_id');
            if(contract_id){
                Leaf.request({
                    url: $('${/parameter/@layout_code}_contract_status_query_link').getUrl(),
                    para: {
                        contract_id: contract_id,
                    },
                    success: function(res) {
                            check_flag  = true;
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        check_flag  = false;
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        check_flag  = false;
                    },
                    sync: true,
                    scope: this
                });
            }else{
                check_flag  = true;
            }
            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            return check_flag;
        };

        function con1100_submit() {

            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var url = $('${/parameter/@layout_code}_con_contract_inception_execute_id').getUrl();
            var record = $(ds_id).getCurrentRecord();
            var data = {
                contractId: record.get('contract_id'),
                leaseExecutionDate: record.get('lease_execution_date')
            };
            if (record.ds.isModified()) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');

                return;
            }
            var cf_count = record.get('cf_count');

            var message = '';

            if (cf_count) {
                message = cf_count + '未完全核销，';
            }
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            Leaf.request(
                {
                    url: $('con1100_check_agent_credit_amount_link').getUrl(),
                    para: {
                        contract_id: record.get('contract_id')
                    },
                    success: function (res) {
                        if (res.result.result == 'Y') {

                            message = '超过代理商授信额度，' + message;
                        }
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        if ($(ds_id).validate()) {
                            Leaf.showConfirm('提示', message + '是否确认执行合同?', function () {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();


                                para = record.data;


                                Leaf.request({
                                    url: url,
                                    para: {
                                        contract_id: record.get('contract_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
                                });

                            });
                        }

                    },
                    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_button2_layout_dynamic_click'] = function () {

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

        };


        //代理商代付客户保证金
        window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var cf_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_cashflow');
            var url = $('${/parameter/@layout_code}_con_contract_inception_update_id').getUrl();
            var record = $(ds_id).getCurrentRecord();
            para = record.data;

            Leaf.showConfirm('提示', '是否确认执行该操作?', function () {
                if ($(ds_id).validate()) {

                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    Leaf.request({
                        url: url,
                        para: {
                            contract_id: record.get('contract_id'),
                            con_deposit_by_agent: record.get('con_deposit_by_agent')
                        },
                        success: function (res) {
                            Leaf.SideBar.show({
                                msg: '执行成功！',
                                duration: 2000
                            });
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $(cf_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
                    });
                }
            });
        }

        //刷新现金流日期
        window['${/parameter/@layout_code}_user_button5_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var cf_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CASHFLOW', 'con_contract_cashflow');
            var url = $('${/parameter/@layout_code}_con_contract_cashflow_date_update_id').getUrl();
            var url2 = $('${/parameter/@layout_code}_con_contract_info_update_id').getUrl();
            var record = $(ds_id).getCurrentRecord();
            para = record.data;

            if (record.ds.isModified()) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                return;
            }

            Leaf.showConfirm('提示', '是否进行此操作，并通知call_center电话确认?', function () {

                if ($(ds_id).validate()) {

                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    Leaf.request({
                        url: url,
                        para: {
                            contract_id: record.get('contract_id'),
                            _status: 'update'
                        },
                        success: function (res) {

                            Leaf.request({
                                url: url2,
                                para: {
                                    contract_id: record.get('contract_id'),
                                    _status: 'update'
                                },
                                success: function (res) {

                                    Leaf.SideBar.show({
                                        msg: '操作成功！',
                                        duration: 2000
                                    });
                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    $(cf_ds_id).query();
                                    $(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
                            });
                        },
                        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_button6_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var url = $('${/parameter/@layout_code}_con_contract_info_update_link').getUrl();
            var record = $(ds_id).getCurrentRecord();
            para = record.data;
            if (record.ds.isModified()) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                return;
            }

            Leaf.showConfirm('提示', '是否确认执行该操作?', function () {

                if ($(ds_id).validate()) {

                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    Leaf.request({
                        url: url,
                        para: {
                            contract_id: record.get('contract_id')
                        },
                        success: function (res) {

                            Leaf.SideBar.show({
                                msg: '执行成功！',
                                duration: 2000
                            });
                            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}_user_button7_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var record = $(ds_id).getCurrentRecord();
            var url = $('${/parameter/@layout_code}_update_content_type_link').getUrl();
            var content_type = record.get('content_type');
            Leaf.showConfirm('提示', '是否确认执行该操作?', function () {
                if (content_type == '02') {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    Leaf.request({
                        url: url,
                        para: {
                            contract_id: record.get('contract_id')
                        },
                        success: function (res) {

                            Leaf.SideBar.show({
                                msg: '执行成功！',
                                duration: 2000
                            });
                            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']();
                            $('${/parameter/@winid}').close();
                        },
                        error: function () {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $('${/parameter/@winid}').close();
                        },
                        scope: this
                    });
                }
                else {
                    Leaf.showMessage('${l:PROMPT}', '非纸质合同，无法修改！');
                }
            });
        }


        //报价
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {
            var url;
            var url2 = $('${/parameter/@layout_code}_con_contract_info_update_id').getUrl();
            var quotation_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var record = $(quotation_ds_id).getCurrentRecord();
            if (record.ds.isModified()) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                return;
            }
            Leaf.showConfirm('提示', '是否进行此操作，并通知call_center电话确认?', function () {
                if ('${/parameter/@calc_type}' == 'LITE_CALCULATOR') {
                    url = $('${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_calc_quotation_header_link_id').getUrl();
                } else if ('${/parameter/@calc_type}' == 'CLASSIC_CALCULATOR') {
                    url = $('${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_calculator_update_link_id').getUrl();
                } else {
                    url = $('${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_calculator_update_link_id').getUrl();
                    // Leaf.showMessage('${l:PROMPT}', '${l:HLS.CALC_TYPE_IS_NULL}');
                    //    return;
                }

                if ($(quotation_ds_id).validate()) {
                    if (!record.get('price_list') || !record.get('currency') || !record.get('lease_times')) {
                        Leaf.showMessage('${l:PROMPT}', '${l:HLS.QUOTATION_EXECUTE_AFTER_SAVE}');
                        return;
                    }

                    Leaf.request({
                        url: url2,
                        para: {
                            contract_id: record.get('contract_id'),
                            _status: 'update'
                        },
                        success: function (res) {

                            Leaf.SideBar.show({
                                msg: '操作成功！',
                                duration: 2000
                            });
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $(quotation_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
                    });


                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    //直接进入报价页面
                    var win = new Leaf.Window({
                        id: 'hls_fin_calc_quotation_update_link_winid',
                        params: {
                            document_id: record.get('contract_id'),
                            document_category: 'CONTRACT',
                            maintain_type: 'MODIFY',
                            calc_session_id: record.get('calc_session_id'),
                            quotation_id: record.get('quotation_id'),
                            dsId: quotation_ds_id,
                            winId: 'hls_fin_calc_quotation_update_link_winid',
                            global_flag: 'Y',
                            id_num: 0,
                            calc_type: '${/parameter/@calc_type}',
                            recreate_L_formula: 'N'
                        },
                        url: url,
                        fullScreen: true,
                        draggable: true
                    });
                    win.on('close', function () {
                        $(quotation_ds_id).query();
                    });

                }
            });
        };
        window['${/parameter/@layout_code}_received_amount_detail'] = function (ds_id, id, name, query_only) {
            var url = $('${/parameter/@layout_code}_con_cashflow_wirte_off_detail_link').getUrl();
            var record = $(ds_id).findById(id);
            if (record) {
                var win = new Leaf.Window({
                    id: 'con_cashflow_wirte_off_detail_window',
                    url: url,
                    params: {
                        cashflow_id: record.get('cashflow_id'),
                        winid: 'con_cashflow_wirte_off_detail_window'
                    },
                    draggable: true,
                    fullScreen: true
                });
            }
        };

        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 == 'project_number') {
                return '<a href="javascript:wfl_prj501_grid_update(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
            } else if (name == 'bp_link' && record.get('bp_id') && record.get('record_id')) {
                link_function = '${/parameter/@layout_code}_open_bp_detail_window';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + config_record.get('prompt') + '</a>';
            } else if (name == 'attachment') {
                link_function = '${/parameter/@layout_code}_prj500_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 == 'attach_file_name' || name == 'attach_file_name_print') {
                var content_type = record.get('content_type');
                var content_id = record.get('content_id');
                //电子合同
                // if (content_type == '01') {
                //     var link = '${/request/@context_path}/modules/xxx/pdf_download.lsc?type=SIN&content_id=' + content_id;
                //     var url = '';
                //     url = url + '<a href=' + link + '>' + '下载' + '</a>' + ',';
                //     return url;
                // } else {
                    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_name = temp[0].toUpperCase();
                                var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                                if (file_name.indexOf('.PDF') >= 0) {
                                    url = url + '<a href=javascript:view_pdf(\'' + temp[1] + '\')>' + temp[0] + '</a>' + ',';
                                } else if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                    url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ',';
                                } else {
                                    url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                                }
                            }
                        }
                        return url;
                    }
                //}
            } else if (name == 'received_amount') {
                link_function = '${/parameter/@layout_code}_received_amount_detail';
                if (value) {
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + Leaf.formatMoney(value) + '</a>';
                }
                return '';
            }


        };

        function wfl_prj501_grid_update(record_id, ds_id) {
            var record = $(ds_id).findById(record_id);
            var param = {};
            param['bp_class'] = record.get('bp_class');
            param['project_id'] = record.get('project_id');
            param['function_code'] = 'PRJ502D';
            param['function_usage'] = 'QUERY';
            param['url_title'] = '租赁申请查询';
            hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, 'wfl_readonly_pageLink_projectQueryScreen_update_project', record.ds.id, '${/parameter/@layout_code}');
        }


        window['${/parameter/@layout_code}_open_lease_item_detail_window'] = function (id, name) {
            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
            var param = record.data;
            var contract_lease_item_id = record.get('contract_lease_item_id');
            new Leaf.Window({
                id: 'contract_lease_item_maintain_window',
                url: $('contract_lease_item_query_link').getUrl(),
                params: {
                    contract_lease_item_id: contract_lease_item_id,
                    winid: 'contract_lease_item_maintain_window'
                },
                draggable: true,
                fullScreen: true
            });
        };

        window['${/parameter/@layout_code}_open_bp_detail_window'] = function (id, name) {
            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];

            var param = {};//record.data;
            param['bp_id'] = record.get('bp_id');
            param['cdd_list_id'] = record.get('cdd_list_id');
            param['company_id'] = '${/session/company_id}';
            param['document_id'] = record.get('bp_id');
            param['document_category'] = 'BP';
            param['bp_class'] = record.get('bp_class');
            param['bp_category'] = record.get('bp_category');
            param['bp_type'] = record.get('bp_type');
            if (!'${/parameter/@lease_execution_flag}' || '${/parameter/@lease_execution_flag}' === 'N') {
                param['function_code'] = 'HLS214D';
                param['function_usage'] = 'MODIFY';
                param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}_hls_bp_master_modify_link', record.ds.id, '${/parameter/@layout_code}');
            } else {
                param['function_code'] = 'HLS215D';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'READONLY';
                param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, 'con505_hls_bp_master_query_link', record.ds.id, '${/parameter/@layout_code}');
            }

        };

        function view_pdf(attachment_id) {
            Leaf.request({
                url: '${/request/@context_path}/autocrud/fnd.fnd_atm_attachment/query',
                para: {
                    attachment_id: attachment_id
                },
                success: function (res) {
                    var path = res.result.record.file_path;
                    path = path.substr(path.indexOf('hls_attachment'));
                    var tomcat_source = '${/parameter/@tomcat_source}';
                    var source_path = 'http://' + window.location.host + '/' + tomcat_source + '/' + path + '?type=pdf';
                    var oWin = window.open(source_path);
                },
                scope: this
            });
        }

        window['${/parameter/@layout_code}_prj500_cdd_attachtment_upload'] = function (ds_id, id, name, query_only) {
            var record = $(ds_id).findById(id);
            if (record.get('check_id')) {
                var url;
                if (query_only == 'Y' || '${/parameter/@function_usage}' == 'QUERY') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_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}${/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}', '请先保存!');
            }
        };

        //选择事件(grid,attach,gridbox,table)
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_select'] = function (ds, record, bp_seq) {
            var bp_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_BP', 'con_contract_bp');

            if (bp_ds_id == ds.id && bp_ds_id) {
                if (record.get('bp_category') == 'TENANT') {
                    //实际为不选中
                    Leaf.showMessage('${l:HLS.PROMPT}', '无法删除主承租人！');
                    ds.unSelect(record);
                    ds.Select(record);
                }
                if (record.get('bp_category') == 'AGENT') {
                    //实际为不选中
                    Leaf.showMessage('${l:HLS.PROMPT}', '无法删除经销商！');
                    ds.unSelect(record);
                    ds.Select(record);
                }
            }
        };
        //更新时调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function (ds, record, name, value, old_value, bp_seq) {
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
//            inception_of_lease
//            
            if (con_ds_id == ds.id) {
                if (name == 'inception_of_lease') {
                    var time = new Date();
                    if (value.getTime() > time.getTime()) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '交付日期不能晚于当天！');
                    }

                }
            }
        };

        //加载时调用(grid,table,gridBox)
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function (ds, record, config_records, bp_seq) {

            var bp_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_BP', 'con_contract_bp');

            if (bp_ds_id == ds.id && bp_ds_id) {
                if (record.get('bp_category') == 'TENANT') {
                    record.getField('bp_category_n').setReadOnly(true);
                    record.getField('bp_id_n').setReadOnly(true);
                }
                if (record.get('bp_category') == 'AGENT') {
                    record.getField('bp_category_n').setReadOnly(true);
                    record.getField('bp_id_n').setReadOnly(true);
                }
            }
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();

        };

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

            var ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC', 'con_contract');
            if (ds.id == ds_id) {
                if (!'${/parameter/@lease_execution_flag}' || '${/parameter/@lease_execution_flag}' === 'N') {
                    //add by chenlingfegn 重置执行日期，未执行时
                    // if (!record.get('lease_execution_date')){
                    record.set('lease_execution_date', new Date());
                    // }
                }

                // var third_party_deposit = record.get('third_party_deposit');
                // if (!third_party_deposit || third_party_deposit == 0){
                //     record.getField('con_deposit_by_agent').setReadOnly(true);
                // }

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

        //grid删除 主承租人
        window['${/parameter/@layout_code}_G_BP_USER_BUTTON1_layout_dynamic_tab_click'] = function () {
//            
            var ds_id = '${/parameter/@layout_code}_G_BP_con_contract_bp_ds';
            var records = $(ds_id).getSelected();
            if (records.length == 0) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                return;
            }
            var param_list = [];
            var param = {};
            for (var i = 0; i < records.length; i++) {
                param = records[i].data;
                if (records[i].get('bp_category') == 'TENANT') {
                    Leaf.showMessage('${l:HLS.PROMPT}', '主承租人不允许删除！');
                    return;
                }
                param['_status'] = 'delete';
                param_list.push(param);
            }

            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            //如果是未保存的直接移除
            if (!records[0].get('record_id')) {
                var grid_id = '${/parameter/@layout_code}_G_BP_con_contract_bp_layout_grid_id';
                $(grid_id).clear();
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            } else {
                Leaf.showConfirm('提示', '是否确认删除选中记录？', function () {
                    Leaf.request({
                        url: $('con_contract_bp_delete').getUrl(),
                        para: param_list,
                        success: function (res) {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $(ds_id).query();
                            Leaf.SideBar.show({
                                html: '<div style="background-color:#ccfbd5;position:absolute;padding:3px;border:1px solid #009900">' + '删除成功' + '</div>',
                                duration: 1000
                            });

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

        }


        window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function (ds, record, res, bp_seq) {
           // var contract_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var bp_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_bp');

                ds.query();
             //   $(contract_ds).query();
                $(bp_ds).query();


            //var record = $(contract_ds).getAt(0);
            // Leaf.request({
            //     url: $('${/parameter/@layout_code}_con_contract_score_id').getUrl(),
            //     para: {
            //         contract_id: record.get('contract_id'),
            //         score_template_code: 'DS_AS_NP'
            //     },
            //     success: function (res) {
            //         window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //         var evaluate_level = res.result.evaluate_level;
            //         var evaluate_value = res.result.evaluate_value;
            //         record.set('sys_level', evaluate_level);
            //         record.set('sys_result', evaluate_value);
            //     },
            //     failure: function () {
            //
            //     },
            //     error: function () {
            //         window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //     },
            //     scope: this
            // });
        };

        //付款单打印 add by chenlingfeng 2019-06-03 14:51:49
        window['${/parameter/@layout_code}_user_button9_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var record = $(ds_id).getCurrentRecord();
            var contract_id = record.get('contract_id');
            var content_id;
            Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认打印审查单？', function () {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('${/parameter/@layout_code}_con_checklist_content_create_link').getUrl(),
                    para: {
                        contract_id: contract_id,
                        content_id: content_id
                    },
                    success: function (rsc) {
                        Leaf.request({
                            url: $('${/parameter/@layout_code}_creat_con_contract_content_link_id').getUrl(),
                            para: {
                                content_id: rsc.result.content_id,
                                file_path: '${/parameter/@file_path}'
                            },
                            success: function () {
                                Leaf.request({
                                    url: $('${/parameter/@layout_code}_file_copy_from_template_link_id').getUrl(),
                                    para: {
                                        contract_id: record.get('contract_id'),
                                        content_id: rsc.result.content_id,
                                        file_path: '${/parameter/@file_path}',
                                        batch_flag: 'Y'
                                    },
                                    success: function () {
                                        var doc_code = '审查单';
                                        // var url_l = $('con_atm_batch_download_pdf_link_id').getUrl() + '?content_id=' + rsc.result.content_id + '&doc_code=' + encodeURI(doc_code) + '&type=SIN&fnd_atm_flag=Y';
                                        var url_l = $('${/parameter/@layout_code}_con_batch_pdf_dl_link_id').getUrl() + '?content_id=' + rsc.result.content_id + '&doc_code=' + encodeURI(doc_code) + '&type=SIN&fnd_atm_flag=Y';

                                        window.open(href = url_l, target = "_self");

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

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

                    },
                    scope: this
                });

            });
        };
        //开始锁屏 数据加载完 gird load 中解屏
        Leaf.onReady(function () {
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
        });


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