<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true"
          trace="true">
	 <a:init-procedure>
        <a:model-query defaultWhereClause="t1.change_req_id = ${/parameter/@change_req_id}"
                       model="cus_deposit.CUS_DEPOSIT106.get_contract_wfl_status" rootPath="default_value_path"/>
         <a:model-query defaultWhereClause="t1.contract_id=${/parameter/@contract_id}" fetchAll="true" model="cont.CON_ET001.create_change_req" rootPath="get_contract_division"/>
    </a:init-procedure>
    <a:view>
        <!--        <a:link id="con731_calc_ccr_fee_link" model="cont.CON731.calc_ccr_fee" modelaction="execute"/>-->
        <a:link id="calc_leasse_amount_link" model="cont.CON731.calc_leasse_date" modelaction="execute"/>
        <a:link id="calc_pay_amount_link" model="cont.CON731.calc_leasse_pay" modelaction="execute"/>
        <a:link id="calc_tenant_amount_link" model="cont.CON733.calc_tenant_change_req" modelaction="execute"/>
        <a:link id="con731_quote_link"
                url="${/request/@context_path}/modules/cont/CON731/hls_fin_calculator_update_n.lview"/>
        <a:link id="con733_quote_calc_change_req_link" model="cont.CON733.calc_change_req" modelaction="execute"/>
        <a:link id="con731_submit_link" model="cont.CON731.submit_change_req" modelaction="execute"/>
        <a:link id="con731_cancel_link" model="cont.CON731.cancel_change_req" modelaction="execute"/>
        <a:link id="con_guarantor_comparison_link" model="cont.CON731.con_guarantor_comparison" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_uploadFile_id"
                url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_downloadFile_id"
                url="${/request/@context_path}/downloadFile.lview"/>
        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>
        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_doc_quotation_link_id"
                url="${/request/@context_path}/modules/hls/HLS500/hls_fin_doc_quotation.lsc"/>
        <a:link id="set_sum_unreceived_principal_cancel_link" model="cont.CON731.con_change_calc" 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="con731_hls_bp_master_query_link" url="${/request/@context_path}/modules/cont/CON505/hls_bp_master_query.lview"/>
          <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}_con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
		<a:link id="con_buyback_info_print_link_id" url="${/request/@context_path}/modules/csh/CSH501/csh_con_req_history_pdf_print.lsc"/>
		 <a:link id="con_check_deduction_limit_link" model="check_after_save_bm.con_check_deduction_limit_after_save"
                modelaction="update"/>
  <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}get_bp_tenant_rate_detail_link" model="cont.CON731.get_bp_tenant_rate_detail" modelaction="query"></a:link>
        <script type="text/javascript"><![CDATA[
        Ext.ux.Lightbox.register('a[ref=img]', true);
        Leaf.onReady(function () {
            var ds_con_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_QUOTATION_01', 'con_contract');
            if ($(ds_con_id)) {
                $(ds_con_id).setQueryParameter('contract_id', '${/parameter/@contract_id}');
                $(ds_con_id).query();
            }
            //让历史信息查询
            var history_con_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?bp_id=${/parameter/@bp_id}';
            $(history_con_id).setQueryUrl(url);
            $(history_con_id).query();

            if('${/model/get_contract_division/record/@division}' !='70' && '${/model/get_contract_division/record/@division}' != ''){
            if(document.getElementById("CON_ET_MODIFY_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_DEPOSIT_BALANCE")){
            document.getElementById("CON_ET_MODIFY_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_DEPOSIT_BALANCE_prompt").style.display = "none";
            document.getElementById("CON_ET_MODIFY_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_DEPOSIT_BALANCE").style.display = "none";
            }
            if(document.getElementById("CON_ET_MODIFY_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_DEPOSIT_DEDUCTION")){
            document.getElementById("CON_ET_MODIFY_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_DEPOSIT_DEDUCTION_prompt").style.display = "none";
            document.getElementById("CON_ET_MODIFY_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_DEPOSIT_DEDUCTION").style.display = "none";
            }
            }
        });

        function open_contract_win(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['function_code'] = 'CON301';
            param['function_usage'] = 'QUERY';
            param['download'] = 'Y';
            param['maintain_type'] = 'UPDATE';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_modify_link', ds_id);
        }

        window['${/parameter/@layout_code}_quote_layout_dynamic_click'] = function () {
            //  $('${/parameter/@layout_code}_quote').disable(); //按钮不可用
            var req_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_QUOTATION_01', 'con_contract');
            var req_record = $(req_ds_id).getAt(0);
            var calc_session_id = req_record.get('calc_session_id');
            var quo_win;
            var calc_type = '${/parameter/@calc_type}';
            var document_category = req_record.get('document_category');
            // 變更起始期數
            var ccr_start_times = req_record.get('ccr_start_times');
            //變更剩餘期數
            var ccr_outstanding_times = req_record.get('ccr_outstanding_times');
            var change_document_type = req_record.get('change_document_type');
            if ($(req_ds_id).validate($('${/parameter/@layout_code}_quote').enable())) {
                if (req_record.dirty) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                    return;
                }
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('con733_quote_calc_change_req_link').getUrl(),
                    para: {
                        change_req_id: '${/parameter/@change_req_id}',
                        ccr_start_times: ccr_start_times,
                        ccr_outstanding_times: ccr_outstanding_times,
                        calc_session_id: calc_session_id
                    },
                    success: function (res) {
                        //     $('${/parameter/@layout_code}_quote').enable();
                        req_record.set('calc_session_id', res.result.calc_session_id);
                        req_record.dirty = false;
                        quo_win = new Leaf.Window({
                            id: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                            params: {
                                price_list: req_record.get('price_list'),
                                document_id: '${/parameter/@change_req_id}',
                                document_category: document_category,
                                maintain_type: 'UPDATE',
                                calc_session_id: res.result.calc_session_id,
                                quotation_id: null,
                                dsId: req_ds_id,
                                winId: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                                global_flag: 'Y',
                                id_num: 0,
                                calc_type: '${/parameter/@calc_type}',
                                recreate_L_formula: 'N'
                            },
                            url: $('con731_quote_link').getUrl(),
                            fullScreen: true,
                            draggable: true
                        });
                        quo_win.addListener('close', function () {
                            $(req_ds_id).query();
                            var cf_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_QUOTATION_04', 'con_contract_cashflow');
                            $(cf_ds_id).setQueryParameter('contract_id', '${/parameter/@contract_id}');
                            $(cf_ds_id).query();
                        });
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function () {
                        //    $('${/parameter/@layout_code}_quote').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function () {
                        //   $('${/parameter/@layout_code}_quote').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            }
        };


        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function (ds, record, name, value, old_value, bp_seq) {
            var ds_con_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_QUOTATION_01', 'con_contract');
            if (ds.id == ds_con_id) {
                // 承租人变更
                if ('${/parameter/@layout_code}' == 'CON_TENANT_CHANGE_MODIFY') {
                    if(name=='bp_id_tenant'){
                        //让历史信息查询
                        var history_con_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?bp_id='+value;
                        $(history_con_id).setQueryUrl(url);
                        $(history_con_id).query();
                        var tennat_score_ds_id=get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');
                        var tenant_score_record=$(tennat_score_ds_id).getAt(0);
                            if(tenant_score_record){
                                Leaf.request({
                                    url: $('${/parameter/@layout_code}get_bp_tenant_rate_detail_link').getUrl(),
                                    para: {
                                        bp_id: value
                                    },
                                    success: function (data) {
                                        if (data.result.record && !data.result.record.length) {
                                            //评分信息
                                            for (var name in tenant_score_record.data) {
                                                if (name != 'bp_detail_id' && name != 'project_id'&& name != 'contract_id') {
                                                    if(data.result.record[name]){
                                                        tenant_score_record.set(name, data.result.record[name]);
                                                    }else{
                                                        tenant_score_record.set(name, '');
                                                    }

                                                }
                                            }
                                        }else{
                                            //未找到则置空
                                            for (var name in tenant_score_record.data) {
                                                if (name != 'bp_detail_id' && name != 'project_id'&& name != 'contract_id') {
                                                        tenant_score_record.set(name, '');
                                                }
                                            }
                                        }

                                    },
                                    failure: function () {
                                    },
                                    error: function () {
                                    },
                                    scope: this
                                });
                            }



                    }
                    // 承租人变更日計算未收金額相關信息
                    if (name == 'ccr_lease_date' && value) {
                        Leaf.request({
                            url: $('calc_tenant_amount_link').getUrl(),
                            para: {
                                change_req_id: ${/parameter/@change_req_id},
                                ccr_lease_date: record.get('ccr_lease_date')
                            },
                            success: function (res) {
                                record.set('ccr_lease_rental', res.result.ccr_lease_rental);
                                record.set('ccr_lease_principal', res.result.ccr_lease_principal);
                                record.set('ccr_lease_interest', res.result.ccr_lease_interest);
                                record.set('ccr_lease_penalty', res.result.ccr_lease_penalty);
                            },
                            error: function () {
                                record.set('ccr_lease_date', null);
                                record.set('ccr_lease_rental', null);
                                record.set('ccr_lease_principal', null);
                                record.set('ccr_lease_interest', null);
                                record.set('ccr_lease_penalty', null);
                            },
                            failure: function () {
                                record.set('ccr_lease_date', null);
                                record.set('ccr_lease_rental', null);
                                record.set('ccr_lease_principal', null);
                                record.set('ccr_lease_interest', null);
                                record.set('ccr_lease_penalty', null);
                            },
                            scope: this
                        });
                    }if (name == 'pay_method') {
                        if ( value== 'WIRE_TRANSFER') {
                            record.set('bank_account_id', null);
                            record.set('bank_account_id_n', null);
                            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);
                            record.set('bank_account_name', null);
                            record.set('bank_branch_num', null);
                            record.set('bank_branch_name', null);
                            record.set('withhold_way', null);
                        } else if (value== 'AGRI_THREE'){
                            record.getField('bank_account_id').setReadOnly(false);
                            record.getField('bank_account_id_n').setReadOnly(false);
                            record.getField('bank_account_id').setRequired(true);
                            record.getField('bank_account_id_n').setRequired(true);
                            record.set('withhold_way', 'ABC');
                        }
                        else if (value == 'AGRI_TWO'){
                            record.getField('bank_account_id').setReadOnly(false);
                            record.getField('bank_account_id_n').setReadOnly(false);
                            record.getField('bank_account_id').setRequired(true);
                            record.getField('bank_account_id_n').setRequired(true);
                            record.set('withhold_way', 'ABC_2');
                        }
                        else if (value == 'CCB_THREE'||value == 'CCB_TWO'){
                            record.getField('bank_account_id').setReadOnly(false);
                            record.getField('bank_account_id_n').setReadOnly(false);
                            record.getField('bank_account_id').setRequired(true);
                            record.getField('bank_account_id_n').setRequired(true);
                            record.set('withhold_way', null);
                        }

                    }
					 //新增 “限制金额”字段；
                    //“扣款限额”：“租金支付方式”为“建行扣款（三方）”时展示，必填，大于0，默认20万，可修改；
                    if (name == 'pay_method') {
                        if (value == 'CCB_THREE'||value == 'CCB_TWO') {
                            document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_prompt').style.display = 'block';
                            document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT').style.display = 'block';
                            record.getField('deduction_limit').setRequired(true);
                            if (Ext.isEmpty(record.get('deduction_limit'))) {
                                record.set('deduction_limit', 200000);
                            }
                        } else {
                            record.getField('deduction_limit').setRequired(false);
                            record.set('deduction_limit', null);
                            document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_prompt').style.display = 'none';
                            document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT').style.display = 'none';
                        }
                    }
                }
                // 回款賬戶變更
                if ('${/parameter/@layout_code}' == 'CON_ACCOUNT_CHANGE_MODIFY') {
                    debugger;
                    if (name == 'pay_method') {
                        if ( value== 'WIRE_TRANSFER') {
                            record.set('bank_account_id', null);
                            record.set('bank_account_id_n', null);
                            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);
                            record.set('bank_account_name', null);
                            record.set('bank_branch_num', null);
                            record.set('bank_branch_name', null);
                            record.set('withhold_way', null);
                        } else if (value== 'AGRI_THREE'){
                            record.getField('bank_account_id').setReadOnly(false);
                            record.getField('bank_account_id_n').setReadOnly(false);
                            record.getField('bank_account_id').setRequired(true);
                            record.getField('bank_account_id_n').setRequired(true);
                            record.set('withhold_way', 'ABC');
                        }
                        else if (value == 'AGRI_TWO'){
                            record.getField('bank_account_id').setReadOnly(false);
                            record.getField('bank_account_id_n').setReadOnly(false);
                            record.getField('bank_account_id').setRequired(true);
                            record.getField('bank_account_id_n').setRequired(true);
                            record.set('withhold_way', 'ABC_2');
                        }
                        else if (value == 'CCB_THREE'||value == 'CCB_TWO'){
                            record.getField('bank_account_id').setReadOnly(false);
                            record.getField('bank_account_id_n').setReadOnly(false);
                            record.getField('bank_account_id').setRequired(true);
                            record.getField('bank_account_id_n').setRequired(true);
                            record.set('withhold_way', null);
                        }

                    }
					 //新增 “限制金额”字段；
                    //“扣款限额”：“租金支付方式”为“建行扣款（三方）”时展示，必填，大于0，默认20万，可修改；
                    if (name == 'pay_method') {
                        if (value == 'CCB_THREE'||value == 'CCB_TWO') {
                            document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_prompt').style.display = 'block';
                            document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT').style.display = 'block';
                            record.getField('deduction_limit').setRequired(true);
                            if (Ext.isEmpty(record.get('deduction_limit'))) {
                                record.set('deduction_limit', 200000);
                            }
                        } else {
                            record.getField('deduction_limit').setRequired(false);
                            record.set('deduction_limit', null);
                            document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_prompt').style.display = 'none';
                            document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT').style.display = 'none';
                        }
                    }
                }
                // 租赁计划變更
                if ('${/parameter/@layout_code}' == 'CON_CHANGE_MODIFY') {
                    var lease_times = record.get('lease_times') || 0;
                    if (name == 'ccr_start_times') {
                        Leaf.request({
                            url: $('set_sum_unreceived_principal_cancel_link').getUrl(),
                            para: {
                                contract_id: record.get('contract_id'),
                                ccr_start_times: value
                            },
                            success: function (res) {
                                record.set('sum_unreceived_principal', res.result.sum_unreceived_principal);
                            },
                            failure: function () {

                            },
                            error: function () {

                            },
                            scope: this
                        });
                        var ccr_outstanding_times = record.get('ccr_outstanding_times') || 0;
                        var curr_times = minus(plus(value || 0, ccr_outstanding_times || 0), 1);
                        if (curr_times > lease_times) {
                            record.set('extend_flag', 'Y');
                            record.set('deflation_flag', 'N');
                        }
                    }
                    if (name == 'ccr_outstanding_times') {
                        var ccr_start_times = record.get('ccr_start_times') || 0;
                        var curr_times = minus(plus(value || 0, ccr_start_times || 0), 1);
                        if (curr_times < lease_times) {
                            record.set('extend_flag', 'N');
                            record.set('deflation_flag', 'Y');
                        }
                    }
                }
            }

            if('${/parameter/@layout_code}' == 'CON_TENANT_CHANGE_MODIFY'){
                var tennat_score_ds_id1=get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');
              if(ds.id==tennat_score_ds_id1){
                  if(name=='third_guar_score'&&!Ext.isEmpty(value)){
                      if(value<0||value>10){
                          setTimeout(function () {
                              record.set('third_guar_score', '');
                          }, 0);
                          Leaf.showInfoMessage("提示", "第三方担保附件分数范围为0-10，请重新输入！");

                      }
                  }
              }
            }
        };

        //新增和加载时调用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_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            if (ds_id == ds.id && ds_id) {
                if (record.get('pay_method') == 'WIRE_TRANSFER') {
                    record.set('bank_account_id', null);
                    record.set('bank_account_id_n', null);
                    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);
                    record.set('bank_account_name', null);
                    record.set('bank_branch_num', null);
                    record.set('bank_branch_name', null);

                }
				 if ('${/parameter/@layout_code}' == 'CON_ACCOUNT_CHANGE_MODIFY' || '${/parameter/@layout_code}' == 'CON_TENANT_CHANGE_MODIFY') {
                    //新增 “限制金额”字段；
                    //“扣款限额”：“租金支付方式”为“建行扣款（三方）”时展示，必填，大于0，默认20万，可修改；
                    if (record.get('pay_method') == 'CCB_THREE'||record.get('pay_method') == 'CCB_TWO') {
                        document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_prompt').style.display = 'block';
                        document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT').style.display = 'block';
                        record.getField('deduction_limit').setRequired(true);
                    } else {
                        document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_prompt').style.display = 'none';
                        document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT').style.display = 'none';
                        record.getField('deduction_limit').setRequired(false);
                    }
                }
                //原楼扣款限额隐藏
                if ('${/parameter/@layout_code}' == 'CON_ACCOUNT_CHANGE_MODIFY') {
                    if (record.get('pay_method_old') == 'CCB_THREE'||record.get('pay_method_old') == 'CCB_TWO') {
                        document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_S_prompt').style.display = 'block';
                        document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_S').style.display = 'block';
                    } else {
                        document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_S_prompt').style.display = 'none';
                        document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_DEDUCTION_LIMIT_S').style.display = 'none';
                    }
                }
                var tennat_score_ds_id=get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');
                 if(tennat_score_ds_id){

                     var division=record.get('division');
                     if(division!='70'){
                         document.getElementById('${/parameter/@layout_code}_F_TENANT_SCORE_INFO_BP_TENANT_RATE_DETAIL_TJ_SCORE_prompt').style.display = 'none';
                         document.getElementById('${/parameter/@layout_code}_F_TENANT_SCORE_INFO_BP_TENANT_RATE_DETAIL_TJ_SCORE').style.display = 'none';
                     }
                 }
            }
			if('${/parameter/@function_code}' == 'CON_REPO001D_WQ'){
                if (!record.get('rec_residue_amount')){
                    var rec_residue_amount = record.get('sum_unreceived_rent_amount') + record.get('sum_overdue_amount')+record.get('due_amount')+record.get('residual_value');
                    record.set('rec_residue_amount',rec_residue_amount);
                }
            }
                var tennat_score_ds_id1=get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TENANT_SCORE_INFO', 'bp_tenant_rate_detail');
                if(ds.id==tennat_score_ds_id1&&tennat_score_ds_id1){
                    var con_record=$(ds_id).getCurrentRecord();
                    if(con_record){
                        var division=con_record.get('division');
                        if(division!='70'){
                            document.getElementById('${/parameter/@layout_code}_F_TENANT_SCORE_INFO_BP_TENANT_RATE_DETAIL_TJ_SCORE_prompt').style.display = 'none';
                            document.getElementById('${/parameter/@layout_code}_F_TENANT_SCORE_INFO_BP_TENANT_RATE_DETAIL_TJ_SCORE').style.display = 'none';
                        }
                    }

                }
            //add by xsh35973 调整后不为默认值高亮显示
            //调整后逾期罚息
            var ds_id_req = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_change_req');
            if (ds_id_req == ds.id && ds_id_req) {
                if(record.get('document_type')=='REPUR_CHAG'|| record.get('document_type')=='ET_CHAG'){
                if (record.get('ccr_penalty') != record.get('penalty')) {
                    var req_change_id_1 = document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_CCR_PENALTY');
                    var req_change_input_1 = req_change_id_1.getElementsByTagName('input');
                    req_change_input_1[0].style.setProperty('background-color', '#FF9965', 'important');
                }
                ;
                //调整后资金占用费
                if (record.get('fund_possession_cost') != record.get('ccr_fund_possession_cost')) {
                    var req_change_id_2 = document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_FUND_POSSESSION_COST');
                    var req_change_input_2 = req_change_id_2.getElementsByTagName('input');
                    req_change_input_2[0].style.setProperty('background-color', '#FF9965', 'important');
                }
                ;
                //调整后提前结清手续费
                var et_fee = record.get('et_fee');
                if (et_fee != 500 && typeof (et_fee) != 'undefined') {
                    var req_change_id_3 = document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_ET_FEE');
                    var req_change_input_3 = req_change_id_3.getElementsByTagName('input');
                    req_change_input_3[0].style.setProperty('background-color', '#FF9965', 'important');
                }
                ;
                //调整后留购价
                var residual_value = record.get('residual_value');
                var ccr_residual_value = record.get('ccr_residual_value');
                var amount_250 = record.get('amount_250');
                
                if (amount_250 == 0){
                    if (residual_value != ccr_residual_value && typeof (residual_value) != 'undefined') {
                        var req_change_id_4 = document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_RESIDUAL_VALUE');
                        var req_change_input_4 = req_change_id_4.getElementsByTagName('input');
                        req_change_input_4[0].style.setProperty('background-color', '#FF9965', 'important');
                    }  
                    
                }
                if(amount_250 != 0){
                    if (residual_value != 0 && typeof (residual_value) != 'undefined') {
                        var req_change_id_4 = document.getElementById('${/parameter/@layout_code}_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_RESIDUAL_VALUE');
                        var req_change_input_4 = req_change_id_4.getElementsByTagName('input');
                        req_change_input_4[0].style.setProperty('background-color', '#FF9965', 'important');
                    }
                }
                
            }
            }
        };

        window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function () {
            //  $('${/parameter/@layout_code}_submit_approval').disable();
            var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var req_ds_id2 = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_change_req');
            var attch_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_cdd_item_doc_ref');
            var req_record = $(req_ds_id).getAt(0);
            var case_type = '';
            var document_type = '${/parameter/@document_type}';
            var calc_session_id = req_record.get('calc_session_id');
            // window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            for (var i=0;i<$(attch_id).getAll().length;i++){
                if ($(attch_id).getAll()[i].dirty == true) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                    //  $('${/parameter/@layout_code}_submit_approval').enable();
                    // window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    return false;
                }
            }
            if (req_record.dirty == true) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                //  $('${/parameter/@layout_code}_submit_approval').enable();
                // window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                return false;
            }
            if ($(req_ds_id).validate($('${/parameter/@layout_code}_submit_approval').enable()) && $(req_ds_id2).validate($('${/parameter/@layout_code}_submit_approval').enable())) {
                // if (req_record.dirty) {
                //     Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                //     window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                //     return;
                // }
                // 回款賬戶變更
                // if ('${/parameter/@layout_code}' == 'CON_ACCOUNT_CHANGE_MODIFY') {
                //     var bank_account_num_s = req_record.get('bank_account_num_s');
                //     var bank_account_num_c = req_record.get('bank_branch_num');
                //     if (bank_account_num_s == bank_account_num_c) {
                //         Leaf.showMessage('警告', '现扣款账号和原扣款账号不能重复！');
                //         //     window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                //         return false;
                //
                //     } else {
                //         con731_submit();
                //     }
                // } else
                    if ('${/parameter/@layout_code}' == 'CON_TENANT_CHANGE_MODIFY') {
                    var bp_id_tenant = req_record.get('bp_id_tenant');
                    var bp_id_tenant_old = req_record.get('bp_id_tenant_old');
                    if (bp_id_tenant == bp_id_tenant_old) {
                        Leaf.showMessage('警告', '变更承租人和原承租人不能重复！');
                        //    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        return false;
                    }
                    else {
                        con731_submit();
                    }

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

        function con731_submit() {
            var same_flag = 'Y';
            // 承租人变更
            if ('${/parameter/@layout_code}' == 'CON_TENANT_CHANGE_MODIFY') {
                Leaf.request({
                    url: $('con_guarantor_comparison_link').getUrl(),
                    para: {
                        change_req_id: '${/parameter/@change_req_id}',
                    },
                    success: function (res) {
                        debugger;
                        same_flag = res.result.same_flag;
                    },
                    failure: function () {

                },
                error: function () {

                },
                scope: this,
                sync: true
            });
            }
            if(same_flag=='Y'){
                var showMessage  ='是否确认提交审批？';
            }else{
                var showMessage ='担保人未发生变更,是否确认提交审批？';
            }
            // debugger;
            Leaf.showConfirm('${l:HLS.PROMPT}', showMessage, function () {
                var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var req_record = $(req_ds_id).getAt(0);
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('con731_submit_link').getUrl(),
                    para: {
                        change_req_id: '${/parameter/@change_req_id}',
                        layout_code: '${/parameter/@layout_code}'
                    },
                    success: function (res) {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $('${/parameter/@winid}').close();

                    },
                    failure: function () {
                        // $('${/parameter/@layout_code}_submit_approval').enable();
                        // $('${/parameter/@layout_code}_save').enable();
                        //  if('${/parameter/@layout_code}' == 'CON_CHANGE_MODIFY'){
                        //          $('${/parameter/@layout_code}_quote').enable();
                        //  }
                        //  $('${/parameter/@layout_code}_user_button1').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function () {
                        // $('${/parameter/@layout_code}_submit_approval').enable();
                        // $('${/parameter/@layout_code}_save').enable();
                        // if('${/parameter/@layout_code}' == 'CON_CHANGE_MODIFY'){
                        //         $('${/parameter/@layout_code}_quote').enable();
                        // }
                        // $('${/parameter/@layout_code}_user_button1').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            }, null, 300, 150);
        }

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


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

        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {
            var ds_con_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_QUOTATION_01', 'con_contract');

            var record = $(ds_con_id).getCurrentRecord();
            if (record) {
                var param = record.data;
                if (record.get('contract_id')) {
                    param['project_id'] = record.get('contract_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_con_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
                        });

                    }
                } else {
                    Leaf.showMessage('${l:PROMPT}', '请先保存');

                }
            }

        }

        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            //  $('${/parameter/@layout_code}_user_button1').disable();
            Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认取消变更？', function () {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('con731_cancel_link').getUrl(),
                    para: {
                        change_req_id: ${/parameter/@change_req_id}
                    },
                    success: function (res) {
                        //   $('${/parameter/@layout_code}_user_button1').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $('${/parameter/@winid}').close();
                    },
                    failure: function () {
                        //    $('${/parameter/@layout_code}_user_button1').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function () {
                        //      $('${/parameter/@layout_code}_user_button1').enable();
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            });
        };

        //附件上传

        function con_repo001_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 con731n_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}_con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}hls_bp_master_query_link', record.ds.id, '${/parameter/@layout_code}');
        }

        function con731n_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}_con_contract_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 == '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 == 'bp_link1' && !record.isNew) {
                link_function = 'con731n_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 == 'contract_number') {
                link_function = 'con731n_contract_number_renderer';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + value + '</a>';
            }else if (name == 'attachment') {
                link_function = 'con_repo001_upload_file';
                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('.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;
                }
            }
        };
        //图片渲染
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_dynamic_pic_renderer'] = function (record, name, bp_seq) {
            var result = name.match(/(.*)_pic$/);
            if (result) {
                var pic_value = record.get(result[1]);
                if (pic_value == 'OUTFLOW') {
                    return '<img src="${/request/@context_path}/images/outflow.png" style="margin-top:4px"/>';
                } else if (pic_value == 'INFLOW') {
                    return '<img src="${/request/@context_path}/images/inflow.png" style="margin-top:4px"/>';
                } else if (pic_value == 'NONCASH') {
                    return '<img src="${/request/@context_path}/images/noncash.png" style="margin-top:4px"/>';
                } else if (pic_value == 'CASH') {
                    return '<img src="${/request/@context_path}/images/cash.png" style="margin-top:4px"/>';
                }
            }
        };

        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');
            if( record.get('bp_category')=='AGENT'){
                param['function_code'] = 'HLS303_Q';
                param['function_usage'] = 'QUERY';
            }else{
                param['function_code'] = 'CON505H';
                param['function_usage'] = 'QUERY';
            }
            param['bp_type'] = record.get('bp_type');
            param['download'] = 'Y';


            param['url_title'] = '${l:HLS212.BP_MASTER_QUERY}';
            hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, 'con731_hls_bp_master_query_link', record.ds.id, '${/parameter/@layout_code}');
        };

        //加载时调用(grid,table,gridBox)
        var query_count = 1;
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
            if ('${/parameter/@layout_code}' == 'CON_TENANT_CHANGE_MODIFY'){
             var project_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_QUOTATION_01', 'con_contract');
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            if(ds.id==ds_id&& ds_id && query_count == 1) {
                query_count = query_count + 1;
                var bp_id = $(project_ds_id).getAt(0).get('bp_id_tenant');
                $(ds_id).setQueryParameter('bp_id', bp_id);
                $(ds_id).query();
            }
            }
            var lease_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASE_10', 'con_contract_lease_item');
            if(ds.id == lease_ds_id&&lease_ds_id){
                var gridId= ds.bindname+'_layout_grid_id';
                var division =$(project_ds_id).getAt(0).get('division');
                if(division=='70' || division=='92'){
                    $(gridId).hideColumn('full_name');
                    $(gridId).hideColumn('machine_number');
                }else {
                    $(gridId).hideColumn('lease_name');
                    $(gridId).hideColumn('machine_number_70');
                }
            };
        };
        //选择事件(grid,attach,gridbox,table)
        /*window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_before_select'] = function(ds, record, bp_seq) {
            if((record.get('bp_category') == 'TENANT' || record.get('bp_category') == 'AGENT') && record.isSelected){
                setTimeout(function() {
                    $(ds.id).unSelect(record);
                }, 0);
            }
        };*/
		 //add by lihh 20210330审批记录打印
            window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function() {
                debugger;
                    var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                    var records = $(ds_id).getCurrentRecord();
                    var document_id = records.get('contract_id');
                    var url_l;
                    var file_name;
                    if('${/parameter/@function_code}' == 'CON_REPO001D_WQ'){
                         file_name = records.get('contract_number') + "合同-解约回购审批记录打印";
                         url_l = $('con_buyback_info_print_link_id').getUrl() + '?document_id=' + document_id + '&file_name=' + encodeURI(file_name) +'&document_table=CON_CONTRACT_BUYBACK_INFO&batch_flag=Y&source_type=COMMON';
                    }
                    if('${/parameter/@function_code}' == 'CON_ET002_WQ'){
                         file_name = records.get('contract_number') + "合同-提前结清审批记录打印";
                         url_l = $('con_buyback_info_print_link_id').getUrl() + '?document_id=' + document_id + '&file_name=' + encodeURI(file_name) +'&document_table=CON_CONTRACT_CLOSE_BEFORE&batch_flag=Y&source_type=COMMON';
                    }
                    if('${/parameter/@function_code}' == 'CON733BPT_WQ'){
                        file_name = records.get('contract_number') + "合同-承租人变更审批记录打印";
                        url_l = $('con_buyback_info_print_link_id').getUrl() + '?document_id=' + document_id + '&file_name=' + encodeURI(file_name) +'&document_table=CON_CONTRACT_TENANT_CHANGE&batch_flag=Y&source_type=COMMON';
                    }
                    var OpenWindow = window.open(href = url_l, target = "_blank");
            };
			
			 //保存前调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function (ds, record) {
            var check_flag = true;
            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            if (ds_id == ds.id && ds_id) {
                if ('${/parameter/@layout_code}' == 'CON_ACCOUNT_CHANGE_MODIFY' || '${/parameter/@layout_code}' == 'CON_TENANT_CHANGE_MODIFY') {
                    if (record.get('pay_method') == 'CCB_THREE'||record.get('pay_method') == 'CCB_TWO') {
                        if (record.get('deduction_limit') <= 0) {
                            Leaf.showMessage('${l:HLS.PROMPT}', '扣款限额应大于0');
                            return false;
                        }
                        $L.request({
                            url: $('con_check_deduction_limit_link').getUrl(),
                            para: {
                                change_req_id: record.get('change_req_id'),
                                pay_method: record.get('pay_method'),
                                bank_branch_num: record.get('bank_branch_num'),
                                contract_number: record.get('contract_number'),
                                deduction_limit: record.get('deduction_limit'),
                                layout_code:'${/parameter/@layout_code}'
                            },
                            success: function (args) {
                                $L.Masker.unmask(Ext.getBody());
                                check_flag = false;
                                if (args.result.err_msg) {
                                    $L.showConfirm('提示', args.result.err_msg, function () {
                                        var root_ds = $('${/parameter/@bp_seq}${/parameter/@layout_code}_virtual_ds');
                                        root_ds.submit();
                                    });
                                } else {
                                    check_flag = true;
                                    return check_flag;
                                }
                            },
                            failure: function (res) {
                                check_flag = false;
                                return check_flag;
                                $L.Masker.unmask(Ext.getBody());
                            },
                            error: function (res) {
                                check_flag = false;
                                return check_flag;
                                $L.Masker.unmask(Ext.getBody());
                            },
                            sync: true,
                            scope: this
                        });
                    }
                }
            }
            if('${/parameter/@layout_code}' == 'CON_TENANT_CHANGE_MODIFY'){
                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 == ds_id) {
                    var con_record=$(ds_id).getCurrentRecord();
                    var division=con_record.get('divison');
                    for (var key in bp_tenant_detail_r.data) {
                        if(division!='70'){
                            if (key != 'bp_detail_id' && key != 'score_name' && key != 'bp_age' && key != 'project_id' && key != 'third_party_credibility' && key != 'third_party_credibility_n'&& key != 'third_guar_score'&&key != 'tj_score') {
                                //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("提示", "承租人评分信息区域的所有字段，除\"第三方担保附件得分\"外，其他都为必输字段，请填写！");
                                    check_flag = false;
                                    break;
                                } else {
                                    check_flag = true;
                                }
                            }
                        }else{
                            if (key != 'bp_detail_id' && key != 'score_name' && key != 'bp_age' && key != 'project_id' && key != 'third_party_credibility' && key != 'third_party_credibility_n'&& key != 'third_guar_score') {
                                //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("提示", "承租人评分信息区域的所有字段，除\"第三方担保附件得分\"外，其他都为必输字段，请填写！");
                                    check_flag = false;
                                    break;
                                } else {
                                    check_flag = true;
                                }
                            }
                        }

                    }
                }
            }

            return check_flag;
        };

        Leaf.onReady(init);

        function init() {
            if ('${/parameter/@function_code}' == 'CON_REPO001D_WQ' || '${/parameter/@function_code}' == 'CON_ET002_WQ' || '${/parameter/@function_code}' == 'CON733BPT_WQ') {
                if ('${/model/default_value_path/record/@req_status}' != 'APPROVED') {
                    document.getElementById('${/parameter/@layout_code}_user_button4').style.display = "none";
                    // $('${/parameter/@layout_code}_user_button4').disable();
                }
            }
        }

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