<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129
    $Date: 2014-8-29 下午03:53:38
    $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 model="cont.CON620.get_sys_role" rootPath="role_info"/>
        <a:model-query defaultWhereClause="t1.user_id=${/session/@user_id}" model="hls.HLS214N.sys_user_lv" rootPath="user_name_path"/>
		<a:model-query defaultWhereClause="t.user_id=${/session/@user_id}" model="hls.HLS214N.sys_division" rootPath="user_division"/>
        <a:model-query model="hls.HLS213N.bp_agent_second_lease" rootPath="second_lease_flag"/>
    </a:init-procedure>
    <a:view>
        <a:link id="hls_bp_master_link" url="${/request/@context_path}/modules/hls/HLS213N/hls_bp_master_create.lview"/>
		<a:link id="hls_bp_op_master_link" url="${/request/@context_path}/modules/hls/HLS213N/hls_bp_master_op_create.lview"/>
        <a:link id="get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                    var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
                    var record = $(ds_id).getCurrentRecord();
                if ($(ds_id).validate()) {
                        if(record.get('bp_type')=='THIRD_PARTY'){
                            record.set('function_code', 'HLS213D_N');
                            record.set('function_usage', 'CREATE');
                            record.set('default_value_dsid', ds_id);
                            record.data['url_title'] = '商业伙伴创建';
                            var param = record.data;
                            hls_doc_get_layout_code('get_layout_code_link_id', param, 'hls_bp_master_link', null, '${/parameter/@layout_code}');

                        }else if(record.get('bp_type')=='RENTER' || record.get('bp_type')=='MAN_FACTURER' || record.get('bp_type')=='ASSET_REGULATOR'){
                    record.set('function_code','HLS213OP');
                    record.set('function_usage','CREATE');
                    record.set('default_value_dsid',ds_id);
                    record.data['url_title'] ='商业伙伴创建'
                    var param=record.data;
                    hls_doc_get_layout_code('get_layout_code_link_id',param,'hls_bp_op_master_link',null,'${/parameter/@layout_code}');
                }else{
                   if(record.get('bp_class')=='NP' &&record.get('bp_type')=='VENDER' &&'${/model/second_lease_flag/record/@second_lease_flag}'=='Y'){
                         record.set('function_code', 'HLS213VE');
                         record.set('function_usage', 'CREATE');
                         record.set('default_value_dsid', ds_id);
                         record.data['url_title'] = '商业伙伴创建';
                         var param = record.data;
                         hls_doc_get_layout_code('get_layout_code_link_id', param, 'hls_bp_master_link', null, '${/parameter/@layout_code}');

                   }else{
                        record.set('function_code', 'HLS213D');
                        record.set('function_usage', 'CREATE');
                        record.set('default_value_dsid', ds_id);
                        record.data['url_title'] = '商业伙伴创建';
                        var param = record.data;
                        hls_doc_get_layout_code('get_layout_code_link_id', param, 'hls_bp_master_link', null, '${/parameter/@layout_code}');
                          }
                        }
                   }
            };
            //更新时调用
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq){
                var f_bp_create_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
                if(f_bp_create_ds_id==ds.id){
                    if(name=='bp_type' && "${/model/user_division/record/@division}"!='95'){
                        //deron 将承租人与经销商分开录入，没有供应商
                        // if(value=='AGENT' || value=='GUTA_ORG' || value=='VENDER'){
                        if(value=='GUTA_ORG'){
                            record.set('bp_class','ORG');
                            record.set('bp_class_n','法人');
                            record.getField('bp_class_n').setReadOnly(true);
                        }
                        else if(value=='GUTA_NP'){
                            record.set('bp_class','NP');
                            record.set('bp_class_n','自然人');
                            record.getField('bp_class_n').setReadOnly(true);
                        }
                        else if(value=='TENANT'){
                            record.getField('bp_class_n').setReadOnly(false);
                        }else if(value=='MAN_FACTURER' || value=='RENTER' || value=='ASSET_REGULATOR'){
                        record.set('bp_class','ORG');
                        record.set('bp_class_n','法人');
                        record.getField('bp_class').setReadOnly(true);
                        record.getField('bp_class_n').setReadOnly(true);
                    } else{
                            record.getField('bp_class_n').setReadOnly(false);
                        }
                    }
					if(name=='bp_type' && "${/model/user_division/record/@division}"=='95'){
                    if(value=='MAN_FACTURER' || value =='RENTER' || value=='ASSET_REGULATOR'){
                        record.set('bp_class','ORG');
                        record.set('bp_class_n','法人');
                        record.getField('bp_class').setReadOnly(true);
                        record.getField('bp_class_n').setReadOnly(true);
                    }else if(value=='GUTA_ORG'){
                        record.set('bp_class','ORG');
                        record.set('bp_class_n','法人');
                        record.getField('bp_class_n').setReadOnly(true);
                    }else if(value=='GUTA_NP'){
                        record.set('bp_class','NP');
                        record.set('bp_class_n','自然人');
                        record.getField('bp_class_n').setReadOnly(true);
                    }else {
                        record.getField('bp_class').setReadOnly(false);
                        record.getField('bp_class_n').setReadOnly(false);
                    }
                }
              }
            };

        window['${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
            var bp_create_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            if(ds.id == bp_create_ds_id) {
                var r = $(bp_create_ds_id).getCurrentRecord();
                if (!r.get('bp_category')) {
                    if("${/model/user_name_path/record/@user_name}"=="DSF001"||"${/model/user_name_path/record/@user_name}"=="DSF002"){
                        r.set('bp_category', 'THIRD_PARTY');
                        r.set('bp_category_n', '第三方');
                    }else if("${/model/user_division/record/@division}"=='95'){
                        r.set('bp_category','RENTER');
                        r.set('bp_category_n','租赁商');
                    }else{
                        r.set('bp_category', 'TENANT');
                        r.set('bp_category_n', '承租人');
                    }

                }

            if("${/model/user_name_path/record/@user_name}"=="DSF001"||"${/model/user_name_path/record/@user_name}"=="DSF002"){
                r.set('bp_type','THIRD_PARTY');
                r.set('bp_type_n', '第三方');
            }else{
                r.set('bp_type','TENANT') ;
                r.set('bp_type_n', '承租人');
            }
			if("${/model/user_division/record/@division}"=='95'){
                    r.set('bp_type','RENTER');
                    r.set('bp_type_n','租赁商');
                    r.set('bp_class','ORG');
                    r.set('bp_class_n','法人');
                    r.getField('bp_class').setReadOnly(true);
                    r.getField('bp_class_n').setReadOnly(true);
                }else{
                    r.set('bp_type','TENANT') ;
                    r.set('bp_type_n', '承租人');
                }
        }
        };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
