<?xml version="1.0" encoding="UTF-8"?>
<!--
    2019-9-6  Spencer 3893  合同提前结清申请创建明细
 -->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.user_id=${/session/@user_id}" fetchAll="true" model="wx.WX100.sys_pilot_run_user" rootPath="pilot_run_user"/>
        <a:model-query defaultWhereClause="t1.contract_id=${/parameter/@contract_id}" fetchAll="true" model="cont.CON_ET001.con_get_contract_status" rootPath="get_contract_status"/>
        <a:model-query defaultWhereClause="t1.contract_id=${/parameter/@contract_id}" fetchAll="true" model="cont.CON_ET001.create_change_req" rootPath="get_contract_division"/>
	   <a:model-query fetchAll="true" model="cont.CON_ET001.con_asset_fee_calc" rootPath="asset_flag_path" ></a:model-query>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_repo_detail_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con_et002_submit_link" model="cont.CON_ET001.submit_change_req" modelaction="execute"/>
        <a:link id="con_et002_cancel_link" model="cont.CON731.cancel_change_req" modelaction="execute"/>
        <a:link id="con_et001_calc_cashflow_link" model="cont.CON_ET001.calc_cashflow" modelaction="execute"/>
        <a:link id="con_et001_calc_cashflow_link1" model="cont.CON_ET001.insert_calc_cashflow" modelaction="execute"/>
        <a:link id="con_et001_calc_et_date_amount_link" model="cont.CON_ET001.calc_et_date_amount" modelaction="execute"/>
        <a:link id="con731_cancel_link" model="cont.CON731.cancel_change_req" modelaction="execute"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_uploadFile_id"
                url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_downloadFile_id"
                url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_con_ele_terminate_create_link_id"
                url="${/request/@context_path}/modules/wx/WX100/con_ele_terminate_create.lsc"/>
        <a:link id="${/parameter/@layout_code}_ele_operator_verify_link_id"
                url="${/request/@context_path}/modules/wx/WX100/wx_ele_verify_operator.lsc"/>
        <a:link id="${/parameter/@layout_code}_con_ele_sign_cancel_link_id"
                url="${/request/@context_path}/modules/cont/CON505/con_ele_sign_cancel.lsc"/>
	<a:link id="con_lease_org_print_link"
                url="${/request/@context_path}/modules/cont/CON_ET001/create_content_for_con_et.lsc"/>
        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>
        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <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();
            }
			if ('${/parameter/@simulation_flag}' == 'Y') {
                if (document.getElementById('${/parameter/@layout_code}_submit_approval')) {
                    document.getElementById('${/parameter/@layout_code}_submit_approval').style.display = 'none';
                }
                if (document.getElementById('${/parameter/@layout_code}_user_button3')) {
                    document.getElementById('${/parameter/@layout_code}_user_button3').style.display = 'none';
                }
                if (document.getElementById('${/parameter/@layout_code}_user_button4')) {
                    document.getElementById('${/parameter/@layout_code}_user_button4').style.display = 'none';
                }
            }
            else{
                if (document.getElementById('${/parameter/@layout_code}_user_button5')) {
                    document.getElementById('${/parameter/@layout_code}_user_button5').style.display = 'none';
                }
            }
            if ('${/model/pilot_run_user/record/@pilot_run_flag}' != 'Y'){
                $('${/parameter/@layout_code}_user_button4').hide();
            }
            //铁甲业务合同展示保证金字段  18083  2023/5/11
            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";
		      }
			}
			 //报价中资管费字段为否时，不展示资产管理费字段 18083 2024/1/29
           if('${/model/asset_flag_path/record/@hd_user_col_v06}' !='Y'){
              if(document.getElementById("CON_ET_MODIFY_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_ASSET_POSSESSION_COST")){
              document.getElementById("CON_ET_MODIFY_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_ASSET_POSSESSION_COST_prompt").style.display = "none";
              document.getElementById("CON_ET_MODIFY_F_QUOTATION_01_CON_CONTRACT_CHANGE_REQ_ASSET_POSSESSION_COST").style.display = "none";
            }
            }
        });
        var calc_flag='N';
        //新增和加载时调用form
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
             var ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_BASE_01', 'con_contract_change_req');
             if (ds_id == ds.id && ds_id) {
                if(record.get('bp_class') == 'NP'){
                    record.getField('signer_n').setReadOnly(true);
                    record.getField('signer_n').setRequired(false);
                    record.set('signer_n','');
                }
                if(record.get('division') == '70'){
                record.getField('deposit_deduction').setRequired(true);
                }
            }

        };

		var clc_flag = 'N';
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
             var ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_BASE_01', 'con_contract_change_req');
            if (ds == $(ds_id)) {
                if(value!=old_value){
                    calc_flag='N';
                    record.set('calc_flag','N');
                }
                //调整后提前结清手续费
                if (name == 'et_fee') {
                    var et_total_amount=record.get('et_total_amount')||0;
                    var old_et_fee=old_value||0;
                    record.set('et_total_amount', plus(minus(et_total_amount,old_et_fee),value||0));
                }
                //调整后逾期罚息
                if (name == 'ccr_penalty') {
                    var et_total_amount=record.get('et_total_amount')||0;
                    var due_amount = record.get('penalty') || 0;
                    if (due_amount < value) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '调整后的罚息必须小于等于逾期罚息！');
                        setTimeout(function () {
                            record.set('ccr_penalty', 0);
                        }, 5);
                        return;
                    }
                    if (value < 0 || value == NaN || value == undefined) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '调整后的罚息金额应大于等于0！');
                        setTimeout(function () {
                            record.set('ccr_penalty', 0);
                        }, 5);
                        return;
                    }
                    record.set('et_total_amount',minus(plus(plus(plus(plus(record.get('et_due_amount')||0,record.get('et_fee')||0),record.get('residual_value')||0),record.get('overdue_amount')||0),value),record.get('deposit_deduction')||0));
                 }
                //铁甲业务计算保证金抵扣金额  18083 2023/5/12
                if('${/model/get_contract_division/record/@division}' =='70' && '${/model/get_contract_division/record/@division}' != ''){
                if (name == 'deposit_deduction') {
                var et_total_amount=record.get('et_total_amount')||0;
                var deposit_balance = record.get('deposit_balance') || 0;
                var old_deposit_balance=old_value||0;
                if (deposit_balance < value) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '调整后的保证金抵扣金额必须小于等于保证金余额！');
                    setTimeout(function () {
                        record.set('deposit_deduction', 0);
                    }, 5);
                    return;
                }

                if (value < 0 || value == NaN || value == undefined) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '调整后的保证金抵扣金额应大于等于0！');
                    setTimeout(function () {
                        record.set('deposit_deduction', 0);
                    }, 5);
                    return;
                }
                //调整后的保证金余额应小于支付总额
                if (value > et_total_amount) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '调整后的保证金抵扣金额应小于支付总额！');
                    setTimeout(function () {
                        record.set('deposit_deduction', 0);
                    }, 5);
                    return;
                }
                 record.set('et_total_amount', minus(plus(plus(plus(plus(record.get('et_due_amount')||0,record.get('et_fee')||0),record.get('residual_value')||0),record.get('overdue_amount')||0),record.get('ccr_penalty')||0),value));

                        }
                 }

                if (name == 'termination_date'&&value) {
                     // 根据结清日计算结清相关金额字段
                    Leaf.request({
                        url: $('con_et001_calc_et_date_amount_link').getUrl(),
                        para: {
                            change_req_id:record.get('change_req_id'),
                            contract_id: record.get('contract_id'),
                            termination_date: value,
                            /**提前结清手续费**/
                            et_fee: record.get('et_fee') || 0,
                            /**提前结清利率**/
                            et_interest_rate: record.get('et_interest_rate'),
                            /**留购价**/
                            residual_value: record.get('residual_value'),  //update by xsh35973 20220613
                            /**保证金抵扣金额**/
                            deposit_deduction: record.get('deposit_deduction')||0  //update by 18083 2023/5/12
                        },
                        success: function (res) {
						     clc_flag = 'Y';
						     //record.set('et_fee', res.result.et_fee);
                            record.set('et_total_amount', res.result.et_total_amount);
                            record.set('et_due_amount', res.result.et_due_amount);
                            record.set('overdue_amount', res.result.overdue_amount||0);
                            record.set('penalty', res.result.penalty||0);
                            record.set('ccr_penalty', res.result.penalty||0);
                            record.set('fund_possession_time', res.result.fund_possession_time);
                            record.set('fund_possession_cost', res.result.fund_possession_cost);
                            record.set('ccr_fund_possession_cost', res.result.fund_possession_cost);   //add by xsh35973 20220610
                            record.set('fund_possession_rate', res.result.fund_possession_rate);
                            record.set('last_rent_due_date',res.result.last_rent_due_date);
                            record.set('sum_unreceived_principal',res.result.sum_unreceived_principal);
							record.set('asset_possession_cost', res.result.asset_possession_cost);
							clc_flag = 'N';
                        },
                        failure: function () {
                            record.set('termination_date','');
                            record.set('et_total_amount','');
                            record.set('et_due_amount','');
                            record.set('overdue_amount', '');
                            record.set('penalty', '');
                            record.set('ccr_penalty', '');
                            record.set('fund_possession_time','');
                            record.set('fund_possession_cost','');
                            //record.set('fund_possession_rate','');
                            record.set('last_rent_due_date','');
                            record.set('sum_unreceived_principal','');
							record.set('asset_possession_cost','');
                        },
                        error: function () {
                            record.set('termination_date','');
                            record.set('et_total_amount','');
                            record.set('et_due_amount','');
                            record.set('overdue_amount', '');
                            record.set('penalty', '');
                            record.set('ccr_penalty', '');
                            record.set('fund_possession_time','');
                            record.set('fund_possession_cost','');
                            //record.set('fund_possession_rate','');
                            record.set('last_rent_due_date','');
                            record.set('sum_unreceived_principal','');
							record.set('asset_possession_cost','');
                        },
                        scope: this
                    });
                }
                //add by xsh35973 添加修改调整后资源占用费提前结清租金跟随变动
                //调整后资金占用费
                if(name == 'fund_possession_cost'&& clc_flag =='N'){
                    if (value < 0 || value == NaN || value == undefined) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '调整后的资金占用费金额应大于等于0！');
                        setTimeout(function () {
                            record.set('fund_possession_cost', 0);
                        }, 5);
                        return;
                    }
                    var sum_unreceived_principal = record.get('sum_unreceived_principal') || 0;
                    if(sum_unreceived_principal !=0) {
                        var et_due_amount_result = plus(sum_unreceived_principal, value);
                        record.set('et_due_amount', et_due_amount_result);
                    }
					 //调整资金占用费 18083 2023/2/6
                   var fund_possession_time = record.get('fund_possession_time')||0;
                   var btb_int_rate = record.get('btb_int_rate')||0;
                   var asset_possession_cost_result =value-sum_unreceived_principal*fund_possession_time*btb_int_rate/360;
                   if(asset_possession_cost_result<0|| asset_possession_cost_result == NaN || asset_possession_cost_result == undefined) {
                   record.set('asset_possession_cost', 0);
                   }else{
                   record.set('asset_possession_cost', asset_possession_cost_result);
                    }
                }
                if(name == 'residual_value'&& clc_flag =='N'){
                    if (value < 0 || value == NaN || value == undefined) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '调整后的留购金金额应大于等于0！');
                        setTimeout(function () {
                            record.set('residual_value', 0);
                        }, 5);
                        return;
                    }
                    var et_total_amount_result=minus(plus(plus(plus(plus(record.get('et_due_amount') || 0, record.get('et_fee') || 0), record.get('residual_value') || 0), record.get('overdue_amount') || 0), record.get('ccr_penalty')),record.get('deposit_deduction') || 0);
                    record.set('et_total_amount',et_total_amount_result);
                }
                //提前结清租金
                if(name == 'et_due_amount'&& clc_flag =='N'){
                    if (value < 0 || value == NaN || value == undefined) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '调整后的提前结清租金金额应大于等于0！');
                        setTimeout(function () {
                            record.set('et_due_amount', 0);
                        }, 5);
                        return;
                    }
                     var et_total_amount_result=minus(plus(plus(plus(plus(record.get('et_due_amount') || 0, record.get('et_fee') || 0), record.get('residual_value') || 0), record.get('overdue_amount') || 0), record.get('ccr_penalty')),record.get('deposit_deduction') || 0);
                    record.set('et_total_amount',et_total_amount_result);
                }
             }

        };

        window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
            $('${/parameter/@layout_code}_submit_approval').disable();
                var req_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASE_01', 'con_contract_change_req');
                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');
            calc_flag=req_record.get('calc_flag');
               // window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                if ($(req_ds_id).validate($('${/parameter/@layout_code}_submit_approval').enable())) {
                    if (req_record.dirty) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                     //   window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        return;
                    }
                    if (calc_flag=='N') {
                        Leaf.showMessage('${l:HLS.PROMPT}', '请先计算！');
                   //     window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        return;
                    }
                    //$('${/parameter/@layout_code}_submit_approval').disable();
                    //$('${/parameter/@layout_code}_save').disable();
                   // $('${/parameter/@layout_code}_user_button1').disable();
                   // $('${/parameter/@layout_code}_user_button3').disable();
                    //setTimeout(window['${/parameter/@layout_code}_SAVE_LAYOUT_DYNAMIC_CLICK'](con_repo001_submit), 2000);
                 // window['${/parameter/@layout_code}_SAVE_LAYOUT_DYNAMIC_CLICK'](con_repo001_submit);
                //解约回购合同增加提交审批前是否完全核销校验 add by xsh35973
                if('${/model/get_contract_status/record/@contract_status}' =='REPURING'){
                    Leaf.request({
                        url: '${/request/@context_path}/autocrud/cont.CON_ET001.con_get_contract_status/execute',
                        para: {
                            contract_id: '${/parameter/@contract_id}'
                        },
                        success: function(res) {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            con_repo001_submit();
                        },
                        failure: function () {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        error: function () {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                }else {
                    con_repo001_submit();
                };
                } else {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                }
        };
        function con_repo001_submit() {
            Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认提交审批？', function () {
                $('${/parameter/@layout_code}_submit_approval').disable();
                //$('${/parameter/@layout_code}_save').disable();
                // $('${/parameter/@layout_code}_user_button1').disable();
                // $('${/parameter/@layout_code}_user_button3').disable();
            var req_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASE_01', 'con_contract_change_req');
            var req_record = $(req_ds_id).getAt(0);
            var sign_type = req_record.get('sign_type');
            var flow_count = req_record.get('flow_count');
           // window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                if (sign_type == 'ELE_SIGN' && flow_count > 0){
                    Leaf.showConfirm('${l:HLS.PROMPT}', '您发起的电子签署还未完成，如此时提交，将会转为纸质签署，请确认。', function (){
                        Leaf.request({
                            url: $('${/parameter/@layout_code}_con_ele_sign_cancel_link_id').getUrl(),
                            para: {
                                contract_id: ${/parameter/@change_req_id}
                            },
                            scope: this,
                            success: function (res) {
                                if (res.result.message != null){
                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    $('${/parameter/@layout_code}_submit_approval').enable();
                                    $('${/parameter/@layout_code}_save').enable();
                                    $('${/parameter/@layout_code}_user_button1').enable();
                                    $('${/parameter/@layout_code}_user_button3').enable();
                                    Leaf.showMessage('${l:HLS.PROMPT}', res.result.message);
                                }else{
                                    Leaf.request({
                                        url: $('con_et002_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/@layout_code}_submit_approval').enable();
                                            $('${/parameter/@layout_code}_save').enable();
                                            $('${/parameter/@layout_code}_user_button1').enable();
                                            $('${/parameter/@layout_code}_user_button3').enable();
                                            $('${/parameter/@winid}').close();

                },
                failure: function() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    $('${/parameter/@layout_code}_submit_approval').enable();
                    $('${/parameter/@layout_code}_save').enable();
                    $('${/parameter/@layout_code}_user_button1').enable();
                    $('${/parameter/@layout_code}_user_button3').enable();

                },
                error: function() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    $('${/parameter/@layout_code}_submit_approval').enable();
                    $('${/parameter/@layout_code}_save').enable();
                    $('${/parameter/@layout_code}_user_button1').enable();
                    $('${/parameter/@layout_code}_user_button3').enable();

                                        },
                                        scope: this
                                    });
                                }
                            },
                            failure: function () {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                $('${/parameter/@layout_code}_submit_approval').enable();
                                $('${/parameter/@layout_code}_save').enable();
                                $('${/parameter/@layout_code}_user_button1').enable();
                                $('${/parameter/@layout_code}_user_button3').enable();
                            },
                            error: function () {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                $('${/parameter/@layout_code}_submit_approval').enable();
                                $('${/parameter/@layout_code}_save').enable();
                                $('${/parameter/@layout_code}_user_button1').enable();
                                $('${/parameter/@layout_code}_user_button3').enable();
                            }
                        });
                    });
                }else{
                    Leaf.request({
                        url: $('con_et002_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/@layout_code}_submit_approval').enable();
                            $('${/parameter/@layout_code}_save').enable();
                            $('${/parameter/@layout_code}_user_button1').enable();
                            $('${/parameter/@layout_code}_user_button3').enable();
                            $('${/parameter/@winid}').close();

                        },
                        failure: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $('${/parameter/@layout_code}_submit_approval').enable();
                            $('${/parameter/@layout_code}_save').enable();
                            $('${/parameter/@layout_code}_user_button1').enable();
                            $('${/parameter/@layout_code}_user_button3').enable();

                        },
                        error: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $('${/parameter/@layout_code}_submit_approval').enable();
                            $('${/parameter/@layout_code}_save').enable();
                            $('${/parameter/@layout_code}_user_button1').enable();
                            $('${/parameter/@layout_code}_user_button3').enable();

                        },
                        scope: this
                    });
                }
            }, null, 300, 150);
        }

        //保存submitsuccess调用
        window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function(ds, record, res, bp_seq) {
            var ca_ds_id_s = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'G_QUOTATION_03', 'con_contract_cashflow');
            if (ca_ds_id_s) {
                $(ca_ds_id_s).query();
            }
            var ca_ds_id_c = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'G_QUOTATION_04', 'con_contract_cashflow');
            if (ca_ds_id_c) {
                $(ca_ds_id_c).query();
            }
            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        };
        //报价计算
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            $('${/parameter/@layout_code}_user_button1').disable(); //按钮不可用
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var con_contract_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_BASE_01', 'con_contract_change_req');
            var con_record = $(con_contract_ds_id).getAt(0);
            if ($(con_contract_ds_id).validate()) {
                if (con_record.dirty) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
                    return;
                }
              clac();
            } else {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
            }
        };

        function clac(){
            Leaf.request({
                url: $('con_et001_calc_cashflow_link1').getUrl(),
                para: {
                    change_req_id: '${/parameter/@change_req_id}',
                },
                success: function(res) {
                    Leaf.SideBar.enable = true;
                    Leaf.SideBar.show({msg: '计算成功！',duration: 2000});
                    calc_flag='Y';
                    //con_record.getField('ccr_start_times').setReadOnly(true);
                    var ca_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'G_QUOTATION_02', 'con_contract_cashflow');
                    var con_contract_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_BASE_01', 'con_contract_change_req');
                    if (ca_ds_id&&con_contract_ds_id) {
                        $(ca_ds_id).query();
                        $(con_contract_ds_id).query();
                    }
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
                },
                failure: function() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
                },
                error: function() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
                },
                scope: this
            });
        }

        //取消变更
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {

            Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认取消变更？', function() {
                $('${/parameter/@layout_code}_user_button3').disable(); //按钮不可用
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('${/parameter/@layout_code}_con_ele_sign_cancel_link_id').getUrl(),
                    para: {
                        contract_id: ${/parameter/@change_req_id}
                    },
                    scope: this,
                    success: function (res) {
                        if (res.result.message != null){
                            $('${/parameter/@layout_code}_user_button3').enable(); //按钮启用
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            Leaf.showMessage('${l:HLS.PROMPT}', res.result.message)
                        }else{
                            Leaf.request({
                                url: $('con_et002_cancel_link').getUrl(),
                                para: {
                                    change_req_id: ${/parameter/@change_req_id}
                                },
                                success: function(res) {
                                    $('${/parameter/@layout_code}_user_button3').enable(); //按钮启用
                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    $('${/parameter/@winid}').close();
                                },
                                failure: function() {
                                    $('${/parameter/@layout_code}_user_button3').enable(); //按钮启用
                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                },
                                error: function() {
                                    $('${/parameter/@layout_code}_user_button3').enable(); //按钮启用
                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                },
                                scope: this
                            });
                        }
                    },
                    failure: function () {
                        $('${/parameter/@layout_code}_user_button3').enable(); //按钮启用
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function () {
                        $('${/parameter/@layout_code}_user_button3').enable(); //按钮启用
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    }
                });
            });
        };
        //提前结清发起电子签署 add by 24976
        window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function() {
            var req_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASE_01', 'con_contract_change_req');
            var req_record = $(req_ds_id).getAt(0);
            var req_status = req_record.get('req_status');
            var contract_id = req_record.get('contract_id');
            var change_req_id = req_record.get('change_req_id');
            var signer = req_record.get('signer');
            var bussiness_type = req_record.get('business_type');
            var bp_tenant_class = req_record.get('bp_class');
/*            if (req_status != 'NEW') {
                Leaf.showMessage('${l:PROMPT}', '只有新建状态的才能发起电子签约');
                return;
            }*/
            //解约回购的合同发起提前结清时，不能发起电子签约 add by xsh35973
            if('${/model/get_contract_status/record/@contract_status}' =='REPURING'){
                Leaf.showMessage('${l:PROMPT}', '解约回购的合同发起提前结清时，不能发起电子签约');
                return;
            };
            if(bussiness_type == 'LEASEBACK' && bp_tenant_class == 'NP'){
                Leaf.showMessage('${l:PROMPT}', '业务类型为售后回租且是个人承租人的合同，不能发起电子签约');
                return;
            }
            Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认发起电子签约？', function () {
                if (req_record.dirty == true) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                    return;
                }
                if (signer == null && bp_tenant_class == 'ORG') {
                    Leaf.showMessage('${l:PROMPT}', '发起电子签约时，签约人不能为空！');
                    return;
                }else if(bp_tenant_class == 'NP'){
                    req_record.getField('signer_n').setReadOnly(true);
                }
                $('${/parameter/@layout_code}_user_button3').disable();
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url:$('${/parameter/@layout_code}_ele_operator_verify_link_id').getUrl(),
                    para:{
                        contract_id:change_req_id,
                        esign_type:'ET'
                    },
                    scope:this,
                    success: function (res) {
                        if(res.result.check_flag == 'N'){
                            Leaf.showConfirm('${HLS.PROMPT}', '该企业下已存在其他经办人，如果发起签约，原账户将失效，请确认是否继续!', function () {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                                Leaf.request({
                                    url: $('${/parameter/@layout_code}_con_ele_sign_cancel_link_id').getUrl(),
                                    para: {
                                        contract_id: change_req_id
                                    },
                                    scope: this,
                                    success: function (res) {
                                        if (res.result.message != null){
                                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                            Leaf.showMessage('${l:HLS.PROMPT}', res.result.message)
                                        }else{
                                            Leaf.request({
                                                url: $('${/parameter/@layout_code}_con_ele_terminate_create_link_id').getUrl(),
                                                para: {
                                                    contract_id: change_req_id
                                                },
                                                success: function(res) {
                                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                                    $('${/parameter/@winid}').close();
                                                },
                                                failure: function() {
                                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                                },
                                                error: function() {
                                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                                },
                                                scope: this
                                            });
                                        }
                                    },
                                    failure: function () {
                                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    },
                                    error: function () {
                                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    }
                                });
                            });
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        }else{
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                            Leaf.request({
                                url: $('${/parameter/@layout_code}_con_ele_sign_cancel_link_id').getUrl(),
                                para: {
                                    contract_id: change_req_id
                                },
                                scope: this,
                                success: function (res) {
                                    if (res.result.message != null){
                                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                        Leaf.showMessage('${l:HLS.PROMPT}', res.result.message)
                                    }else{
                                        Leaf.request({
                                            url: $('${/parameter/@layout_code}_con_ele_terminate_create_link_id').getUrl(),
                                            para: {
                                                contract_id: change_req_id
                                            },
                                            success: function(res) {
                                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                                $('${/parameter/@winid}').close();
                                            },
                                            failure: function() {
                                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                            },
                                            error: function() {
                                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                            },
                                            scope: this
                                        });
                                    }
                                },
                                failure: function () {
                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                },
                                error: function () {
                                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                }
                            });
                        }
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    }
                });
            });
        }

        //加载时调用(grid,table,gridBox)
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function (ds, record, config_records, bp_seq) {
            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';
                if(record.data.division=='70' || record.data.division=='92'){
                    $(gridId).hideColumn('full_name');
                    $(gridId).hideColumn('machine_number');
                }else {
                    $(gridId).hideColumn('lease_name');
                    $(gridId).hideColumn('machine_number_70');
                }
            }
        }

        //图片渲染
        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"/>';
                }
            }
        };
        //附件上传

        function con_et_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}', '请先保存!');
            }
        }

        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 = 'con_et_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/@layout_code}_user_button5_layout_dynamic_click'] = function () {
            var req_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASE_01', 'con_contract_change_req');
            var req_record = $(req_ds_id).getAt(0);
             calc_flag = req_record.get('calc_flag')||'N';
                if (calc_flag == 'N') {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存并计算！');
                    return;
                }
            var contract_id =req_record.get('change_req_id');
            var templet_code = 'ET_CALCULATION_TABLE_SIMU';
            var  url=$('con_lease_org_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
            window.open(url, '_self');
        };
		
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>