<?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:view>
        <a:link id="con_repo_submit_link" model="cont.CON_REPO001.submit_change_req" modelaction="execute"/>
        <a:link id="con_repo001_cancel_link" model="cont.CON731.cancel_change_req" modelaction="execute"/>
        <a:link id="con_repo001_calc_one_time_cashflow_link" model="cont.CON_REPO001.calc_cashflow" modelaction="execute"/>
        <a:link id="con_repo001_calc_repo_date_amount_link" model="cont.CON_REPO001.calc_repo_date_amount" modelaction="execute"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_calculator_update_link_id"
                url="${/request/@context_path}/modules/cont/CON_REPO001/hls_fin_calculator_update_n.lview"/>
        <a:link id="con_update_record_link_id" model="cont.CON_REPO001.save_calc_from_con" modelaction="execute"/>
        <a:link id="con_update_record_link1_id" model="cont.CON_REPO001.con_change_calc_from_con" modelaction="execute"/>
        <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"/>

        <script type="text/javascript"><![CDATA[
        var calc_flag = false ,manual_calc_flag = false;
        // Leaf.onReady(function() {
        //     var ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_BASE_01', 'con_contract');
        //     if ($(ds_id)) {
        //         $(ds_id).setQueryParameter('contract_id',${/parameter/@contract_id});
        //         $(ds_id).query();
        //     }
        // });
       /* function open_contract_win(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['function_code'] = 'CON301';
            param['function_usage'] = 'QUERY';
            param['download'] = 'Y';
            param['maintain_type'] = 'UPDATE';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_modify_link', ds_id);
        }*/

        // //保存submitsuccess调用
        window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function(ds, record, res, bp_seq) {

            //window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
           // alert(11111);
            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        };
        //新增和加载时调用form
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
            if('${/parameter/@function_code}'=='CON_REPO001D') {

                var repurchase_types = record.get('repurchase_types');
                if (repurchase_types == 'ONE_TIME_REPURCHASE') {
                    record.set('payment_period', 1);
                    record.getField('payment_period').setReadOnly(true);
                    record.getField('price_list').setReadOnly(true);
                    record.getField('price_list_n').setReadOnly(true);
                } else {
                    record.getField('payment_period').setReadOnly(false);
                    record.getField('price_list').setReadOnly(false);
                    record.getField('price_list_n').setReadOnly(false);

                }
                // if (record.get('depoist_offset_flag')) {
                //     if (record.get('depoist_offset_flag') == 'Y') {
                //         record.getField('depoist_remaining_amount').setReadOnly(false);
                //     } else if (record.get('depoist_offset_flag') == 'N') {
                //         record.getField('depoist_remaining_amount').setReadOnly(true);
                //     }
                // }
            }
			  //add by lihh 20210401 原合同剩余应收金额取值
            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);
            }

        };
        function compareDate(start, end) {
            if (start > end) {
                return false;
            }
            return true;
        };
        /*保存前调用*/
        window['${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function (ds, record) {
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'con_contract');
                var req_record = $(req_ds_id).getAt(0);
                var repurchase_date = Leaf.formatDate(req_record.get('repurchase_date'));
                var paymengt_deadlinedate = Leaf.formatDate(req_record.get('paymengt_deadlinedate'));
            var repurchase_types = record.get('repurchase_types');
            var payment_period = record.get('payment_period');
			//add by 26887cz 2021-08-13
            var create_date = Leaf.formatDate(new Date());
            var last_rent_due_date = Leaf.formatDate(req_record.get('last_rent_due_date'));
            if (!compareDate(last_rent_due_date, create_date)) {
                Leaf.showMessage('${l:HLS.PROMPT}', '申请创建日期小于变更起始期前期租金支付约定日，请先取消变更，进行收入和增值税确认！');
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                return false;
            }
                //支付预定日需要大于解约回购日
                if (!compareDate(repurchase_date, paymengt_deadlinedate)) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '支付预定日需要大于等于解约回购日！');
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    return false;
                }
            if (repurchase_types == 'STAGE_REPURCHASE') {
                if (payment_period<2) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '回购类型为分期回购时，支付期数需大于1期');
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    return false;
                }
            }
            //return true;
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        };



        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
           debugger;
            if(value!=old_value){
                record.set('offset_flag', 'N');
            }
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var head_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_BASE_01', 'con_contract');
            var ds_id2 = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_QUOTATION_02', 'con_contract');
            var ds_id3 = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_QUOTATION_01', 'con_contract');
            // 回购价款总额 = 逾期租金 + 逾期罚息+ 剩余本金 + 留购价 + 手续费 + 资金占用费-保证金余额(抵扣情况下)
            // sum_overdue_amount+due_amount+sum_unreceived_principal+residual_value+repurchase_service_charges+fund_possession_cost
            // 回购价款计算基数 = 回购价款总额
            if (ds == $(ds_id)) {
                var repurchase_types = record.get('repurchase_types');
                // if (name != 'repurchase_types_n' && name != 'payment_frequency' && name != 'payment_frequency_n') {
                //     if (repurchase_types == null || repurchase_types == undefined) {
                //         Leaf.showMessage('${l:HLS.PROMPT}', '请先维护基本信息中的回购类型！');
                //         return;
                //     }
                // }
                if (name =='repurchase_types'&&value == 'ONE_TIME_REPURCHASE') {
                    record.getField('payment_period').setReadOnly(true);
                    record.set('payment_period', 1);
                    record.getField('price_list').setReadOnly(true);
                    record.getField('price_list_n').setReadOnly(true);
                    // 分期回购
                } else if (name =='repurchase_types'&&value == 'STAGE_REPURCHASE') {
                    record.getField('payment_period').setReadOnly(false);
                    record.getField('price_list').setReadOnly(false);
                    record.getField('price_list_n').setReadOnly(false);
                }
                var depoist_remaining_amount=0;
                // if (record.get('depoist_offset_flag') == 'Y') {
                //     depoist_remaining_amount = record.get('depoist_remaining_amount') || 0;
                // } else {
                //     depoist_remaining_amount = 0 * 1;
                // }
                // if (name == 'depoist_offset_flag' && value) {
                //     var repurchase_tatal_amount=record.get('repurchase_tatal_amount') || 0;
                //     var temp_amount= record.get('depoist_remaining_amount') || 0;
                //     if(value=='Y'){
                //         record.getField('depoist_remaining_amount').setReadOnly(false);
                //         record.set('depoist_remaining_amount', 0);
                //         record.set('repurchase_tatal_amount', minus(repurchase_tatal_amount,temp_amount));
                //         record.set('repurchase_count_amount', minus(repurchase_tatal_amount,temp_amount));
                //     }else{
                //         record.getField('depoist_remaining_amount').setReadOnly(true);
                //         record.set('depoist_remaining_amount', 0);
                //         record.set('repurchase_tatal_amount', minus(plus(repurchase_tatal_amount,temp_amount),0));
                //         record.set('repurchase_count_amount', minus(plus(repurchase_tatal_amount,temp_amount),0));
                //     }
                // }
                // //保证金余额(抵扣情况下)
                // if (name == 'depoist_remaining_amount') {
                //
                //
                //     if (value < 0 || value == NaN || value == undefined) {
                //         Leaf.showMessage('${l:HLS.PROMPT}', '保证金抵扣金额应大于等于0！');
                //         setTimeout(function () {
                //             record.set('depoist_remaining_amount', 0);
                //         }, 5);
                //         return;
                //     }
                //     var repurchase_tatal_amount=record.get('repurchase_tatal_amount') || 0;
                //     var deposit_left= record.get('deposit_left') || 0;
                //     if(record.get('depoist_offset_flag')=='Y'){
                //         if (value>deposit_left){
                //             Leaf.showMessage('${l:HLS.PROMPT}', '保证金抵扣金额不能大于合同剩余保证金余额！');
                //             setTimeout(function () {
                //                 record.set('depoist_remaining_amount', 0);
                //             }, 5);
                //             return;
                //         }else{
                //             record.set('repurchase_tatal_amount', minus(plus(repurchase_tatal_amount,old_value||0),value));
                //             record.set('repurchase_count_amount', minus(plus(repurchase_tatal_amount,old_value||0),value));
                //         }
                //
                //     }
                //     else if(record.get('depoist_offset_flag')=='N'){
                //         null;
                //     }
                // else{
                //         Leaf.showMessage('${l:HLS.PROMPT}', '请先选择保证金是否抵扣！');
                //         setTimeout(function () {
                //             record.set('depoist_remaining_amount', 0);
                //         }, 5);
                //         return;
                //     }
                // }
                //逾期罚息
                if (name == 'ccr_due_amount') {
                    var due_amount = record.get('due_amount') || 0;
                    if (due_amount < value) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '调整后的罚息必须小于等于逾期罚息！');
                        setTimeout(function () {
                            record.set('ccr_due_amount', 0);
                        }, 5);
                        return;
                    }
                    // if ( value == NaN || value == undefined) {
                    //     Leaf.showMessage('${l:HLS.PROMPT}', '调整后的罚息金额应大于等于0！');
                    //     setTimeout(function () {
                    //         record.set('ccr_due_amount', 0);
                    //     }, 5);
                    //     return;
                    // }
                    //var new_ccr_due_amount=minus(value,old_value||0);
                    // var repurchase_count_amount = plus(plus(plus(record.get('sum_overdue_amount') || 0, new_ccr_due_amount || 0), record.get('sum_unreceived_principal') || 0)
                    //     , record.get('residual_value') || 0);
                    var repurchase_count_amount = plus(plus(record.get('sum_overdue_amount') , record.get('sum_unreceived_principal') || 0)
                        , record.get('residual_value') || 0);
                    var repurchase_tatal_amount = plus(plus(repurchase_count_amount, record.get('repurchase_service_charges') || 0), record.get('fund_possession_cost') || 0);
                    repurchase_tatal_amount=plus(repurchase_tatal_amount,value||0);
                    record.set('repurchase_tatal_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                    record.set('repurchase_count_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                }
                // 手续费
                if (name == 'repurchase_service_charges'&&value>=0) {
                    var repurchase_count_amount = plus(plus(plus(record.get('sum_overdue_amount') || 0, record.get('ccr_due_amount') || 0), record.get('sum_unreceived_principal') || 0)
                        , record.get('residual_value') || 0);
                    var repurchase_tatal_amount = plus(plus(repurchase_count_amount, value || 0), record.get('fund_possession_cost') || 0);
                    record.set('repurchase_tatal_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                    record.set('repurchase_count_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                }
                // 资金占用费value
                if (name == 'fund_possession_cost'&&value>=0) {
                    var repurchase_count_amount = plus(plus(plus(record.get('sum_overdue_amount') || 0, record.get('ccr_due_amount') || 0), record.get('sum_unreceived_principal') || 0)
                        , record.get('residual_value') || 0);
                    var repurchase_tatal_amount = plus(plus(repurchase_count_amount, record.get('repurchase_service_charges') || 0), value || 0);
                    record.set('repurchase_tatal_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                    record.set('repurchase_count_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                }
                //逾期租金
                if (name == 'sum_overdue_amount'&&value) {
                    var repurchase_count_amount = plus(plus(plus(value || 0, record.get('ccr_due_amount') || 0), record.get('sum_unreceived_principal') || 0)
                        , record.get('residual_value') || 0);
                    var repurchase_tatal_amount = plus(plus(repurchase_count_amount, record.get('repurchase_service_charges') || 0), record.get('fund_possession_cost') || 0);
                    record.set('repurchase_tatal_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                    record.set('repurchase_count_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                }
                //剩余本金
                if (name == 'sum_unreceived_principal'&&value) {
                    var repurchase_count_amount = plus(plus(plus(record.get('sum_overdue_amount') || 0, record.get('ccr_due_amount') || 0), value || 0)
                        , record.get('residual_value') || 0);
                    var repurchase_tatal_amount = plus(plus(repurchase_count_amount, record.get('repurchase_service_charges') || 0), record.get('fund_possession_cost') || 0);
                    record.set('repurchase_tatal_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                    record.set('repurchase_count_amount', minus(repurchase_tatal_amount, depoist_remaining_amount));
                }
                if (name == 'repurchase_date' && value) {
                    debugger;
                    Leaf.request({
                        url: $('con_repo001_calc_repo_date_amount_link').getUrl(),
                        para: {
                            contract_id: record.get('contract_id'),
                            repurchase_date: value
                        },
                        success: function (res) {
						  //add by lihh 20210329原合同应收剩余金额取值
							var rec_residue_amount;
                            record.set('last_rent_due_date', res.result.last_rent_due_date);
                            record.set('sum_received_rent_amount', res.result.sum_received_rent_amount || 0);
                            record.set('sum_unreceived_rent_amount', res.result.sum_unreceived_rent_amount || 0);
                            record.set('sum_overdue_amount', res.result.sum_overdue_amount || 0);
                            record.set('sum_unreceived_principal', res.result.sum_unreceived_principal || 0);
                            record.set('due_amount', res.result.due_amount || 0);
                            record.set('ccr_due_amount', res.result.due_amount || 0);
                            record.set('offset_flag', 'N');
							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 || 0);
                            //record.set('fund_possession_cost', res.result.fund_possession_cost || 0);
                        },
                        failure: function () {
                            record.set('last_rent_due_date', '');
                            record.set('repurchase_date', '');
                            record.set('sum_received_rent_amount', '');
                            record.set('sum_unreceived_rent_amount', '');
                            record.set('sum_overdue_amount', '');
                            record.set('sum_unreceived_principal', '');
                            record.set('due_amount', '');
                            record.set('ccr_due_amount', '');
                           // record.set('fund_possession_cost', 0);
                        },
                        error: function () {
                            record.set('repurchase_date', '');
                            record.set('last_rent_due_date', '');
                            record.set('sum_received_rent_amount', '');
                            record.set('sum_unreceived_rent_amount', '');
                            record.set('sum_overdue_amount', '');
                            record.set('sum_unreceived_principal', '');
                            record.set('due_amount', '');
                            record.set('ccr_due_amount', '');
                           // record.set('fund_possession_cost', 0);
                        },
                        scope: this
                    });
                }

            }


        };

        window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
           // window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            debugger;
               // var req_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASE_01', 'con_contract');
            var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'con_contract');
			 var req_reason_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'con_contract_change_req');
            var req_record = $(req_ds_id).getCurrentRecord();
                var case_type = '';
                var document_type = '${/parameter/@document_type}';
                var calc_session_id = req_record.get('calc_session_id');
                //计算标志
                var offset_flag=req_record.get('offset_flag');
            if (req_record.dirty == true||$(req_reason_ds_id).getCurrentRecord().dirty == true) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                return false;
            }
            if (offset_flag!=='Y') {
                Leaf.showMessage('${l:HLS.PROMPT}', '请先成功计算报价！');
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                return false;
            }
                if ($(req_ds_id).validate($('${/parameter/@layout_code}_submit_approval').enable())) {
                    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 () {
            var req_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASE_01', 'con_contract');
            var req_record = $(req_ds_id).getAt(0);
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            Leaf.request({
                url: $('con_repo_submit_link').getUrl(),
                para: {
                    change_req_id:' ${/parameter/@change_req_id}',
                    layout_code: '${/parameter/@layout_code}'
                },
                success: function(res) {
                    $('${/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();
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                failure: function() {
                    $('${/parameter/@layout_code}_submit_approval').enable();
                    $('${/parameter/@layout_code}_save').enable();
                    $('${/parameter/@layout_code}_user_button1').enable();
                    $('${/parameter/@layout_code}_user_button3').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();
                    $('${/parameter/@layout_code}_user_button1').enable();
                    $('${/parameter/@layout_code}_user_button3').enable();
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                scope: this
            });
            });
        }

        //报价计算
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            debugger;
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var ds_id_head = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'con_contract');
            var cashflow_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_cashflow');
            var record = $(ds_id_head).getCurrentRecord();
            var price_list = record.get('price_list');
                var calc_session_id = record.get('calc_session_id');
                var parent_pk_value = record.get('contract_id');
                var calc_type = '${/parameter/@calc_type}' || 'CLASSIC_CALCULATOR';
               if (record.dirty == true) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                   window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                   return false;
               }
               if($(ds_id_head).validate()){
                   if(record.get('repurchase_types') == 'ONE_TIME_REPURCHASE'){
                       Leaf.request({
                           url: $('con_repo001_calc_one_time_cashflow_link').getUrl(),
                           para: {
                               contract_id: record.get('contract_id'),
                           },
                           success: function(res) {
                               calc_flag = true;
                               Leaf.SideBar.enable = true;
                               Leaf.SideBar.show({msg: '计算成功!',duration: 2000});
                               var ca_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'G_QUOTATION_04', 'con_contract_cashflow');
                               // if (ca_ds_id) {
                               //     $(ca_ds_id).query();
                               // }
                               $(cashflow_ds_id).query();
                               $(ds_id_head).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
                       });
                   }else {
                       Leaf.request({
                           url: $('con_update_record_link1_id').getUrl(),
                           para: {
                               'contract_id': record.get('contract_id')
                           },
                           success: function(res) {
                               debugger;
                               window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                               if (calc_session_id) {
                                   //直接进入报价页面
                                   var win = new Leaf.Window({
                                       id: 'hls_fin_calc_quotation_update_link_winid',
                                       params: {
                                           document_id: parent_pk_value,
                                           price_list: price_list,
                                           document_category: 'CONTRACT',
                                           contract_status:record.get('contract_status'),
                                           maintain_type: 'MODIFY',
                                           calc_session_id: record.get('calc_session_id'),
                                           quotation_id: record.get('quotation_id'),
                                           dsId: cashflow_ds_id,
                                           winId: 'hls_fin_calc_quotation_update_link_winid',
                                           global_flag: 'Y',
                                           id_num: 1,
                                           calc_type: calc_type,
                                           recreate_H_formula: 'N',
                                           recreate_L_formula: 'N'
                                       },
                                       url: $('${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_calculator_update_link_id').getUrl(),
                                       fullScreen: true,
                                       draggable: true
                                   });
                                   win.on('close', function () {
                                       window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                       if(cashflow_ds_id&&ds_id_head){
                                       $(cashflow_ds_id).query();
                                       $(ds_id_head).query();}
                                   });

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

               }


        };
        //取消变更
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
           // window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
           // $('${/parameter/@layout_code}_user_button3').disable(); //按钮不可用
            Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认取消变更？', function() {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('con_repo001_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
                });
            });
        };
        window['${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function (ds, qpara, bp_seq) {

        };
        //图片渲染
        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"/>';
                }
            }
        };
        //查询时调用(grid,table,gridBox)
      /*  window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) {
            var ds_us_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'F_BASE_03', 'hls_document_use_seal');
            if (ds == $(ds_us_id)) {
                ds.setQueryParameter('document_table','CON_CONTRACT_CHANGE_REQ');
                ds.setQueryParameter('change_req_id','${/parameter/@change_req_id}');
                ds.query();
            }
        };*/
      //add  by  lijingjing

        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}', '请先保存!');
            }
        }
        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_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('.PDF') >= 0) {
                            //     url = url + '<a href=javascript:view_pdf(\'' + temp[1] + '\')>' + temp[0] + '</a>' + ',';
                            // } //else if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {

                           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;
                }
            }
        };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>