<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei5743  
    $Date: 2014-10-8 下午3:16:19  
    $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>
        <a:model-query defaultWhereClause="t1.user_id=${/session/@user_id}" model="prj.PRJ500D.sys_user_lv"
                       rootPath="user_name_path"/>
        <a:model-query defaultWhereClause="v.role_id = ${/session/@role_id} and v.role_code in (&apos;HAND&apos;,&apos;0017&apos;)" model="zjwfl.sys_role_flag" rootPath="role_flag_path"/>
        <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:init-procedure>
    <a:view>
        <a:link id="hls_bp_master_billing_link" model="prj.PRJ500N.hls_bp_master_billing" modelaction="query"/>
        <a:link id="bp_tenant_detail_query_link" model="prj.PRJ500D.bp_tenant_old_r_query" modelaction="query"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}get_special_fields_link_id"
                model="cont.CON500.con_contract_get_special_fields" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_uploadFile_id"
                url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_downloadFile_id"
                url="${/request/@context_path}/downloadFile.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_for_deron_link_id"
                url="${/request/@context_path}/modules/hls/HLS500/hls_fin_doc_quotation_for_deron.lsc"/>
        <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="${/parameter/@layout_code}hls_bp_master_query_link"
                url="${/request/@context_path}/modules/hls/HLS215N/hls_bp_master_query.lview"/>

        <a:link id="${/parameter/@layout_code}contract_number_query_link"
                url="${/request/@context_path}/modules/cont/CON505/con_contract_modify.lview"/>
        <a:link id="${/parameter/@layout_code}_tenant_rate_query_link"
                url="${/request/@context_path}/modules/prj/PRJ902/prj_project_score_result.lview"/>
        <a:link id="${/parameter/@layout_code}_hls_fin_calc_get_base_rate_link_id"
                model="hls.HLS500.hls_fin_calc_get_base_rate" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>

        <!-- <script src="${/request/@context_path}/modules/prj/PRJ500N/javascripts/check_org_code.js" type="text/javascript"/> -->
        <!--  <a:link id="prj_project_create_con_id" model="prj.PRJ513N.prj_peoject_create_con" modelaction="update"/> -->
        <a:link id="${/parameter/@layout_code}_prj_project_create_contract_link_id"
                model="prj.PRJ505.prj_project_create_contract" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_prj_project_update_status_link_id"
                model="prj.PRJ505.prj_project_create_contract" modelaction="execute"/>
        <a:link id="prj_approval_link_id" model="prj.PRJ501N.project_approval" modelaction="update"/>
        <a:link id="check_prj_lease_item_link_id" model="prj.PRJ501N.project_approval" modelaction="execute"/>
        <script src="${/request/@context_path}/javascripts/jquery-1.6.4.min.js" type="text/javascript"/>

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

        <a:link id="prj_check_prj_record_link_n" model="hls.HLS500N.check_prj_record" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
        jQuery.noConflict();
        window['${/parameter/@layout_code}_user_button5_layout_dynamic_click'] = function () {
            Leaf.showConfirm('提示', '是否确认生成合同?', function () {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
                var quotation_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_quotation');
                var quo_record = $(quotation_ds_id).getCurrentRecord();

                var cal_hd_price_list = quo_record.get('cal_hd_price_list');
                var price_list = quo_record.get('price_list');
                if (cal_hd_price_list == price_list) {
                    var url = $('${/parameter/@layout_code}_prj_project_create_contract_link_id').getUrl();
                    var record = $(ds_id).getCurrentRecord();
                    if ($(ds_id).validate()) {
                        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                        Leaf.request(
                            {
                                url: url,
                                para: {
                                    project_id: record.get('project_id'),
                                    contract_seq: 1,
                                    bp_contract_seq: 1,
                                    contract_type: 'CARCON',
                                    contract_name: record.get('project_name'),
                                    billing_method: record.get('billing_method'),
                                },
                                success: function (res) {
                                    $('${/parameter/@winid}').close();
                                    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

                            }
                        );
                    }
                } else {
                    Leaf.showMessage('${l:PROMPT}', '报价有变动请重新计算!');

                }
            });
        };


        //add by zhuxianfei
        window['${/parameter/@layout_code}_quote_layout_dynamic_click'] = function () {

            var url;
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
            var quotation_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_quotation');
            var history_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CASHFLOW_NS', 'prj_quotation');

            var record = $(quotation_ds_id).getCurrentRecord();
            var head_record = $(ds_id).getAt(0);
            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 (head_record.dirty == true) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                return;
            }
            if (record.dirty == true) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                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;
                 }*/

                var parent_pk_value = head_record.get('project_id');
                var secondary_lease = head_record.get('secondary_lease');
                var payment_deduction = head_record.get('payment_deduction');
                record.set('function_code', 'PRJ505_QUOTATION');
                record.set('function_usage', 'UPDATE');
                record.set('project_id', parent_pk_value);
                //拆分合同可维护
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                //首次插入
                if (!record.get('calc_session_id')) {
                    record.set('to_doc_table', 'HLS_FIN_CALCULATOR_HD');
                    var calc_recreate_L_formula;
                    calc_recreate_L_formula = 'Y';

                    record.set('_status', 'update');
                    record.set('from_doc_table', 'PRJ_QUOTATION');
                    record.set('from_doc_pk', record.get('quotation_id'));
                    record.set('calculate_flag', 'N');
                    if (!'${/parameter/@document_id}') {
                        record.set('document_id', parent_pk_value);
                    }
                    var price_list = record.get('price_list');
                    var saveData = [];
                    saveData.push(record.data);
                    Leaf.request({
                        url: $('${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_doc_quotation_link_id').getUrl(),
                        para: saveData,
                        success: function (res) {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $(quotation_ds_id).query();
                            $(history_ds_id).query();
                            var quotation_id = record.get('quotation_id') || res.result.record.quotation_id;
                            var win = new Leaf.Window({
                                id: 'hls_fin_calc_quotation_link_winid',
                                params: {
                                    layout_code: '${/parameter/@layout_code}',
                                    document_id: parent_pk_value,
                                    price_list: price_list,
                                    secondary_lease: secondary_lease,
                                    payment_deduction: payment_deduction,
                                    document_category: 'PROJECT',
                                    maintain_type: 'MODIFY',
                                    business_type: head_record.get('business_type'),
                                    calc_session_id: res.result.record.calc_session_id,
                                    quotation_id: quotation_id,
                                    dsId: quotation_ds_id,
                                    winId: 'hls_fin_calc_quotation_link_winid',
                                    global_flag: 'Y',
                                    id_num: 1,
                                    calc_type: '${/parameter/@calc_type}' || 'CLASSIC_CALCULATOR',
                                    recreate_L_formula: calc_recreate_L_formula
                                },
                                url: url,
                                fullScreen: true,
                                draggable: true
                            });

                            win.on('close', function () {
                                $(quotation_ds_id).query();
                                $(history_ds_id).query();

                            });
                        },
                        failure: function () {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        error: function () {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                } else {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    var cal_hd_price_list = record.get('cal_hd_price_list');
                    var price_list = record.get('price_list');
                    if (cal_hd_price_list == price_list) {

                        //直接进入报价页面
                        var win = new Leaf.Window({
                            id: 'hls_fin_calc_quotation_update_link_winid',
                            params: {
                                layout_code: '${/parameter/@layout_code}',
                                document_id: parent_pk_value,
                                price_list: price_list,
                                secondary_lease: secondary_lease,
                                payment_deduction: payment_deduction,
                                document_category: 'PROJECT',
                                maintain_type: 'MODIFY',
                                business_type: head_record.get('business_type'),
                                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: 1,
                                calc_type: '${/parameter/@calc_type}',
                                recreate_L_formula: 'N'
                            },
                            url: url,
                            fullScreen: true,
                            draggable: true
                        });
                        win.on('close', function () {
                            $(quotation_ds_id).query();
                            $(history_ds_id).query();
                        });
                    } else {
                        record.set('to_doc_table', 'HLS_FIN_CALCULATOR_HD');
                        var calc_recreate_L_formula;
                        calc_recreate_L_formula = 'Y';

                        record.set('_status', 'update');
                        record.set('from_doc_table', 'PRJ_QUOTATION');
                        record.set('from_doc_pk', record.get('quotation_id'));
                        record.set('calculate_flag', 'N');
                        if (!'${/parameter/@document_id}') {
                            record.set('document_id', parent_pk_value);
                        }
                        var price_list = record.get('price_list');
                        var saveData = [];
                        saveData.push(record.data);
                        Leaf.request({
                            url: $('${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_doc_quotation_link_id').getUrl(),
                            para: saveData,
                            success: function (res) {

                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                $(quotation_ds_id).query();
                                $(history_ds_id).query();
                                var quotation_id = record.get('quotation_id') || res.result.record.quotation_id;
                                var win = new Leaf.Window({
                                    id: 'hls_fin_calc_quotation_link_winid',
                                    params: {
                                        layout_code: '${/parameter/@layout_code}',
                                        document_id: parent_pk_value,
                                        price_list: price_list,
                                        secondary_lease: secondary_lease,
                                        payment_deduction: payment_deduction,
                                        document_category: 'PROJECT',
                                        maintain_type: 'MODIFY',
                                        business_type: head_record.get('business_type'),
                                        calc_session_id: res.result.record.calc_session_id,
                                        quotation_id: quotation_id,
                                        dsId: quotation_ds_id,
                                        winId: 'hls_fin_calc_quotation_link_winid',
                                        global_flag: 'Y',
                                        id_num: 1,
                                        calc_type: '${/parameter/@calc_type}' || 'CLASSIC_CALCULATOR',
                                        recreate_L_formula: calc_recreate_L_formula
                                    },
                                    url: url,
                                    fullScreen: true,
                                    draggable: true
                                });
                                win.on('close', function () {
                                    $(quotation_ds_id).query();
                                    $(history_ds_id).query();

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


        function prj501n_upload_file(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' || '${/parameter/@function_usage}' == 'QUERY') {
                    url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                } else {
                    url = $('${/parameter/@layout_code}${/parameter/@pre_layout}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: 'prj500_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });

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

        function prj501n_upload_file_new(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' || '${/parameter/@function_usage}' == 'QUERY') {
                    if('${/model/role_flag_path/record/@sys_role_flag}' == 'Y') {
                        url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    }else{
                        url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    }
                } else {
                    url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                }*/

                if('${/model/role_flag_path/record/@sys_role_flag}' == 'Y') {
                    url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                }else{
                    url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_downloadFile_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: 'prj500_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });

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

        function prj501n_bp_code_renderer(id, name, query_only) {
            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
            var param = {};
            param['bp_id'] = record.get('bp_id');
            param['bp_class'] = record.get('bp_class');
            if (record.get('bp_category') == 'AGENT') {
                param['function_code'] = 'HLS303_Q';
                param['function_usage'] = 'QUERY';

            } else {
                param['function_code'] = 'HLS215D';
                param['function_usage'] = 'QUERY';
            }
            param['winid'] = '${/parameter/@layout_code}_bp_win_id';
            param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
            hls_doc_get_layout_code('${/parameter/@layout_code}_get_layout_code_link_id', param, '${/parameter/@layout_code}hls_bp_master_query_link', record.ds.id, '${/parameter/@layout_code}');
        }

        function prj501n_project_number_renderer(id, name, query_only) {
            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
            var param = {};
            param['bp_id'] = record.get('project_id');
            param['bp_class'] = record.get('bp_class');
            param['function_code'] = 'PRJ501D';
            param['function_usage'] = 'QUERY';
            param['maintain_type'] = 'READONLY';
            param['winid'] = '${/parameter/@layout_code}_project_number_win_id';
            param['prj_bp_id'] = record.get('prj_bp_id');

            hls_doc_get_layout_code('${/parameter/@layout_code}_get_layout_code_link_id', param, '${/parameter/@layout_code}project_number_query_link', record.ds.id, '${/parameter/@layout_code}');
        }

        function prj501n_contract_number_renderer(id, name, query_only) {
            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
            var param = {};
            param['contract_id'] = record.get('contract_id');
            param['function_code'] = 'CON301';
            param['function_usage'] = 'QUERY';
            param['winid'] = '${/parameter/@layout_code}_project_number_win_id';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('${/parameter/@layout_code}_get_layout_code_link_id', param, '${/parameter/@layout_code}contract_number_query_link', record.ds.id, '${/parameter/@layout_code}');

        }

        //超链接渲染
        window['${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record) {
            var link_function = '';
            window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
            if (name == 'attachment') {
                link_function = 'prj501n_upload_file';
                if(record.get('cdd_item') == 'ADD_ATTACH'){
                    link_function = 'prj501n_upload_file_new';
                }
                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])) {
                             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;

                  }*/
                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('.BMP') >= 0 || file_name.indexOf('.JPG') >= 0 || file_name.indexOf('.JPEG') >= 0 || file_name.indexOf('.PNG') >= 0 || file_name.indexOf('.GIF') >= 0) {
                                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 == 'bp_link' && !record.isNew) {
                link_function = 'prj501n_bp_code_renderer';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';

            } else if (name == 'project_number') {
                link_function = 'prj501n_project_number_renderer';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + value + '</a>';

            } else if (name == 'contract_number') {
                link_function = 'prj501n_contract_number_renderer';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + value + '</a>';
            }
        };

        //保存submitsuccess调用
        window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function (ds, record, res) {
            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
            var prj_quotation_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_quotation');
            var bp_ds_ids = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC_INFO_1', 'prj_project');
            var prj_project_lease_item_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_LEASE_HEAD_CAR', 'prj_project_lease_item');
            var bp_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_BP', 'prj_project_bp');
            var tenant_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'T_HISTORY_INGO', 'hls_bp_master');
            var cdd_item_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_cdd_item_doc_ref');
            var virtual_ds_id = '${/parameter/@layout_code}_virtual_ds';
            var score_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');
            if (ds_id == ds.id || virtual_ds_id == ds.id) {
                $(cdd_item_ds_id).query();
                $(bp_ds_id).query();
                $(tenant_ds_id).query();
                $(prj_project_lease_item_ds_id).query();
                $(prj_quotation_ds_id).query();
                $(score_ds_id).query();
            }

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

        //选择事件(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_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_BP', 'prj_project_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);
                    setTimeout(function () {
                        ds.unSelect(record);
                    }, 1);
                }
                if (record.get('bp_category') == 'AGENT') {
                    //实际为不选中
                    Leaf.showMessage('${l:HLS.PROMPT}', '无法删除经销商!');
                    // ds.unSelect(record);
                    // ds.select(record);
                    setTimeout(function () {
                        ds.unSelect(record);
                    }, 1);
                }
            }
        };

        function jsGetAge(strBirthday) {
            var returnAge;
            var strBirthdayArr = strBirthday.split("-");
            var birthYear = strBirthdayArr[0];
            var birthMonth = strBirthdayArr[1];
            var birthDay = strBirthdayArr[2];

            var d = new Date();
            var nowYear = d.getFullYear();
            var nowMonth = d.getMonth() + 1;
            var nowDay = d.getDate();

            if (nowYear == birthYear) {
                returnAge = 0;//同年 则为0岁  
            } else {
                var ageDiff = nowYear - birthYear; //年之差  
                if (ageDiff > 0) {
                    if (nowMonth == birthMonth) {
                        var dayDiff = nowDay - birthDay;//日之差  
                        if (dayDiff < 0) {
                            returnAge = ageDiff - 1;
                        } else {
                            returnAge = ageDiff;
                        }
                    } else {
                        var monthDiff = nowMonth - birthMonth;//月之差  
                        if (monthDiff < 0) {
                            returnAge = ageDiff - 1;
                        } else {
                            returnAge = ageDiff;
                        }
                    }
                } else {
                    returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天  
                }
            }
            return returnAge;//返回周岁年龄  
        }

        //更新时调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function (ds, record, name, value, old_value, bp_seq) {
            var prj_project_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
            var prj_project_history_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'T_HISTORY_INGO', 'hls_bp_master');
            var score_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');

            //选择承租人带出开票信息
            if (prj_project_ds_id == ds.id && prj_project_ds_id) {
                if (name == "payment_deduction" && value == "DOWN_PAYMENT_DEDUCTION") {
                    //业务类型回租时,默认只读“首付款抵扣”选项
                    if ($(prj_project_ds_id).getAt(0).get('business_type') == 'LEASE') {
                        Leaf.showInfoMessage("提示", "直租业务不能选择首付款抵扣");
                        setTimeout(function () {
                            $(prj_project_ds_id).getAt(0).set('payment_deduction', null);
                            $(prj_project_ds_id).getAt(0).set('payment_deduction_n', null);
                        }, 10);

                    }
                }
                if (name == "bp_id_tenant_n" && value) {
                    var bp_id_tenant = record.get('bp_id_tenant');
                    Leaf.Masker.mask(Ext.getBody());
                    Leaf.request({
                        url: $('hls_bp_master_billing_link').getUrl(),
                        para: {
                            bp_id: bp_id_tenant
                        },
                        success: function (res) {
                            var billing_into = res.result.record;
                            var prj_project_bp_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project_bp');

                            $(prj_project_bp_ds_id).getAt(0).set('taxpayer_type_n', billing_into.taxpayer_type_n);
                            $(prj_project_bp_ds_id).getAt(0).set('taxpayer_type', billing_into.taxpayer_type);
                            $(prj_project_bp_ds_id).getAt(0).set('invoice_title', billing_into.invoice_title);
                            $(prj_project_bp_ds_id).getAt(0).set('invoice_bp_address', billing_into.invoice_bp_address);
                            $(prj_project_bp_ds_id).getAt(0).set('invoice_bp_phone_num', billing_into.invoice_bp_phone_num);
                            $(prj_project_bp_ds_id).getAt(0).set('invoice_bp_bank', billing_into.invoice_bp_bank);
                            $(prj_project_bp_ds_id).getAt(0).set('invoice_bp_bank_account', billing_into.invoice_bp_bank_account);
                            $(prj_project_bp_ds_id).getAt(0).set('tax_registry_num', billing_into.tax_registry_num);
                            $(prj_project_bp_ds_id).getAt(0).set('ref_v07', billing_into.ref_v07);

                            //record.set();
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        failure: function () {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function () {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
                    //根据承租人查找该承租人的历史合同信息
                    $(prj_project_history_ds_id).setQueryUrl('${/request/@context_path}/autocrud/prj.PRJ501N.prj_project_history_display/query');
                    $(prj_project_history_ds_id).setQueryParameter("bp_id", bp_id_tenant);
                    $(prj_project_history_ds_id).query();

                    Leaf.Masker.mask(Ext.getBody());
                    $(score_ds_id).getCurrentRecord().set('score_name', value);
                    Leaf.request({
                        url: $('bp_tenant_detail_query_link').getUrl(),
                        para: {
                            bp_id: bp_id_tenant
                        },
                        success: function (res) {
                            var obj = res.result.record;
                            if (obj) {
                                var bp_tenant_detail_r = $(score_ds_id).getCurrentRecord();
                                if (bp_tenant_detail_r) {
                                    for (var key in bp_tenant_detail_r.data) {
                                        if (key != 'bp_detail_id' && key != 'score_name' && key != 'bp_age') {
                                            var vl = obj[key];
                                            if (key == 'bp_birth' && obj[key]) {
                                                vl = new Date(obj[key].toString());
                                            }
                                            if (vl != "null" && vl != "undefined") {
                                                bp_tenant_detail_r.set(key, vl);
                                            }
                                        }
                                    }
                                }
                            }
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        failure: function () {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function () {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
                }
                if (name == 'legal_person' && value) {
                    $(score_ds_id).getCurrentRecord().set('score_name', value);
                }
                if (name == 'pay_method') {
                    if (record.get('pay_method') == 'WIRE_TRANSFER') {
                        record.set('bank_account_id', null);
                        record.set('bank_account_id_n', null);
                        record.set('bank_branch_num', '');
                        record.set('bank_account_name', '');
                        record.getField('bank_account_id').setReadOnly(true);
                        record.getField('bank_account_id_n').setReadOnly(true);
                        record.getField('bank_account_id').setRequired(false);
                        record.getField('bank_account_id_n').setRequired(false);
                    } else {
                        record.getField('bank_account_id').setReadOnly(false);
                        record.getField('bank_account_id_n').setReadOnly(false);
                        record.getField('bank_account_id').setRequired(false);
                        record.getField('bank_account_id_n').setRequired(false);
                    }

                }
                if (name == 'payment_deduction') {
                    var quoation_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_QUOTATION_N', 'prj_quotation');
                    var quoation_record = $(quoation_ds_id).getCurrentRecord();
                    var down_payment = quoation_record.get('down_payment') || 0;
                    var calc_session_id = quoation_record.get('calc_session_id');
                    var other_payment2;
                    if (value && calc_session_id && value == 'NO_DEDUCTION') {
                        other_payment2 = 0;
                    } else if (value && calc_session_id && value != 'NO_DEDUCTION') {
                        other_payment2 = down_payment;
                    }
                    window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    Leaf.request({
                        url: $('${/parameter/@layout_code}_prj_project_update_status_link_id').getUrl(),
                        para: {
                            other_payment2: other_payment2,
                            calc_session_id: calc_session_id
                        },
                        success: function (arg) {
                            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

                    });
                }
                if (name == 'bp_id_tenant') {
                    if (!value) {
                        var bp_tenant_detail_r = $(score_ds_id).getCurrentRecord();
                        if (bp_tenant_detail_r) {
                            for (var key in bp_tenant_detail_r.data) {
                                bp_tenant_detail_r.set(key, '');
                            }
                        }
                    }
                    record.getField('bank_account_id').setLovPara('bp_id_tenant', record.get('bp_id_tenant'));
                }
                //add by niminmin
                //当“二次租赁”字段选择‘是’时,“回购合同编号”字段为必填。当选择‘否’时,“回购合同编号”字段为只读。
                if (name == 'secondary_lease') {
                    if (value == 'YES') {
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID_prompt').style.display = 'block';
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID').style.display = 'block';
                        record.getField('repur_contract_id').setRequired(true);
                        record.getField('repur_contract_id_n').setRequired(true);
                        record.getField('repur_contract_id').setReadOnly(false);
                        record.getField('repur_contract_id_n').setReadOnly(false);
                    } else if (value == 'NO') {
                        record.getField('repur_contract_id').setRequired(false);
                        record.getField('repur_contract_id_n').setRequired(false);
                        record.getField('repur_contract_id').setReadOnly(true);
                        record.getField('repur_contract_id_n').setReadOnly(true);
                        record.set('repur_contract_id', null);
                        record.set('repur_contract_id_n', null);
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID_prompt').style.display = 'none';
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID').style.display = 'none';
                    }

                }
            }

            if (score_ds_id == ds.id) {
                if (name == 'bp_birth' && value) {
                    if (jsGetAge(value.format('yyyy-mm-dd').toString()) == -1) {
                        Leaf.showInfoMessage("提示", "出生日期不能大于当前日期");
                        setTimeout(function () {
                            record.set('bp_birth', old_value);
                        }, 0);
                    } else {
                        record.set('bp_age', jsGetAge(value.format('yyyy-mm-dd').toString()));
                    }
                }
            }
            var device_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_SCORE_DEVICE', 'bp_tenant_rate_item');
            if (device_ds_id == ds.id) {
                if (name == 'quantity') {
                    if (value <= 0) {
                        Leaf.showInfoMessage("提示", "数量必须大于0");
                        setTimeout(function () {
                            record.set('quantity', old_value);
                        }, 0);
                    }
                }
            }
        };


        //加载时调用(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', 'prj_project_bp');
            /*  var bp_ds_ids = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_HISTORY_INFO_1', 'prj_project_bp');
              $(bp_ds_ids).setQueryParameter('bp_id','${/parameter/@bp_id_tenant}');
              $(bp_ds_ids).query();*/
            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);
                }
            }

        };

        function arrToObject(arr) {
            var strJs = '({';
            for (var i = 0; i < arr.length; i += 1) {
                var as = arr[i].split("=");
                strJs = strJs + as[0] + ':' + '"' + as[1] + '"' + ',';
            }
            strJs = strJs.substr(0, strJs.length - 1) + '})';
            return eval(strJs);
        }
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function (ds, record, config_records, bp_seq) {
            debugger;
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
            if (ds_id == ds.id && ds_id) {
                if (record.get('pay_method') == 'WIRE_TRANSFER') {
                    record.getField('bank_account_id').setReadOnly(true);
                    record.getField('bank_account_id_n').setReadOnly(true);
                    record.getField('bank_account_id').setRequired(false);
                    record.getField('bank_account_id_n').setRequired(false);
                }
                if ('${/parameter/@function_usage}' != 'QUERY') {
                    if (record.get('secondary_lease') == 'YES') {
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID_prompt').style.display = 'block';
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID').style.display = 'block';
                        record.getField('repur_contract_id').setRequired(true);
                        record.getField('repur_contract_id_n').setRequired(true);
                        record.getField('repur_contract_id').setReadOnly(false);
                        record.getField('repur_contract_id_n').setReadOnly(false);
                    } else if (record.get('secondary_lease') == 'NO') {
                        record.getField('repur_contract_id').setRequired(false);
                        record.getField('repur_contract_id_n').setRequired(false);
                        record.getField('repur_contract_id').setReadOnly(true);
                        record.getField('repur_contract_id_n').setReadOnly(true);
                        record.set('repur_contract_id', null);
                        record.set('repur_contract_id_n', null);
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID_prompt').style.display = 'none';
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID').style.display = 'none';
                    }
                } else {
                    if (record.get('secondary_lease') == 'YES') {
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID_prompt').style.display = 'block';
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID').style.display = 'block';
                    } else if (record.get('secondary_lease') == 'NO') {
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID_prompt').style.display = 'none';
                        document.getElementById('${/parameter/@layout_code}_F_BASIC_INFO_1_PRJ_PROJECT_REPUR_CONTRACT_ID').style.display = 'none';
                    }
                }
                //业务类型回租时,默认只读“首付款抵扣”选项
                if (record.get('business_type') == 'LEASEBACK') {
                    record.set('payment_deduction', 'DOWN_PAYMENT_DEDUCTION');
                    record.set('payment_deduction_n', "首付款抵扣");
                    record.getField('payment_deduction').setReadOnly(true);
                    record.getField('payment_deduction_n').setReadOnly(true);
                    record.set('pay_method', 'WIRE_TRANSFER');
                    record.set('pay_method_n', "电汇");
                    record.getField('pay_method').setReadOnly(true);
                    record.getField('pay_method_n').setReadOnly(true);
                    record.getField('bank_account_id').setReadOnly(true);
                    record.getField('bank_account_id_n').setReadOnly(true);
                    record.getField('bank_account_id').setRequired(false);
                    record.getField('bank_account_id_n').setRequired(false);

                }


            }
            var score_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');
            if (score_ds_id == ds.id) {
                if (!record.get('score_name')) {
                    if ($(ds_id).getCurrentRecord()) {
                        var score_name = $(ds_id).getCurrentRecord().get('legal_person') || $(ds_id).getCurrentRecord().get('bp_id_tenant_n');
                        record.set('score_name', score_name);
                    }
                }
            }
        };

        //pdf预览  add by zhuxianfei
        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;
                    var oWin = window.open(source_path);
                },
                scope: this
            });
        }


        Leaf.onReady(function () {
            var bp_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'T_HISTORY_INGO', 'hls_bp_master');
            var url = '${/request/@context_path}/autocrud/prj.PRJ501N.prj_project_history_display/query?project_id=${/parameter/@project_id}&bp_id=${/parameter/@bp_id}';
            $(bp_ds_id).setQueryUrl(url);
            $(bp_ds_id).query();
            var quotation_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_quotation');
            $(quotation_ds_id).query();
            // var billing_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_INVOICE_INFO', 'prj_project_bp');
            var billing_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project_bp');
            var billing_url = '${/request/@context_path}/autocrud/prj.PRJ501N.prj_project_bp/query?project_id=${/parameter/@project_id}';
            $(billing_ds_id).setQueryUrl(billing_url);
            $(billing_ds_id).query();


        });
        //序号自增  add by lijingjing
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_add'] = function (ds, record, config_records, bp_seq) {
            //租赁物序号
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project_lease_item');
            if (ds_id == ds.id && ds_id) {
                //设置序号
                var measure_records = ds.getAll(),
                    seq_num = 0;
                if (measure_records.length) {
                    for (var j = 0; j < measure_records.length; j++) {
                        var measure_record = measure_records[j],
                            rk = measure_record.get('lease_item_seq');
                        if (seq_num <= rk) {
                            seq_num = rk;
                        }
                    }
                }
                var rk_value = seq_num + 1;
                record.set('lease_item_seq', rk_value);

            }
            var device_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_SCORE_DEVICE', 'bp_tenant_rate_item');
            var traffic_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_SCORE_TRAFFIC', 'bp_tenant_rate_item');
            if ((device_ds_id == ds.id && device_ds_id) || (traffic_ds_id == ds.id && traffic_ds_id)) {
                //设置序号
                var rs = ds.getAll(),
                    seq_num = 0;
                if (rs.length) {
                    for (var j = 0; j < rs.length; j++) {
                        var r = rs[j],
                            rk = r.get('seq_num');
                        if (seq_num <= rk) {
                            seq_num = rk;
                        }
                    }
                }
                var rk_value = seq_num + 1;
                record.set('seq_num', rk_value);

            }

        };
        //indexchange事件(grid,attach,gridbox,table)
        // window['${/parameter/@layout_code}_on_layout_dynamic_grid_indexchange'] = function(ds, record, bp_seq) {
        //     if(!record.get('pattern')){
        //
        //         var nodes=document.querySelectorAll('td[dataindex="machine_number"]');
        //         // var nodes=document.getElementsByClassName('cell-editor-div');
        //         for (var i=1;i<nodes.length;i++){
        //             nodes[i].children[0].style.backgroundColor= "#FAFACD";
        //         }
        //         //  $('.cell-editor-div').parent().css("background-color","yellow");
        //     }
        // };
        //客户评分
        window['${/parameter/@layout_code}_user_button9_layout_dynamic_click'] = function () {

            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');

            var record = $(ds_id).getCurrentRecord();
            if (record) {
                var param = record.data;
                if (record.get('project_id')) {
                    param['project_id'] = record.get('project_id');
                    param['winid'] = 'hl_tenant_score_rate_win_id';
                    param['url_title'] = '客户评分明细';
                    var score_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');
                    var r = $(score_ds_id).getCurrentRecord();
                    if (r.dirty && '${/parameter/@function_usage}' == 'MODIFY') {
                        Leaf.showInfoMessage('提示', '评分数据发生修改,请先保存再进行评分');
                        return;
                    }
                    if ($(ds_id).validate()) {
                        var win = new Leaf.Window({
                            id: param['winid'],
                            params: param,
                            url: $('${/parameter/@layout_code}_tenant_rate_query_link').getUrl(),
                            title: param['url_title'],
                            fullScreen: true,
                            draggable: true
                        });
                        win.on('close', function () {
                            $(ds_id).query();
                        });
                    }
                } else {
                    Leaf.showMessage('${l:PROMPT}', '请先保存');

                }
            }

        };
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
            var lease_item_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project_lease_item');
            var quotation_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_quotation');
            var bp_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project_bp');
            var record = $(quotation_ds_id).getCurrentRecord();
            var current_record = $(ds_id).getCurrentRecord();
            var lease_item_record = $(lease_item_ds_id).getCurrentRecord();
            var bp_record = $(bp_ds_id).getCurrentRecord();
            var project_id = current_record.get('project_id');
            var score_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');
            var bp_tenant_detail_r = $(score_ds_id).getCurrentRecord();
            if (bp_tenant_detail_r) {
                for (var key in bp_tenant_detail_r.data) {
                    if (key != 'bp_detail_id' && key != 'score_name' && key != 'bp_age' && key != 'project_id' && key != 'third_party_credibility' && key != 'third_party_credibility_n') {
                        //if (!bp_tenant_detail_r.get(key)) {
                        if (typeof bp_tenant_detail_r.get(key)== "null"||typeof bp_tenant_detail_r.get(key)== "undefined"|| bp_tenant_detail_r.get(key)=== "") {
                            Leaf.showInfoMessage("提示", "承租人评分信息区域的所有字段,除\"第三方信用度\"外,其他都为必输字段,请填写!");
                            return;
                        }
                    }
                }
            }
            if (current_record.dirty == true) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                return;
            }
            if (record.dirty == true) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                return;
            }
            if (lease_item_record.dirty == true) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                return;
            }
            if (bp_record.dirty == true) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                return;
            }
            if (current_record.get('business_type') == 'LEASE') {
                Leaf.request({
                    url: $('prj_check_prj_record_link_n').getUrl(),
                    para: {
                        'project_id': project_id
                    },
                    success: function (res) {
                        var secondary_lease = res.result.secondary_lease;
                        var payment_deduction = res.result.payment_deduction;
                        var price_list = res.result.price_list;
                        var down_payment_rate_new = res.result.down_payment_rate_new;
                        var H16 = record.get('down_payment');
                        var H97 = record.get('third_party_deposit');
                        var H99 = record.get('other_fee');
                        var H102 = record.get('other_fee2');

                        var show = down_payment_rate_new * 100;
                        if ((price_list == 'HL_PRICR_E' || price_list == 'HL_PRICR_TEST' || price_list == 'HL_PRICR_NTEST' || price_list == 'HL_PRICR_EN') && secondary_lease == 'NO') {
                            if ((div((H16 + H97), (H99 + H102 - H16)).toFixed(2) * 1) < down_payment_rate_new) {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                Leaf.showMessage('${l:PROMPT}', '首付款比例+首付款保证金比例之和不能低于' + down_payment_rate_new * 100 + '%');
                                return;
                            }
                        }
                        if ($(ds_id).validate()) {
                            Leaf.showConfirm('${HLS.PROMPT}', '确认要提交工作流吗?', function () {
                                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                                Leaf.request({
                                    url: $('prj_approval_link_id').getUrl(),
                                    para: {
                                        project_id: project_id
                                    },
                                    scope: this,
                                    success: function () {
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                        $('${/parameter/@winid}').close();
                                    },
                                    failure: function () {
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    },
                                    error: function () {
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    }
                                });
                            });

                        }

                    },
                    failure: function () {
                        unlock_calc_current_window('${l:HLS.SAVING}');

                    },
                    error: function () {
                        unlock_calc_current_window('${l:HLS.SAVING}');

                    },
                    scope: this
                });
            } else {
                if ($(ds_id).validate()) {
                    Leaf.showConfirm('${HLS.PROMPT}', '确认要提交工作流吗?', function () {
                        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                        Leaf.request({
                            url: $('prj_approval_link_id').getUrl(),
                            para: {
                                project_id: project_id
                            },
                            scope: this,
                            success: function () {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                $('${/parameter/@winid}').close();
                            },
                            failure: function () {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            error: function () {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            }
                        });
                    });

                }

            }


        };

        var bp_rate_flag;
        /*保存前调用,生成项目编号*/
        window['${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function (ds, record) {
            var prj_project_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
            var score_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');
            var bp_tenant_detail_r = $(score_ds_id).getCurrentRecord();

            if (bp_tenant_detail_r && ds.id == prj_project_ds_id) {
                for (var key in bp_tenant_detail_r.data) {
                    if (key != 'bp_detail_id' && key != 'score_name' && key != 'bp_age' && key != 'project_id' && key != 'third_party_credibility' && key != 'third_party_credibility_n') {
                        //if (!bp_tenant_detail_r.get(key)) {
                        if (typeof bp_tenant_detail_r.get(key)== "null"||typeof bp_tenant_detail_r.get(key)== "undefined"|| bp_tenant_detail_r.get(key)=== "") {
                            Leaf.showInfoMessage("提示", "承租人评分信息区域的所有字段,除\"第三方信用度\"外,其他都为必输字段,请填写!");
                            bp_rate_flag = false;
                            break;
                        } else {
                            bp_rate_flag = true;
                        }
                    }
                }
            }
            if (!bp_rate_flag) {
                return false;
            }

            return true;
        };


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