<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2014-8-1 下午02:44:52  
    $Revision: 1.0  
    $Purpose: 合同维护
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:view>
        <a:link id="${/parameter/@layout_code}_wfl_prj_project_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="contract_lease_item_maintain_link" url="${/request/@context_path}/modules/cont/CON501N/con_lease_item_maintain.lview"/>
        <a:link id="contract_history_window_link" url="${/request/@context_path}/modules/cont/CON501N/con_document_history_query.lview"/>
        <a:link id="con501_item_detail_maintain" url="${/request/@context_path}/modules/cont/CON501N/con_item_detail_maintain.lview"/>
        <a:link id="con501_hls_bp_master_modify_link" url="${/request/@context_path}/modules/cont/CON501N/hls_bp_master_modify.lview"/>
        <a:link id="${/parameter/@layout_code}_wfl_readonly_pageLink_projectQueryScreen_update_project" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_maintain_readonly.lview"/>
        <a:link id="con501_contract_maintain_flag_update_link" model="cont.CON500.con_contract_maintain_flag_update" modelaction="execute"/>
        <a:link id="con501_contract_maintain_entrance_link" url="${/request/@context_path}/modules/cont/CON501N/con_contract_modify_entrance.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="${/parameter/@layout_code}_prj500_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_con_contract_content_confirm_link_id" url="${/request/@context_path}/modules/cont/CON501N/con_contract_content_confirm.lview"/>
        <a:link id="get_atch_download_link" url="${/request/@context_path}/modules/batch_download/lease_atm_batch_dl.lsc"/>
        <a:link id="con_contract_gps_send_link" url="${/request/@context_path}/modules/gps/con_contract_gps_send.lsc"/>
        <a:link id="con_contract_gps_send_address_win_link" url="${/request/@context_path}/modules/gps/con_contract_gps_send.lview"/>
        <a:link id="get_bp_class_link_id" model="cont.CON500.con_get_bp_class" modelaction="update"/>
        <script src="${/request/@context_path}/modules/prj/PRJ500N/javascripts/input_validator.js" type="text/javascript"/>
        <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="con_item_frame_number_link" model="cont.CON501N.con_item_frame_number" modelaction="execute"/>
        <a:link id="con_item_frame_number_update_link" model="cont.CON501N.con_item_frame_number" modelaction="update"/>
        <a:link id="lease_item_exists_check_link" model="cont.CON501N.is_exists_lease_item" modelaction="query"/>
        <!-- <a:link id="con_through_flag_link" model="cont.CON501N.con_bp_through_flag" modelaction="update"/> -->
        <a:link id="${/parameter/@layout_code}_con_cashflow_wirte_off_detail_link" url="${/request/@context_path}/modules/cont/CON302N/con_cashflow_wirte_off_detail.lview"/>
        <script type="text/javascript"><![CDATA[
            Ext.ux.Lightbox.register('a[ref=img]', true);
            if ('${/parameter/@save_source_type}' == 'JGPS') {
                zjwfl5110_ApproveChecker_add('zjwfl5110_submit', function(type) {
                    var root_ds = $('${/parameter/@layout_code}_virtual_ds');
                    if (type == 'agree') {
                        if (root_ds.validate()) {
                            //提交先保存
                            root_ds.submit();
                            return true;
                        } else {
                            return false;
                        }
                    }
                });
            } else if ('${/parameter/@save_source_type}' == 'CONTRACT_PRINT') {
            
                zjwfl5110_ApproveChecker_add('zjwfl5110_submit', function(type) {
                    var root_ds = $('${/parameter/@layout_code}_virtual_ds');
                    if (type == 'agree') {
                        if (change_flag == 'Y') {
                            Leaf.showErrorMessage('提示', '数据改变,请生成合同文本！');
                            return false;
                        } else {
                            return true;
                        }
                    }
                });
            } else if ('${/parameter/@save_source_type}' == 'FPJY') {
                zjwfl5110_ApproveChecker_add('zjwfl5110_submit', function(type, callback) {
                    if (type == 'agree') {
                        var con_contract_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                        var con_contract_lease_item_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                        var con_contract_record = $(con_contract_id).getCurrentRecord();
                        var con_contract_lease_item_record = $(con_contract_lease_item_id).getCurrentRecord();
                        var invoice_price = con_contract_record.get('invoice_price');
                        var invoice_amt = con_contract_lease_item_record.get('invoice_amt');
                        var division = con_contract_record.get('division');
                        if (division == '00') {
                            if (Ext.isEmpty(invoice_price)) {
                                invoice_price = 0;
                            }
                            if (Ext.isEmpty(invoice_amt)) {
                                invoice_amt = 0;
                            }
                            confirm_message = null;
                            if (invoice_price != invoice_amt) {
                                confirm_message = '车款' + invoice_price + ',车辆发票金额:' + invoice_amt;
                            }
                        }
            
                        return true;
                    } else {
                        return true;
                    }
                });
            }
            
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var contract_id = $(ds_id).getCurrentRecord().get('contract_id');
                new Leaf.Window({
                    id: 'contract_history_window',
                    url: $('contract_history_window_link').getUrl(),
                    params: {
                        contract_id: contract_id
                    },
                    fullScreen: true
                });
            };
            
            window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var contract_id = $(ds_id).getCurrentRecord().get('contract_id');
                Leaf.showConfirm('提示', '您确认已保存？', function() {
                    Leaf.request({
                        url: $('con501_contract_maintain_flag_update_link').getUrl(),
                        para: {
                            contract_id: contract_id
                        },
                        success: function() {
                            Leaf.SideBar.show({
                                msg: '已提交',
                                duration: 2000
                            });
                            $('${/parameter/@winid}').close();
                        },
                        scope: this
                    });
            
                });
            };
            
            // window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
            // if (name == 'car_detail') {
            // return '<a href="javascript:open_contract_window(\'' + record.id + '\',\'' + record.ds.id + '\')">' + config_record.get('prompt') + '</a>';
            // }
            // return value;
            // };
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record, bp_seq) {
                var link_function = '';
                window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
                if (name == '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=='project_number'){
                        return '<a href="javascript:wfl_prj501_grid_update(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
                }else if (name == 'car_detail' && record.get('contract_lease_item_id')) {
                    link_function = '${/parameter/@layout_code}_open_lease_item_detail_window';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + config_record.get('prompt') + '</a>';
                } else if (name == 'attachment') {
                    link_function = '${/parameter/@layout_code}_prj500_cdd_attachtment_upload';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                } else if (name == 'attach_file_name') {
                    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_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                                if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                    url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                                } else {
                                    url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                                }
                            }
                        }
                        return url;
                    }
                } else if (name == 'link1') {
                    link_function = '${/parameter/@layout_code}_ast_con_cdd_attachtment_upload';
                    if (record.get('atm_num1') > 0) {
                        return '<a style="color:red" href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    } else {
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    }
                } else if (name == 'link2') {
                    link_function = '${/parameter/@layout_code}_ast_con_cdd2_attachtment_upload';
                    if (record.get('atm_num2') > 0) {
                        return '<a style="color:red" href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    } else {
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    }
            
                } else if (name == 'link3') {
                    link_function = '${/parameter/@layout_code}_ast_con_cdd3_attachtment_upload';
                    if (record.get('atm_num3') > 0) {
                        return '<a style="color:red" href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    } else {
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    }
                }else if (name == 'gps_attch'){
                    link_function = '${/parameter/@layout_code}_ast_con_cdd4_attachtment_upload';
                    if (record.get('atm_num3') > 0) {
                        return '<a style="color:red" href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    } else {
                        return '<a style="font-weight:bolder;font-size:1.2em" href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    }}
                     else if (name == 'description') {

                    if (record.get('important_flag') == 'Y') {
                        return '<font color="RED">' + value + '</font>';
                    }
                    return value;
                }else if (name == 'reg_attch'){
                    link_function = '${/parameter/@layout_code}_ast_con_cdd5_attachtment_upload';
                    return '<a style="font-weight:bolder;font-size:1.2em" href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                }else if (name == 'received_amount') {
                    link_function = '${/parameter/@layout_code}_received_amount_detail';
                    if (value) {
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + Leaf.formatMoney(value) + '</a>';
                    }
                    return '';
                }
            };

        window['${/parameter/@layout_code}_received_amount_detail'] = function (ds_id, id, name, query_only) {
            var url = $('${/parameter/@layout_code}_con_cashflow_wirte_off_detail_link').getUrl();
            var record = $(ds_id).findById(id);
            if (record) {
                var win = new Leaf.Window({
                    id: 'con_cashflow_wirte_off_detail_window',
                    url: url,
                    params: {
                        cashflow_id: record.get('cashflow_id'),
                        winid: 'con_cashflow_wirte_off_detail_window'
                    },
                    draggable: true,
                    fullScreen: true
                });
            }
        };
            //link1
            window['${/parameter/@layout_code}_ast_con_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                if (record.get('ast_con_car_insurance_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=AST_CON_INSURANCE&header_id=' + record.get('ast_con_car_insurance_id');
                    } else {
                        url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=AST_CON_INSURANCE&header_id=' + record.get('ast_con_car_insurance_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: '${/parameter/@layout_code}${/parameter/@tree_code}_ast_con_cdd_attachtment_upload_id',
                        width: 850,
                        height: 400
                    });
                    // win.on('close', function() {
                    // $(ds_id).query();
                    // });
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                }
            };
            //link2
            window['${/parameter/@layout_code}_ast_con_cdd2_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                if (record.get('ast_con_car_insurance_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=AST_CON_INSURANCE_2&header_id=' + record.get('ast_con_car_insurance_id');
                    } else {
                        url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=AST_CON_INSURANCE_2&header_id=' + record.get('ast_con_car_insurance_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: '${/parameter/@layout_code}${/parameter/@tree_code}_ast_con_cdd2_attachtment_upload_id',
                        width: 850,
                        height: 400
                    });
                    // win.on('close', function() {
                    // $(ds_id).query();
                    // });
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                }
            };
            
            //link3
            window['${/parameter/@layout_code}_ast_con_cdd3_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                if (record.get('ast_con_car_insurance_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=AST_CON_INSURANCE_3&header_id=' + record.get('ast_con_car_insurance_id');
                    } else {
                        url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=AST_CON_INSURANCE_3&header_id=' + record.get('ast_con_car_insurance_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: '${/parameter/@layout_code}${/parameter/@tree_code}_ast_con_cdd3_attachtment_upload_id',
                        width: 850,
                        height: 400
                    });
                    // win.on('close', function(){
                    // $(ds_id).query();
                    // });
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                }
            };
            window['${/parameter/@layout_code}_ast_con_cdd4_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                // if (record.get('con_contract_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CON_CONTRACT&header_id=' + record.get('contract_id');
                    } else {
                        url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CON_CONTRACT&header_id=' + record.get('contract_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: 'gps附件上传',
                        id: '${/parameter/@layout_code}${/parameter/@tree_code}_ast_con_cdd4_attachtment_upload_id',
                        width: 850,
                        height: 400
                    });
                    // win.on('close', function(){
                    // $(ds_id).query();
                    // });
                // } else {
                    // Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                // }
            };
            window['${/parameter/@layout_code}_ast_con_cdd5_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                // if (record.get('con_contract_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CON_CONTRACT_1&header_id=' + record.get('contract_id');
                    } else {
                        url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CON_CONTRACT_1&header_id=' + record.get('contract_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: '登记证书附件上传',
                        id: '${/parameter/@layout_code}${/parameter/@tree_code}_ast_con_cdd5_attachtment_upload_id',
                        width: 850,
                        height: 400
                    });
                    // win.on('close', function(){
                    // $(ds_id).query();
                    // });
                // } else {
                    // Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                // }
            };
            window['${/parameter/@layout_code}_prj500_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                if (record.get('check_id')) {
                    var url;

                    if (query_only == 'Y' || '${/parameter/@download}' =='Y') {
                        url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    } else {
                        url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_cdd_uploadFile_screen_id',
                        width: 850,
                        height: 400
                    });
            
                    win.on('close', function() {
                        record.ds.query();
                    });
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                }
            };
            
            window['${/parameter/@layout_code}_open_lease_item_detail_window'] = function(id, name) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
                var param = record.data;
                param['function_code'] = 'CON501M';
                param['function_usage'] = 'MODIFY';
                param['url_title'] = '租赁物明细维护';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con501_item_detail_maintain', record.ds.id, '${/parameter/@layout_code}');
                // var contract_lease_item_id = record.get('contract_lease_item_id');
                // new Leaf.Window({
                // id: 'contract_lease_item_maintain_window',
                // url: $('contract_lease_item_maintain_link').getUrl(),
                // params: {
                // contract_id:'${/parameter/@contract_id}',
                // contract_lease_item_id: contract_lease_item_id,
                // winid: 'contract_lease_item_maintain_window'
                // },
                // draggable: true,
                // fullScreen: true
                // });
            };
            
            window['${/parameter/@layout_code}_open_bp_detail_window'] = function(id, name) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
                //var param = record.data;
                var param = {};
                param['bp_id'] = record.get('bp_id');
                param['bp_class'] = record.get('bp_class');
                param['bp_category'] = record.get('bp_category');
                param['function_code'] = 'CON501H';
                param['function_usage'] = 'QUERY';
                /* param['function_code'] = 'HLS214D';
                param['function_usage'] = 'QUERY'; */
                param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, 'con501_hls_bp_master_modify_link', null, '${/parameter/@layout_code}');
            };
            
            function wfl_prj501_grid_update(record_id,ds_id) {
                var record = $(ds_id).findById(record_id);
                var param = {};
                param['bp_class'] = record.get('bp_class');
                param['project_id'] = record.get('project_id');
                param['function_code'] = 'PRJ502D';
                param['function_usage'] = 'QUERY';
                param['url_title'] = '租赁申请查询';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}_wfl_readonly_pageLink_projectQueryScreen_update_project',record.ds.id, '${/parameter/@layout_code}');
            }
            
            // function open_contract_window(record_id, ds_id) {
            // var record = $(ds_id).findById(record_id);
            // var param = record.data;
            // var contract_lease_item_id = record.get('contract_lease_item_id');
            // new Leaf.Window({
            // id: 'contract_lease_item_maintain_window',
            // url: $('contract_lease_item_maintain_link').getUrl(),
            // params: {
            // contract_lease_item_id: contract_lease_item_id
            // },
            // fullScreen: true
            // });
            // // param['function_code'] = 'CON501D';
            // // param['function_usage'] = 'MODIFY';
            // // 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);
            // }
            //数据是否发生改变
            var change_flag = 'N';
            //工作流中合同文本生成按钮
            //基本信息tab页 新增必输字段的校验  add by liukang 20160328
            window['${/parameter/@layout_code}_print_layout_dynamic_click'] = function() {

                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var con_lease_item_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                var record = $(ds_id).getCurrentRecord();
                var con_lease_record = $(con_lease_item_id).getCurrentRecord();
                var direct_debit_bank_id = record.get('direct_debit_bank_id');
                var dd_bank_account_name = record.get('dd_bank_account_name');
                var dd_bank_account_num = record.get('dd_bank_account_num');
                var color_of_apprearance = con_lease_record.get('color_of_apprearance');
                var item_frame_number = con_lease_record.get('item_frame_number');
                var item_engine_number = con_lease_record.get('item_engine_number');
                var license_number = con_lease_record.get('license_number');
                /* if (Ext.isEmpty(direct_debit_bank_id)) {
                 Leaf.showMessage('${l:HLS.PROMPT}', '请先填写数据并保存!');
                 } else */
                if (!Ext.isEmpty(record.get('contract_number'))) {
                    var win = new Leaf.Window({
                        id: '${/parameter/@layout_code}_con_contract_content_confirm_win_id',
                        params: {
                            contract_id: record.get('contract_id'),
                            company_id: record.get('company_id'),
                            document_category: record.get('document_category'),
                            business_type: record.get('business_type'),
                            winid: '${/parameter/@layout_code}_con_contract_content_confirm_win_id',
                            change_flag: change_flag,
                            contract_name: record.get('contract_name'),
                            contract_number: record.get('contract_number')
                        },
                        url: $('${/parameter/@layout_code}_con_contract_content_confirm_link_id').getUrl(),
                        title: '合同文本生成',
                        width: 1300,
                        height: 550
                    });
                    //在关闭页面之后,刷新一下ds
                    win.on('close', function() {
                        if (ds_id) {
                            $(ds_id).query();
                        }
                    });
                } else {
                    Leaf.showErrorMessage('错误', '请先点击保存生成合同编号！');
                }
            };
            // 合同文本查看
            window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var con_lease_item_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                var record = $(ds_id).getCurrentRecord();
                //var con_lease_record = $(con_lease_item_id).getCurrentRecord();
                var direct_debit_bank_id = record.get('direct_debit_bank_id');
                var dd_bank_account_name = record.get('dd_bank_account_name');
                var dd_bank_account_num = record.get('dd_bank_account_num');
                // var color_of_apprearance = con_lease_record.get('color_of_apprearance');
                // var item_frame_number = con_lease_record.get('item_frame_number');
                // var item_engine_number = con_lease_record.get('item_engine_number');
                // var license_number = con_lease_record.get('license_number');
                /* if (Ext.isEmpty(direct_debit_bank_id)) {
                 Leaf.showMessage('${l:HLS.PROMPT}', '请先填写数据并保存!');
                 } else  */
                if (!Ext.isEmpty(record.get('contract_number'))) {
                    new Leaf.Window({
                        id: '${/parameter/@layout_code}_con_contract_content_confirm_win_id',
                        params: {
                            action: 'VIEW',
                            contract_id: record.get('contract_id'),
                            company_id: record.get('company_id'),
                            document_category: record.get('document_category'),
                            business_type: record.get('business_type'),
                            winid: '${/parameter/@layout_code}_con_contract_content_confirm_win_id'
            
                        },
                        url: $('${/parameter/@layout_code}_con_contract_content_confirm_link_id').getUrl(),
                        title: '合同查看',
                        width: 1300,
                        height: 550
                    });
                } else {
                    Leaf.showErrorMessage('错误', '请先点击保存生成合同编号！');
                }
            };
            
            window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var contract_id = $(ds_id).getCurrentRecord().get('contract_id');
                Leaf.showConfirm('提示', '是否确认发送GPS安装请求？', function() {
                    zjwfl5110_approvePage_mask();
                    Leaf.request({
                        url: $('con_contract_gps_send_link').getUrl(),
                        para: {
                            contract_id: contract_id,
                            gps_type: 'NEW_GPS'
                        },
                        success: function(res) {
                            Leaf.SideBar.show({
                                msg: '发送成功！',
                                duration: 2000
                            });
                            zjwfl5110_approvePage_noMask();
                        },
                        failure: function(res) {
                            zjwfl5110_approvePage_noMask();
                        },
                        error: function() {
                            zjwfl5110_approvePage_noMask();
                        },
                        scope: this
                    });
            
                });
            };
            
            window['${/parameter/@layout_code}_user_button5_layout_dynamic_click'] = function() {
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var contract_id = $(ds_id).getCurrentRecord().get('contract_id');
                var win = new Leaf.Window({
                    url: $('con_contract_gps_send_address_win_link').getUrl(),
                    title: '实时定位',
                    params: {
                        contract_id: contract_id,
                        winid: '${/parameter/@layout_code}_con_contract_gps_send_address_win_link_winid'
                    },
                    id: '${/parameter/@layout_code}_con_contract_gps_send_address_win_link_winid',
                    width: 600,
                    height: 400
                });
            };
            
            //打包下载
            window['${/parameter/@layout_code}_user_button9_layout_dynamic_click'] = function() {
                //
                var con_contract_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var con_contract_record = $(con_contract_id).getAt(0);
                var con_contract = con_contract_record.get('contract_id');
                var url_l = $('get_atch_download_link').getUrl() + '?table_pk_value=' + con_contract + '&table_name=CON_CONTRACT' + '&doc_code=' + con_contract + '&all_flag=Y';
                window.open(href = url_l, target = "_self");
            };
            
            //保存前调用
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function(ds, record) {
                //
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                //var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                // var con_lease_item_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                // var record_ds = $(ds_id).getCurrentRecord();
                //var con_lease_record = $(con_lease_item_id).getCurrentRecord();
                var check_flag = true;
                var con_contract_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                if (ds.id = con_contract_id) {
                    var contract_id = record.get('contract_id');
                    var bp_id_tenant_n = record.get('bp_id_tenant_n');
                    var dd_bank_account_name = record.get('dd_bank_account_name');
                    var bp_class = record.get('bp_class');
                    if (bp_class == 'NP' && bp_id_tenant_n != dd_bank_account_name) {
                        Leaf.showErrorMessage('提示', '个人客户中，自动扣款账户与主承租人姓名应相同！');
                        setTimeout(function() {
                            record.set('dd_bank_account_name', '');
                        }, 50);
                        check_flag = false;
                    }
            
            
                }
            
            
                if (record.dirty) {
                    change_flag = 'Y';
                }
            
                return check_flag;
            };
            
            //加载时调用(grid,table,gridBox)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
                var con_contract_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var con_contract_lease_item_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                if (ds.id == con_contract_lease_item_ds_id) {
                    var division = $(con_contract_ds_id).getCurrentRecord().get('division');
                    if (division == '01') {
                        record.getField('item_frame_number').setReadOnly(true);
                    }
                    //车架号校验
                    /* if (ds.fields.item_frame_number) {
                        ds.fields.item_frame_number.pro.validator = item_no_validator;
                    } */
                }
            };
            
            //更新时调用
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                var ast_con_insurance_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'ast_con_insurance');
                //资产信息
                var con_contract_lease_item_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                //add by Spencer 3893 20160801
                var con_contract_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                if (ds.id == ast_con_insurance_ds_id) {
            
                    if ($L.CmpManager.get(ast_con_insurance_ds_id)) {
                        if (name == 'vci_insurance_date_from') {
                            var date = new Date(value);
                            date.setFullYear(date.getFullYear() + 1);
                            record.set('vci_insurance_date_to', date);
                        } else if (name == 'tci_insurance_date_from') {
                            var date = new Date(value);
                            date.setFullYear(date.getFullYear() + 1);
                            record.set('tci_insurance_date_to', date);
                        }
                    }
                } else if (ds.id == con_contract_ds_id) { //当代扣方式为浦发，大额行号必输 //add by Spencer 3893 20160801
                    if (name == 'withhold_way') {
                        if (!Ext.isEmpty(value) && value == 'SPD') {
                            record.set('ebank_flag', 'Y');
                            record.getField('dd_remark').setReadOnly(false);
                            record.getField('dd_remark').setRequired(true);
                        } else if (!Ext.isEmpty(value) && value == 'AIP') {
                            record.set('ebank_flag', 'N');
                            record.set('dd_remark', null);
                            record.getField('dd_remark').setRequired(false);
                            record.getField('dd_remark').setReadOnly(true);
                        }
                    }
                    //此段代码上传生产时，需注释掉
                    if (name == 'ebank_province_d') {
                        if (record.get('ebank_province_d') == '110000' || record.get('ebank_province_d') == '120000' || record.get('ebank_province_d') == '500000' || record.get('ebank_province_d') == '310000') {
                            record.set('ebank_city_n', null);
                            record.set('ebank_city', null);
                            record.set('dd_remark', null);
                            record.getField('ebank_city_n').setReadOnly(true);
                            record.getField('ebank_city_n').setRequired(false);
                            record.getField('dd_remark').setReadOnly(true);
                            record.getField('dd_remark').setRequired(false);
                        } else {
                            record.getField('ebank_city_n').setReadOnly(false);
                            record.getField('ebank_city_n').setRequired(true);
                            record.getField('dd_remark').setReadOnly(false);
                            record.getField('dd_remark').setRequired(true);
                        }
                    }
                }
            };
            
            //打包下载
            window['${/parameter/@layout_code}_C_ATTCH_USER_BUTTON1_layout_dynamic_tab_click'] = function() {
                //
                var con_contract_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var con_contract_record = $(con_contract_id).getAt(0);
                var con_contract = con_contract_record.get('contract_id');
                var url_l = $('get_atch_download_link').getUrl() + '?table_pk_value=' + con_contract + '&table_name=CON_CONTRACT' + '&doc_code=' + con_contract + '&all_flag=Y';
                window.open(href = url_l, target = "_self");
            };
            
            function item_no_validator(record, name, value) {
                var count = 0;
                if (value) { //进行校验
                    Leaf.request({
                        url: $('lease_item_exists_check_link').getUrl(),
                        para: {
                            item_frame_number: value
                        },
                        success: function(res) {
                            count = res.result.record.v_count;
            
                        },
                        failure: function() {
            
                           },
                        error: function() {
            
                           },
                        scope: this,
                        sync: true
                    });
                } else {
                    return true;
                }
                if (count == 0) {
                    return '此车架号不在库存中，请检查库存';
                } else {
                    return true;
                }
            }
            
            //新增和加载时调用(form)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
                if ('${/parameter/@layout_code}' == 'CONTRACT_MODIFY') {
                    if (ds.id == '${/parameter/@layout_code}_F_BASIC_con_contract_ds') {
                        var bp_id_tenant = record.get('bp_id_tenant');
                        Leaf.request({
                            url: $('get_bp_class_link_id').getUrl(),
                            para: {
                                bp_id_tenant: bp_id_tenant
                            },
                            success: function(res) {
                                var bp_class_flag = res.result.bp_class_flag;
                                //alert(bp_class_flag);
                                if (bp_class_flag == 'NP') {
                                    record.set('ebank_account_prop', '20');
                                    record.set('ebank_account_prop_n', '个人账户');
                                    record.getField('ebank_account_prop').setReadOnly(true);
                                    record.getField('ebank_account_prop_n').setReadOnly(true);
                                }
                            },
                            failure: function() {
            
                               },
                            error: function() {
            
                               },
                            scope: this
                        });
            
                        //当代扣方式为浦发，大额行号必输 //add by Spencer 3893 20160801
                        if (record.get('withhold_way') == 'SPD') {
                            record.set('ebank_flag', 'Y');
                            record.getField('dd_remark').setRequired(true);
                        } else if (record.get('withhold_way') == 'AIP') {
                            record.set('ebank_flag', 'N');
                            record.getField('dd_remark').setReadOnly(true);
                        }
                        //此段代码上传生产时，需注释掉
                        if (record.get('ebank_province_d') == '110000' || record.get('ebank_province_d') == '120000' || record.get('ebank_province_d') == '500000' || record.get('ebank_province_d') == '310000') {
                            record.getField('ebank_city_n').setReadOnly(true);
                            record.getField('ebank_city_n').setRequired(false);
                            record.getField('dd_remark').setReadOnly(true);
                            record.getField('dd_remark').setRequired(false);
                        } else {
                            record.getField('ebank_city_n').setReadOnly(false);
                            record.getField('ebank_city_n').setRequired(true);
                            record.getField('dd_remark').setReadOnly(false);
                            record.getField('dd_remark').setRequired(true);
                        }
                    }
            
                }
            
            };
            
            //打包下载
            window['${/parameter/@layout_code}_ACY_USER_BUTTON1_layout_dynamic_tab_click'] = function() {
                //
                // var prj_project_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
                // var prj_project_record = $(prj_project_id).getAt(0);
                //var project_id = prj_project_record.get('project_id');
                var prj_cdd_item_check_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_cdd_item_check');
                var record = $(prj_cdd_item_check_id).getAt(0);
                var check_id = record.get('check_id');
                var url_l = $('get_atch_download_link').getUrl() + '?table_pk_value=' + project_id + '&table_name=PRJ_CDD_ITEM_CHECK' + '&doc_code=' + check_id + '&all_flag=Y';
                window.open(href = url_l, target = "_self");
            };
            
            
            //合同确认及打印 维护GPS信息时只允许一条记录
            //新增时调用(grid,table,gridBox)   check_after_save_bm
            // window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_add'] = function(ds, record, config_records, bp_seq) {
            //
            // if (ds.id == '${/parameter/@layout_code}_GPS_AST_ast_car_gps_ds') {
            // var records = ds.getAll();
            // var num = records.length;
            // if (num >= 2) {
            // Leaf.showErrorMessage('提示', 'GPS信息只允许维护一条信息!');
            // return;
            // }
            // }
            // };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
