<?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:init-procedure>
        <a:model-query defaultWhereClause="t1.contract_id=${/parameter/@contract_id}" model="cont.CON501N.con_contract_return_flag" rootPath="rerurn_flag_path"/>
    </a:init-procedure>
    <a:view>
        <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="hls_bp_master_modify_link" url="${/request/@context_path}/modules/hls/HLS215N/hls_bp_master_query.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}/modules/cont/CON501N/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_uploadFile_rd_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_ln_gps_send_link" url="${/request/@context_path}/modules/gps/con_contract_ln_gps_send.lsc"/>
        <a:link id="con_contract_zr_gps_send_link" url="${/request/@context_path}/modules/gps/con_contract_zr_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"/> -->
        <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}_on_layout_dynamic_before_submit'] = function(ds, record) {
            //
            // window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            // var check_flag = true;
            // //车辆二手车 车架号校验
            // var ds2 = $('${/parameter/@layout_code}_G_ASSET_con_contract_lease_item_ds');
            // var ds2Record = ds2.getCurrentRecord();
            // if (ds2Record) {
            // if (!Leaf.isEmpty(ds2Record.get('item_frame_number'))) {
            // if (!Leaf.isEmpty(ds2Record.get('item_frame_number'))) {
            // if (!checkVumber(ds2Record.get('item_frame_number'))) {
            // Leaf.showMessage('提示', '二手车信息中,请输入正确格式的车架号!');
            // window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            // return false;
            // }
            // }
            // }
            // }
            // return check_flag;
            // };
            
            
            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 == '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') {
                    //
                    //var contract_id = ${/parameter/@contract_id};
                    //alert(contract_id);
                    if ('${/model/rerurn_flag_path/record/@rerurn_flag}' == 'Y') {
                        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 ('${/model/rerurn_flag_path/record/@rerurn_flag}' == 'N') {
                        link_function = '${/parameter/@layout_code}_prj500_cdd_attachtment_rd_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;
                }
            };
            //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}', '请先保存!');
                }
            };
            
            //link4
            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}_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') {
                        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}_prj500_cdd_attachtment_rd_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') {
                        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_rd_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 = {};
                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['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, 'hls_bp_master_modify_link', null, '${/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
                var root_ds = $('${/parameter/@layout_code}_virtual_ds');
                if($(ds_id).validate()){
                	root_ds.submit();
	                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() {
	
	                    });
	                } else {
	                    Leaf.showErrorMessage('错误', '请先点击保存生成合同编号!');
	                }
                }else{
                    Leaf.showMessage('提示','请先正确填写信息!');
                }
            };
            // 合同文本查看
            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 ast_car_gps_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'ast_car_gps');
                var contract_id = $(ds_id).getCurrentRecord().get('contract_id');
                var gps_record = $(ast_car_gps_id).getCurrentRecord();
                var gps_provider = gps_record.get('gps_provider');
                if (gps_record.dirty) {
                    Leaf.showMessage('${l:PROMPT}', '请先保存数据!');
                    return;
                }
                Leaf.showConfirm('提示', '是否确认发送GPS安装请求?', function() {
                    zjwfl5110_approvePage_mask();
                    var url, gps_type, params = {};
                    params['contract_id'] = contract_id;
                    if (gps_provider == 'LN') {
                        url = $('con_contract_ln_gps_send_link').getUrl();
                        params['gps_type'] = 'LN_NEW_GPS'
                    } else if (gps_provider == 'MSD') {
                        url = $('con_contract_gps_send_link').getUrl();
                        params['gps_type'] = 'NEW_GPS'
                    } else if (gps_provider == 'ZR') {
                        url = $('con_contract_zr_gps_send_link').getUrl();
                        params['gps_type'] = 'ZR_NEW_GPS'
                    }else {
                        Leaf.showMessage('${l:PROMPT}', '没有对应的GPS厂商接口!');
                        zjwfl5110_approvePage_noMask();
                        return;
                    }
                    Leaf.request({
                        url: url,
                        para: params,
                        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 ast_car_gps_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'ast_car_gps');
                var contract_id = $(ds_id).getCurrentRecord().get('contract_id');
                var gps_record = $(ast_car_gps_id).getCurrentRecord();
                var gps_provider = gps_record.get('gps_provider');
                if (gps_record.dirty) {
                    Leaf.showMessage('${l:PROMPT}', '请先保存数据!');
                    return;
                }
                var win = new Leaf.Window({
                    url: $('con_contract_gps_send_address_win_link').getUrl(),
                    title: '实时定位',
                    params: {
                        contract_id: contract_id,
                        gps_provider: gps_provider,
                        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/@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');
				var lease_fin_info_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
				var ast_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'ast_con_insurance');
				if(ds.id == lease_fin_info_ds_id){

				    var insurance_flag=record.get('insurance_flag');
				    if(insurance_flag=='Y'){
				        var temp=$(ast_id).getAll();
				        if(temp.length == 0){
				            Leaf.showMessage('提示','保险信息不能为空!');
				            check_flag= false;
				        }
				    }
				}
				// 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;
                    // }
            
            
                // }
            
                //资产信息 车架号校验  G_ASSET
                var ds2 = $('${/parameter/@layout_code}_G_ASSET_con_contract_lease_item_ds');
                var ds2Record = ds2.getCurrentRecord();
                if (ds2Record) {
                    if (!Leaf.isEmpty(ds2Record.get('item_frame_number'))) {
                        if (!Leaf.isEmpty(ds2Record.get('item_frame_number'))) {
                            if (!checkVumber(ds2Record.get('item_frame_number'))) {
                                Leaf.showMessage('提示', '请输入正确格式的车架号!');
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                return 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');
                var ast_car_gps_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'ast_car_gps');
                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_lease_item_id) { //车架号唯一性校验
                    if (name == 'item_frame_number') {

                        if (!Ext.isEmpty(value)) {
                            var contract_lease_item_id = record.get('contract_lease_item_id');

                            Leaf.request({
                                url: $('con_item_frame_number_link').getUrl(),
                                para: {
                                    item_frame_number: value,
                                    contract_lease_item_id: contract_lease_item_id
            
                                },
                                success: function(res) {

                                    var number = res.result.number;
                                    if (number > 0) {
                                        Leaf.showErrorMessage('提示', '车架号已存在!');
                                        setTimeout(function() {
                                            record.set('item_frame_number', '');
                                        }, 50);
                                    }
                                },
                                failure: function(res) {},
                                error: function() {},
                                scope: this
                            });

                        }
                    }
            
                } else if (ds.id == con_contract_ds_id) { //当代扣方式为浦发,大额行号必输 //add by Spencer 3893 20160801
                    if (name == 'withhold_way') {
                        if (!Ext.isEmpty(value) && value == 'SPD') {
                            if(record.get('ebank_flag') != 'Y'){
                            	record.set('ebank_flag','Y');
                            }
                            record.getField('dd_remark').setReadOnly(false);
                            record.getField('dd_remark').setRequired(true);
                        } else if (!Ext.isEmpty(value) && value == 'AIP') {
                            if(record.get('ebank_flag') != 'N'){
                            	record.set('ebank_flag','N');
                            }
                            record.set('dd_remark', null);
                            record.getField('dd_remark').setRequired(false);
                            record.getField('dd_remark').setReadOnly(true);
                        }
                    }
                    if(name == 'direct_debit_bank_id'){
                        if(value==389||value==422||value==429){
                            record.getField('withhold_way_n').setReadOnly(true);
                            record.getField('dd_remark').setRequired(false);
                        }else{
                            record.getField('dd_remark').setRequired(true);
                        }
                    }
                    // if(name == 'dd_bank_account_name'){
                        //
                        // var bp_id_tenant_n = record.get('bp_id_tenant_n');
                        // if(value != bp_id_tenant_n&&value){
                            // Leaf.showErrorMessage('提示', '个人客户中,自动扣款账户与主承租人姓名应相同!');
                            // record.set('dd_bank_account_name','');
                        // }
                    // }
                    
                    //此段代码上传生产时,需注释掉 
                   /*  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);
                        }
                    }*/
                }else  if (ds.id == ast_car_gps_ds_id) {
                        if (record.get('gps_provider') == 'ZR') {
                            record.getField('zr_product_id').setRequired(false);
                            record.set('ln_product_code',null);
                            record.getField('ln_product_code').setRequired(false);
                        }else if (record.get('gps_provider') == 'LN') {
                            record.getField('ln_product_code').setRequired(false);
                            record.set('zr_product_id',null);
                            record.getField('zr_product_id').setRequired(false);
                        }else if (record.get('gps_provider') == 'MSD') {
                            record.set('ln_product_code',null);
                            record.getField('ln_product_code').setRequired(false);
                            record.set('zr_product_id',null);
                            record.getField('zr_product_id').setRequired(false);
                        }
                    }
            };
            
            //打包下载
            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;
                }
            }
            
            function dd_bank_account_name_validate(record, name, value) {
                var bp_id_tenant_n = record.get('bp_id_tenant_n');
                var bp_class = record.get('bp_class');
                if(bp_class=='NP'){
	                if(bp_id_tenant_n != value){
	                    Leaf.showErrorMessage('提示', '个人客户中,自动扣款账户与主承租人姓名应相同!');
	                    return;
	                }
                }
                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') {
                        if (ds.fields.dd_bank_account_name) {
                        ds.fields.dd_bank_account_name.pro.validator = dd_bank_account_name_validate;
                    	}
                        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
                        });
                        if(record.get('direct_debit_bank_id')==389||record.get('direct_debit_bank_id')==422||record.get('direct_debit_bank_id')==429){
                            record.getField('withhold_way_n').setReadOnly(true);
                            record.getField('dd_remark').setRequired(false);
                        }else{
                            record.getField('dd_remark').setRequired(true);
                        }
                        record.getField('withhold_way_n').setReadOnly(true);
                        //当代扣方式为浦发,大额行号必输 //add by Spencer 3893 20160801
                        if (record.get('withhold_way') == 'SPD') {
                            if(record.get('ebank_flag') != 'Y'){
                            	record.set('ebank_flag','Y');
                            }
                            record.getField('dd_remark').setRequired(true);
                        } else if (record.get('withhold_way') == 'AIP') {
                            if(record.get('ebank_flag') != 'N'){
                           		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);
                        }*/
                    }else  if (ds.id == '${/parameter/@layout_code}_T_GPS_ast_car_gps') {
                        if (record.get('gps_provider') == 'ZR') {
                            record.getField('zr_product_id').setRequired(true);
                            record.set('ln_product_code',null);
                            record.getField('ln_product_code').setRequired(false);
                        }else if (record.get('gps_provider') == 'LN') {
                            record.getField('ln_product_code').setRequired(true);
                            record.set('zr_product_id',null);
                            record.getField('zr_product_id').setRequired(false);
                        }else if (record.get('gps_provider') == 'MSD') {
                            record.set('ln_product_code',null);
                            record.getField('ln_product_code').setRequired(false);
                            record.set('zr_product_id',null);
                            record.getField('zr_product_id').setRequired(false);
                        }
                    }
                }
                // if (ds.id == '${/parameter/@layout_code}_G_INSURANCE_1_ast_con_insurance_ds') {
                // var contract_id = ${/parameter/@contract_id};
                // Leaf.request({
                // url: $('con_through_flag_link').getUrl(),
                // para: {
                // contract_id: contract_id
                // },
                // success: function(res) {
                // var bp_through_flag = res.result.bp_through_flag;
                // if (bp_through_flag == 'Y') {
                // record.getField('vci_insurance_company').setRequired(true);
                // record.getField('vci_insurance_company_n').setRequired(true);
                // record.getField('commercial_insurance_amount').setRequired(true);
                // record.getField('vci_insurance_number').setRequired(true);
                // record.getField('vci_insurance_date_from').setRequired(true);
                // record.getField('vci_insurance_date_to').setRequired(true);
                // record.getField('vci_place').setRequired(true);
                // record.getField('vci_place_n').setRequired(true);
                // record.getField('tci_insurance_company').setRequired(true);
                // record.getField('tci_insurance_company_n').setRequired(true);
                // record.getField('compulsory_insurance_amount').setRequired(true);
                // record.getField('tci_insurance_number').setRequired(true);
                // record.getField('tci_insurance_date_from').setRequired(true);
                // record.getField('tci_insurance_date_to').setRequired(true);
                // record.getField('tci_place').setRequired(true);
                // record.getField('tci_place_n').setRequired(true);
                // record.getField('travel_tax').setRequired(true);
                // record.getField('pilfer_insurance_amount').setRequired(true);
                // }
                // },
                // failure: function(res) {},
                // error: function() {},
                // scope: this
                // });
                // }
            };
            
            //打包下载
            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>