<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei5743  
    $Date: 2014-10-8 下午3:16:19  
    $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="get_special_fields_link_id" model="cont.CON500.con_contract_get_special_fields" modelaction="update"/>
        <script src="${/request/@context_path}/modules/prj/PRJ500N/javascripts/input_validator.js" type="text/javascript"/>
        <script type="text/javascript"><![CDATA[
   			//保存前调用,生成项目编号  // 确定保存开始校验
            window['${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function(ds, record) {
                if (record.get('project_number')) {
                    return true;
                }
                Leaf.request({
                    url: $('get_special_fields_link_id').getUrl(),
                    para: {
                        document_category: '${/parameter/@document_category}',
                        document_type: '${/parameter/@document_type}',
                        function_code: '${/parameter/@function_code}',
                        function_usage: '${/parameter/@function_usage}'
                    },
                    success: function(res) {
                        var document_number = res.result.document_number;
                        record.set('project_number', document_number);
                        record.set('document_category', '${/parameter/@document_category}');
                        check_flag = true;
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    sync: true,
                    scope: this
                });
                return check_flag;
            };
            
            function prj500n_card_id_check(record,name,value){
                if (!value){
                    return '身份证号不能为空';
                }else{
                    if(!checkCard(value)){
                        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((ds.id).indexOf('prj_project_bp')!=-1 && (ds.id).indexOf('prj_project_bp_contact_info')==-1){
            	    ds.fields.id_card_no.pro.validator = prj500n_card_id_check;
            	    ds.fields.id_no_sp.pro.validator = prj500n_card_id_check;
            	}
            };
            //加载时调用(grid,table,gridBox)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
            	//如果存在的话,进行校验逻辑  排除掉联系人校验
            	if((ds.id).indexOf('prj_project_bp')!=-1 && (ds.id).indexOf('prj_project_bp_contact_info')==-1){
            	    ds.fields.id_card_no.pro.validator = prj500n_card_id_check;
            	    if (ds.fields.id_no_sp){
            	        ds.fields.id_no_sp.pro.validator = prj500n_card_id_check;
            	    }
            	}
            };
            //新增时调用(grid,table,gridBox)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_add'] = function(ds, record, config_records, bp_seq) {
            	if((ds.id).indexOf('prj_project_bp')!=-1 && (ds.id).indexOf('prj_project_bp_contact_info')==-1){
            	    ds.fields.id_card_no.pro.validator = prj500n_card_id_check;
            	    if (ds.fields.id_no_sp){
            	        ds.fields.id_no_sp.pro.validator = prj500n_card_id_check;
            	    }
            	    
            	}
            };
            
            
            
            
            /* 		    //window['${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq){
			//申请人业务逻辑,更新时调用
			//if(ds.id==ds_id){
               
                //申请人配偶身份证校验

               	if(name == 'id_no_sp'&&!Ext.isEmpty(value)){
                    var card_type_sp = record.get('card_type_sp');
                    if(card_type_sp == 'ID_CARD'){
                        if (!checkCard(value)) {
                            Leaf.showMessage('提示', '申请人配偶信息中,请输入正确格式的身份证!');
                            return false;
                        }
                    }
                    if (value.length == 18 && card_type_sp == 'ID_CARD') {
                        record.set('date_of_birth_sp', new Date(value.substr(6, 4) + '/' + value.substr(10, 2) + '/' + value.substr(12, 2)));
                        record.set('age_sp', new Date().getFullYear() - value.substr(6, 4));
                        if (value.substr(16, 1) % 2 == 1) {
                            record.set('gender_sp', 'MALE');
                            record.set('gender_sp_n', '男');
                        } else if (value.substr(16, 1) % 2 == 0) {
                            record.set('gender_sp', 'FEMALE');
                            record.set('gender_sp_n', '女');
                        }
                        gender=record.get('gender');
                        gender_sp=record.get('gender_sp');
                        if(gender==gender_sp){
                            Leaf.showMessage('提示', '申请人和申请人配偶的性别不能相同!');
                            record.set('gender_sp_n','');
                            record.set('date_of_birth_sp','');
                            record.set('age_sp','');
                            record.set('id_no_sp','');
                            return false;
                        }
                    }
                }
                //申请人配偶手机校验
                if(name == 'cell_phone_sp'){
                    if(!checkMobile(value)){
                        Leaf.showMessage('提示', '申请人配偶信息中,请输入正确格式的手机号码!');
                        return false;
                    }
                    if(record.get('cell_phone')==record.get('cell_phone_sp')){
                        Leaf.showMessage('提示', '申请人和申请人配偶的手机号不能相同!');
                        return false;
                    }
                }
                        	}  
        	if(ds.id==bp_gur_np_ds_id){
        	    //担保人身份证校验
                if(name == 'id_card_no'){
                    var id_type_g = record.get('id_type');
                    if(id_type_g == 'ID_CARD'){
                        if (!checkCard(value)) {
                            Leaf.showMessage('提示', '担保人信息中,请输入正确格式的身份证!');
                            return false;
                        }
                        if(record.get('id_card_no')==$(ds_id).getAt(0).get('id_card_no')){
                            Leaf.showMessage('提示', '申请人和担保人的身份证不能相同!');
                            record.set('id_card_no','');
                            record.set('gender','');
                            record.set('date_of_birth','');
                            record.set('age','');
                            return false;
                        }
                    }
                    if (value.length == 18 && id_type_g == 'ID_CARD') {
                        record.set('date_of_birth', new Date(value.substr(6, 4) + '/' + value.substr(10, 2) + '/' + value.substr(12, 2)));
                        record.set('age', new Date().getFullYear() - value.substr(6, 4));
                        if (value.substr(16, 1) % 2 == 1) {
                            record.set('gender', 'MALE');
                            record.set('gender_n', '男');
                        } else if (value.substr(16, 1) % 2 == 0) {
                            record.set('gender', 'FEMALE');
                            record.set('gender_n', '女');
                        }
                    }
                }
                //担保人手机校验
                if(name == 'cell_phone'){
                    if(!checkMobile(value)){
                        Leaf.showMessage('提示', '担保人信息中,请输入正确格式的手机号码!');
                        return false;
                    }
                    if(record.get('cell_phone')==$(ds_id).getAt(0).get('cell_phone')){
                        Leaf.showMessage('提示', '申请人和担保人的手机号不能相同!');
                        return false;
                    }
                }
        	}
        	
		};
		
		function id_card_no_validate(record,name,value){

		    if(name == 'id_card_no'){
                var id_type_s = record.get('id_type');
                if(id_type_s == 'ID_CARD'){
                    if (!checkCard(value)) {
                        Leaf.showMessage('提示', '申请人信息中,请输入正确格式的身份证!');
                        return  '申请人信息中,请输入正确格式的身份证!';
                    }
                }
                if (value.length == 18 && id_type_s == 'ID_CARD') {
                    record.set('date_of_birth', new Date(value.substr(6, 4) + '/' + value.substr(10, 2) + '/' + value.substr(12, 2)));
                    record.set('age', new Date().getFullYear() - value.substr(6, 4));
                    if (value.substr(16, 1) % 2 == 1) {
                        record.set('gender', 'MALE');
                        record.set('gender_n', '男');
                    } else if (value.substr(16, 1) % 2 == 0) {
                        record.set('gender', 'FEMALE');
                        record.set('gender_n', '女');
                    }
                }
            }
			return true;
		}
		
		
		//申请人业务逻辑,保存前调用
		window['${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function(ds, record){
		    window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
		    var ds1 = $('${/parameter/@layout_code}_BP_INFO_prj_project_bp_ds');
		    var ds1Record = ds1.getCurrentRecord();
                if (ds1Record) {
                    //申请人身份证校验
                    if (!Leaf.isEmpty(ds1Record.get('id_card_no'))) {
                        if (ds1Record.get('id_type') == 'ID_CARD') {
                            if (!checkCard(ds1Record.get('id_card_no'))) {
                                Leaf.showMessage('提示', '申请人信息中,请输入正确格式的身份证!');
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                return false;
                            }
                        }
                    }
                    //申请人手机校验
                    if (!Leaf.isEmpty(ds1Record.get('cell_phone'))) {
                        if (!checkMobile(ds1Record.get('cell_phone'))) {
                            Leaf.showMessage('提示', '申请人信息中,请输入正确格式的手机号码!');
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            return false;
                        }
                    }
                    //申请人配偶身份证校验
                    if (!Leaf.isEmpty(ds1Record.get('id_no_sp'))) {
                        if (ds1Record.get('card_type_sp') == 'ID_CARD') {
                            if (!checkCard(ds1Record.get('id_no_sp'))) {
                                Leaf.showMessage('提示', '配偶信息中,请输入正确格式的身份证!');
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                return false;
                            }
                        }
                    }
                }
                if (record.get('project_number')) {
                    return true;
                }
                Leaf.request({
                    url: $('get_special_fields_link_id').getUrl(),
                    para: {
                        document_category: '${/parameter/@document_category}',
                        document_type: '${/parameter/@document_type}',
                        function_code: '${/parameter/@function_code}',
                        function_usage: '${/parameter/@function_usage}'
                    },
                    success: function(res) {
                        var document_number = res.result.document_number;
                        record.set('project_number', document_number);
                        record.set('document_category', '${/parameter/@document_category}');
                        check_flag = true;
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    sync: true,
                    scope: this
                });
                return check_flag;
                
		}; */
            
   		]]></script>
    </a:view>
</a:screen>