<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129
    $Date: 2014-8-4 下午03:12:06
    $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 fetchAll="true" model="prj.PRJ500D.user_agent_description" rootPath="user_agent_description"/>
        <a:model-query fetchAll="true" model="hls.HLS214N.hls_bp_master_modify_user" rootPath="modify_user"/>
        <a:model-query model="cont.CON620.get_sys_role" rootPath="role_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="bank_account_num_link" model="hls.HLS214.hls_bp_bank_account_num" modelaction="update"/>
        <a:link id="bp_agent_modify_link" url="${/request/@context_path}/modules/hls/HLS303/bp_agent_create.lview"/>
        <script src="${/request/@context_path}/modules/prj/PRJ500N/javascripts/input_validator.js"
                type="text/javascript"/>
        <a:link id="${/parameter/@layout_code}_downloadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="hls214N_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="hls214N_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="hls214_bp_master_save_link_id" model="hls.HLS214.hls_bp_change_agent" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_signer_create_link_id" model="hls.HLS213.hls_bp_master_signer_create_check"
                modelaction="update"/>
        <a:link id="rsc303_fin_statement_link" url="${/request/@context_path}/modules/rsc/RSC303/rsc_fin_statement_prj_all_query.lview"/>
        <!--        <a:link id="hls214_sap_eai_create_customer_link" url="${/request/@context_path}/modules/interface/INTERFACE_EAI/hls_sap_eai_CrCustomer.lsc"/>-->
        <!--        <a:link id="hls214_sap_eai_create_vender_link" url="${/request/@context_path}/modules/interface/INTERFACE_EAI/hls_sap_eai_CrVender.lsc"/>-->
        <!--        <script src="${/request/@context_path}/javascripts/identity_card_info_query.js"-->
        <!--                type="text/javascript"></script>-->
        <script type="text/javascript"><![CDATA[
        //保存前调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function (ds, record) {

            //     window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            //     var bp_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            //     debugger
            //     var Pattern = /^[A-Za-z]+$/;
            //     var  record=$(bp_ds_id).getCurrentRecord();
            //     var record_name=record.get('extra_nam');
            //     if(record_name=='extra_nam'){
            //
            //         if((!Pattern.test(record_name)||(record_name.length!=3))){
            //             Leaf.showMessage('${l:HLS.PROMPT}', '简称不合规！');
            //             window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            //             return;
            //         }
            //     }
            var bank_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_bank_account');
            var bank_record = $(bank_ds_id).getAll();
            var flag = true;
            if(bank_record.length>0){
                for(var i=0;i<bank_record.length;i++){
                    var full_name=bank_record[i].get('bank_full_name');
                    var branch_name=bank_record[i].get('bank_branch_name');
                    if (!Leaf.isEmpty(bank_record[i].get('bank_full_name'))&&
                        !Leaf.isEmpty(bank_record[i].get('bank_branch_name'))){
                        if(branch_name.indexOf(full_name)==-1){
                            flag = false;
                        }
                    }
                }
            }
            if(flag == false){
                Leaf.showErrorMessage('${l:PROMPT}', '请填写支行全称（例如：上海浦东发展银行外高桥保税区支行）');
                return false;
            }

            var role_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_role');
            var v_primary_flag_count=0;
            var role_records = $(role_ds_id).getAll();
            for (var i = 0;i < role_records.length;i++) {
                if(role_records[i].get('primary_flag') == 'Y'){
                    v_primary_flag_count=v_primary_flag_count+1;
                }

            }
            if(v_primary_flag_count!=1){
                Leaf.showErrorMessage('错误', '一个商业伙伴有且仅有一个主角色！');
                return  false;
            }



            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            var bp_record = $(ds_id).getCurrentRecord();

            var address_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_address');
            var records_addr = $(address_ds_id).getAll();
            //校验银行账户名必须与商业伙伴名称一致 18083 2023/9/5
            var bp_name=bp_record.get('bp_name');
            var bank_flag =true;
            if(bank_record.length>0){
                for(var i=0;i<bank_record.length;i++){
                    if(!Leaf.isEmpty(bank_record[i].get('bank_account_name'))&&bank_record[i].get('bank_account_name')!=bp_name){
                        bank_flag = false;
                    }
                }
            }

            if(bank_flag == false){
                Leaf.showErrorMessage('${l:PROMPT}', '银行账户户名必须与商业伙伴名称一致');
                return false;
            }
            //新增校验，承租人(法人)和担保人(法人)商业伙伴的创建，银行账号信息都是要必填(为电子签约做准备)
            if(bp_record.get('bp_class') == 'ORG'){
                if(bp_record.get('bp_type')=='TENANT' || bp_record.get('bp_type')=='GUTA_ORG'){
                    if(bank_record.length==0){
                        flag=false;
                        if(flag==false){
                            Leaf.showErrorMessage('${l:PROMPT}','请在银行账户信息中维护[银行账号信息]!');
                            return false;
                        }
                    }
                }
            }
            //新增校验，承租人(自然人)商业伙伴创建必须维护居住地址（为电子签约做准备）
            if(bp_record.get('bp_class')=='NP' && bp_record.get('bp_type')=='TENANT'){
                var check_flag=true;
                for(var i=0;i<records_addr.length;i++){
                    if(records_addr[i].get('address_type')=='HOUSE_ADDRESS'){
                        check_flag=true;
                        break;
                    }else {
                        check_flag=false;
                    }
                }
                if(check_flag==false){
                    Leaf.showErrorMessage('${l:PROMPT}','必填项[居住住址]为空,请在地址信息新增！');
                    return false;
                }
            }

            if (bp_record.get('bp_class') == 'NP'){
                //判断户籍地址
                var flag = true;
                if (records_addr.length <=0){
                    Leaf.showErrorMessage('${l:PROMPT}', '自然人必填[通讯地址]和[户籍地址],请在地址信息新增!');
                    return false;
                }else{
                    for(var i=0;i<records_addr.length;i++){
                        if (records_addr[i].get('address_type') == 'HOUSEHOLD_ADDRESS'){
                            flag = true;
                            break;
                        }else{
                            flag = false;
                        }
                    }
                    //判断通讯地址
                    var flag1 = true;
                    for(var i=0;i<records_addr.length;i++){
                        if (records_addr[i].get('address_type') == 'POSTAL_ADDRESS'){
                            flag1 = true;
                            break;
                        }else{
                            flag1 = false;
                        }
                    }
                    if (flag == false || flag1 == false){
                        Leaf.showErrorMessage('${l:PROMPT}', '自然人必填[通讯地址]和[户籍地址],请在地址信息新增!');
                        return  false;
                    }
                }

            }else if (bp_record.get('bp_class') == 'ORG'){
                //判断通讯地址
                var flag1 = true;
                if (records_addr.length <= 0){
                    Leaf.showErrorMessage('${l:PROMPT}', '法人必填[通讯地址],请在地址信息新增!');
                    return  false;
                }else {
                    for(var i=0;i<records_addr.length;i++){
                        if (records_addr[i].get('address_type') == 'POSTAL_ADDRESS'){
                            flag1 = true;
                            break;
                        }else{
                            flag1 = false;
                        }
                    }
                    if (flag1 == false){
                        Leaf.showErrorMessage('${l:PROMPT}', '法人必填[通讯地址],请在地址信息新增!');
                        return  false;
                    }
                }
            }

            if (old_id_card != new_id_card) {
                bp_record.set('id_card_no_change_flag', 'Y');
            } else {
                bp_record.set('id_card_no_change_flag', 'N');
            }


            if (old_bp_name != new_bp_name) {
                bp_record.set('bp_name_change_flag', 'Y');
            } else {
                record.set('bp_name_change_flag', 'N');
            }
            if (bp_record.get('marital_status') && (bp_record.get('marital_status') !== '30' && bp_record.get('marital_status') !== '40')) {
                bp_record.set('bp_name_sp', null);
                bp_record.set('card_type_sp', null);
                bp_record.set('card_type_sp_n', null);
                bp_record.set('id_no_sp', null);
                bp_record.set('date_of_birth_sp', null);
                bp_record.set('cell_phone_sp', null);
                bp_record.set('work_unit_phone_sp', null);
                bp_record.set('work_unit_name_sp', null);
                bp_record.set('work_unit_address_sp', null);
                return true;
            }

            return true;


        };


        function CheckSocialCreditCode(Code) {
            var patrn = /^[0-9A-Z]+$/;
            //18位校验及大写校验
            //去除空格
            Code = Code.trim();
            Code = Code.replace(/[\t\r\f\n\s]*/g,"");
            if ((Code.length != 18) || (patrn.test(Code) == false)) {
                return false;
            } else {
                var Ancode;//统一社会信用代码的每一个值
                var Ancodevalue;//统一社会信用代码每一个值的权重
                var total = 0;
                var weightedfactors = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];//加权因子
                var str = '0123456789ABCDEFGHJKLMNPQRTUWXY';
                //不用I、O、S、V、Z
                for (var i = 0; i < Code.length - 1; i++) {
                    Ancode = Code.substring(i, i + 1);
                    Ancodevalue = str.indexOf(Ancode);
                    total = total + Ancodevalue * weightedfactors[i];
                    //权重与加权因子相乘之和
                }
                var logiccheckcode = 31 - total % 31;

                if (logiccheckcode == 31) {
                    logiccheckcode = 0;
                }
                var Str = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,T,U,W,X,Y";
                var Array_Str = Str.split(',');
                logiccheckcode = Array_Str[logiccheckcode];

                var checkcode = Code.substring(17, 18);
                if (logiccheckcode != checkcode) {
                    return false;
                } else {
                    return true;
                }
            }
        }

        //保存submitsuccess调用
        window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function (ds, record, res, bp_seq) {
            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_cdd_item_doc_ref');
            var bp_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            var records = $(ds_id);
            if (!(records == 'undefined' || records == null)) {
                $(ds_id).query();
            }
            //add by zc
            var signer_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_signer');
            var record = $(bp_ds_id).getCurrentRecord();
            bp_id = prj_check_bp_id(record);
            if (!bp_id) {
                return;
            }
            Leaf.request({
                url: $('${/parameter/@layout_code}_signer_create_link_id').getUrl(),
                para: {
                    bp_id: bp_id
                },
                success: function (res) {
                    $(signer_ds_id).query();
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                failure: function (res) {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                error: function () {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                scope: this
            });
            // 简称校验
            //
            // var Pattern = /^[A-Za-z]+$/;
            //
            // if(record.getField('extra_nam')=='extra_nam'){
            //     if((!Pattern.text(extra_nam)||(extra_nam.length!=3))){
            //         Leaf.showMessage('${l:HLS.PROMPT}', '简称不合规！');
            //         return true;
            //     }
            // }

            // Leaf.request({
            //     url: $('hls214_sap_eai_create_customer_link').getUrl(),
            //     para: {
            //         bp_id: bp_id
            //     },
            //     scope: this,
            //     success: function () {
            //         Leaf.request({
            //             url: $('hls214_sap_eai_create_vender_link').getUrl(),
            //             para: {
            //                 bp_id: bp_id
            //             },
            //             scope: this,
            //             success: function () {
            //                 $(bp_ds_id).query();
            //                 window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //             },
            //             failure: function () {
            //                 window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //             },
            //             error: function () {
            //                 window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //             },
            //             sync: true
            //         });
            //     },
            //     failure: function () {
            //         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //     },
            //     error: function () {
            //         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            //     },
            //     sync: true
            // });
            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        };


        function prj_check_bp_id(record) {
            var bp_id;
            if (record) {
                bp_id = record.get('bp_id');
            }
            if (!bp_id) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                bp_id = '';
            }
            return bp_id;
        }

        //财务报表模板导入
        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();

            bp_id = prj_check_bp_id(record);
            if (!bp_id) {
                return;
            }
            new Leaf.Window({
                id: 'rsc_fin_statement_prj_import_handle_winid',
                url: '${/request/@context_path}/modules/rsc/RSC303/rsc_fin_statement_prj_import_handle.lview',
                params: {
                    bp_id: bp_id,
                    winid: 'rsc_fin_statement_prj_import_handle_winid'
                },
                title: '${l:STATEMENTS_BUSINESS_DATA_IMPORT}',
                width: 950,
                height: 200
            });
        };

        //财务报表模板查看
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            var record = $(ds_id).getCurrentRecord();
            var bp_id = prj_check_bp_id(record);
            if (!bp_id) {
                return;
            }
            new Leaf.Window({
                id: 'rsc_fin_statement_prj_all_query_winid',
                url: '${/request/@context_path}/modules/rsc/RSC303/rsc_fin_statement_prj_all_query.lview',
                params: {
                    bp_id: bp_id,
                    winid: 'rsc_fin_statement_prj_all_query_winid'
                },
                title: '${l:STATEMENTS_BUSINESS_DATA_IMPORT}',
                fullScreen: true,
                draggable: true
            });
        };

        // function fin_institution_code_validate(record, name, value) {
        // if (!value) {
        // return '金融机构代码不能为空';
        // } else {
        // if (value.length != 11) {
        // return '金融机构代码长度必须为11位';
        // }
        // }
        // return true;
        // }

        // function trade_type_code_validate(record, name, value) {
        // var trade_type_code = record.get('trade_type_code');
        // if(!trade_type_code){
        // if(trade_type_code != trade_type_code.toLowerCase()){
        // return '行业分类代码必须为小写字母';
        // }}
        // return true;
        // }

        var old_id_card;
        var new_id_card;
        var old_bp_name;
        var new_bp_name;

        //新增和加载时调用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('hls_bp_master_credit') != -1 && (ds.id).indexOf('F_ORG_CREDIT') != -1) {
            // if (ds.fields.fin_institution_code) {
            // ds.fields.fin_institution_code.pro.validator = fin_institution_code_validate;
            // }
            // if (ds.fields.trade_type_code) {
            // ds.fields.trade_type_code.pro.validator = trade_type_code_validate;
            // }
            // }
            // }
            if ((ds.id).indexOf('hls_bp_master') != -1 && (ds.id).indexOf('F_BASIC') != -1) {

                if(record.get('bp_class') && record.get('bp_class') == 'ORG'){
                    if(record.get('bp_type') == 'TENANT'){
                        record.getField('etp_sts').setRequired(true);
                        //record.getField('credit_code').setRequired(true);
                        record.getField('etp_sts_n').setRequired(true);
                        record.getField('org_type').setRequired(true);
                        record.getField('org_type_n').setRequired(true);
                        record.getField('org_type_sub').setRequired(true);
                        record.getField('org_type_sub_n').setRequired(true);
                        record.getField('enterprise_scale').setRequired(true);
                        record.getField('enterprise_scale_n').setRequired(true);
                        record.getField('due_date').setRequired(true);
                        record.getField('org_unit_property').setRequired(true);
                        record.getField('org_unit_property_n').setRequired(true);
                        //record.getField('industry').setRequired(true);
                        //record.getField('industry_n').setRequired(true);
                        record.getField('industry_a').setRequired(true);
                        record.getField('industry_a_n').setRequired(true);
                        record.getField('industry_b').setRequired(true);
                        record.getField('industry_b_n').setRequired(true);
                        record.getField('industry_c').setRequired(true);
                        record.getField('industry_c_n').setRequired(true);
                        record.getField('industry_d').setRequired(true);
                        record.getField('industry_d_n').setRequired(true);
                        record.getField('nationalities').setRequired(true);
                        record.getField('nationalities_n').setRequired(true);
                    }
                }
                //法人供应商非必填 18083 2022/11/25
                if(record.get('bp_class') == 'ORG' && record.get("bp_type") == 'VENDER'){
                    record.getField('id_card_no_leg').setRequired(false);
                }

                //第三方 证件号非必填 2022年12月29日09:41:15
                if(record.get('bp_class') == 'ORG' && record.get("bp_type") == 'THIRD_PARTY'){
                    record.getField('social_code').setRequired(false);
                }else if(record.get('bp_class') == 'NP' && record.get("bp_type") == 'THIRD_PARTY'){
                    record.getField('id_card_no').setRequired(false);
                }

                var employee_type_id = '${/model/modify_user/record/@employee_type_id}';
                old_bp_name = record.get('bp_name');
                new_bp_name = record.get('bp_name');
                if (record.get('id_type') == 'ID_CARD') {
                    old_id_card = record.get('id_card_no');
                    new_id_card = record.get('id_card_no');
                }

                if (record.get('bp_category') == 'VENDER') {
                    record.getField('unit_id_n').setReadOnly(true);
                    record.getField('unit_id_n').setRequired(false);
                    record.getField('unit_id').setRequired(false);
                } else {
                    if (employee_type_id == '64') {
                        record.getField('unit_id_n').setReadOnly(true);
                        record.getField('unit_id_n').setRequired(false);
                    } else {
                        record.getField('unit_id_n').setReadOnly(true);
                        record.getField('unit_id_n').setRequired(false);
                    }
                }
                if(record.get('bp_class')&&record.get('bp_class')=='NP'){
                    if (record.get('marital_status') && (record.get('marital_status') == '30' || record.get('marital_status') == '40')) {
                        document.getElementById('${/parameter/@layout_code}_F_SPOUSE_1_component_id').style.display = 'block';
                        record.getField('bp_name_sp').setRequired(true);
                        record.getField('card_type_sp').setRequired(true);
                        record.getField('card_type_sp_n').setRequired(true);
                        record.getField('id_no_sp').setRequired(true);
                    } else {
                        document.getElementById('${/parameter/@layout_code}_F_SPOUSE_1_component_id').style.display = 'none';
                    }
                }

            }

        };



        window['${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function (ds, line_record) {
            var dsId = ds.id;
            var base_table_temp = 'hls_bp_master_role_ds';
            if (dsId.substring(dsId.length - base_table_temp.length, dsId.length) == base_table_temp) {
                var record = ds.getCurrentRecord();
                if (record) {
                    record.getField('bp_type_n').setReadOnly(true);
                    record.getField('enabled_flag').setReadOnly(true);
                }
            }
            if (ds.fields.parent_id) {
                record.getField('parent_id_n').setReadOnly(true);
            }
            var role_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_ROLE', 'hls_bp_master_role');
            if("${/model/role_info/record/@role_code}"!="0017"&&"${/model/role_info/record/@role_code}"!="HAND"){
                if(role_ds_id == ds.id){
                    var records = $(ds.id).getAll();
                    for (var i = 0;i < records.length;i++) {
                        records[i].getField('primary_flag').setReadOnly(true);

                    }
                }
            }
            //法人供应商非必填  18083 2022/12/01
            var bp_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC', 'hls_bp_master');
            var sign_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC_SIGNER', 'hls_bp_master_signer');
            var bp_record=$(bp_ds_id).getCurrentRecord();
            if(bp_record.get('bp_class') == 'ORG' && bp_record.get("bp_type") == 'VENDER'){
                if(sign_ds_id == ds.id &&sign_ds_id){
                    var records = $(sign_ds_id).getAll();
                    for (i = 0; i < records.length; i++) {
                        records[i].getField('id_card').setRequired(false);
                    }
                }
            }

        };
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_add'] = function(ds, record, config_records, bp_seq) {
            var role_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_ROLE', 'hls_bp_master_role');
            if("${/model/role_info/record/@role_code}"!="0017"&&"${/model/role_info/record/@role_code}"!="HAND"){
                if(role_ds_id == ds.id){
                    var records = $(ds.id).getAll();
                    for (var i = 0;i < records.length;i++) {
                        records[i].getField('primary_flag').setReadOnly(true);

                    }
                }
            }
            //法人供应商非必填  2022/12/1  18083
            var bp_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC', 'hls_bp_master');
            var sign_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC_SIGNER', 'hls_bp_master_signer');
            var bp_record=$(bp_ds_id).getCurrentRecord();
            if(bp_record.get('bp_class') == 'ORG' && bp_record.get("bp_type") == 'VENDER'){
                if(sign_ds_id == ds.id &&sign_ds_id){
                    var records = $(sign_ds_id).getAll();
                    for (i = 0; i < records.length; i++) {
                        records[i].getField('id_card').setRequired(false);
                    }
                }
            }
        }

        //更新时调用 add by liukang
        //填写银行账号时 允许银行账号相同 但是给一个提示(提示一下而已)
        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');
            var gird_ds_id = 'BP_NP_MODIFY_N_BP_ASSETS01_hls_bp_assets_ds';
            var gird_ds_id2 = 'BP_NP_MODIFY_N_BP_ASSETS04_hls_bp_assets_ds';
            var gird_ds_id3 = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_bank_flow');
            //学历学位校验 add  20230710
            if(name=='academic_background'||name=='degrees') {
                var academic_background = record.get('academic_background');
                var degrees = record.get('degrees');
                if(!Ext.isEmpty(academic_background)&& !Ext.isEmpty(degrees)){
                    if ((academic_background == '1' && degrees != '1'&& degrees != '2'&& degrees != '3') ||
                        (academic_background == '2' && degrees != '4')||
                        ((academic_background == '3'||academic_background == '4'||academic_background == '5'||academic_background == '6'||academic_background == '7'||academic_background == '8') && (degrees != '5'))){
                        Leaf.showMessage('提示', '请正确填写学位和学历');
                        setTimeout(function () {
                            if(name=='academic_background'){
                                record.set('degrees', '');
                                record.set('degrees_n', '');
                            }else if(name=='degrees'){
                                record.set('academic_background', '');
                                record.set('academic_background_n', '');
                            }
                        }, 20);
                        return false;
                    }
                }
            }
            //许可证有效期校验
            if (name == 'due_date') {
                var lastday = new Date('2099-12-31');
                if (value >lastday) {
                    Leaf.showMessage('${l:PROMPT}', '营业许可证到期日最大不得超过2099-12-31');
                    setTimeout(function () {
                        record.set('due_date', '');
                    }, 20);
                }
            }
            if (name == 'due_box') {
                if (value == 'Y') {
                    record.set('due_date', '2099-12-31');
                }else if(value == 'N'){
                    record.set('due_date', '');
                }
            }
            //邮编校验 add by 20230619
            if(name=='zipcode'|| name=='work_unit_zip') {
                value = value.trim();
                value = value.replace(/[\t\r\f\n\s]*/g,"");
                if (!(/^[0-9]{6}$/.test(value)) && value) {
                    Leaf.showMessage('提示', '请正确填写邮编', function () {
                        record.set(name, '');
                    });
                }
            }
            //单位性质和职业校验 20230420
            if (name == 'unit_properties' || name == 'occuption') {
                debugger
                var unit_properties = record.get('unit_properties');
                var occuption = record.get('occuption');
                if (unit_properties == '30' || unit_properties == '40' || unit_properties == '50') {
                    if (occuption == '0' || occuption == 'X') {

                        //当单位性质为“30-外资企业”、“40-个体、私营企业”、“50-其他“时，职业不能为“0-国家机关、党群组织、企业、事业单位负责人”、“X-军人”
                        Leaf.showMessage('提示', '当单位性质为“外资企业”、“个体、私营企业”、“其他“时，职业不能为“国家机关、党群组织、企业、事业单位负责人”、“军人”。', null, 500, 100);
                        if(name == 'unit_properties' ){
                            record.set('occuption','');
                            record.set('occuption_n','');
                        }
                        if(name == 'occuption' ){
                            record.set('unit_properties','');
                            record.set('unit_properties_n','');
                        }
                    }
                }
                debugger;
                if('${/parameter/@function_usage}'=='QUERY'){
                    if(record.get('bp_type') == 'RENTER' || record.get('bp_type') == 'MAN_FACTURER' || record.get('bp_type')=='ASSET_REGULATOR'){
                        record.getField('phone').setRequired(false);
                        record.getField('cell_phone').setRequired(false);
                        record.getField('due_date').setRequired(false);
                        record.getField('registered_place').setRequired(false);
                        record.getField('org_unit_property').setRequired(false);
                        record.getField('org_unit_property_n').setRequired(false);
                    }
                }

            }
            //中征码校验
            if (record.get('bp_class') == 'ORG') {

                //if(record.get('bp_type') == 'TENANT' && name =='credit_code'){
                var credit_code = record.get('credit_code');
                if (!Leaf.isEmpty(credit_code)) {
                    credit_code = credit_code.trim();
                    credit_code = credit_code.replace(/[\t\r\f\n\s]*/g,"");
                    if (credit_code.length == '16'){
                        // if(!(/^[A-Z][A-z0-9]*$/).test(credit_code)){
                        //     Leaf.showMessage('提示', '中征码首字母需要大写');
                        //     window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        //     setTimeout(function () {
                        //         record.set('credit_code', '');
                        //     }, 20);
                        //     return false;
                        //
                        // }else {
                        //     return true;
                        // }
                        let financeCode = new Array(16);
                        for (let i = 0; i < credit_code.length && i < 16; i++) {
                            financeCode[i] = credit_code.charCodeAt(i);
                        }
                        if(!checkDKK(financeCode)){
                            Leaf.showMessage('提示', '中征码错误');
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            setTimeout(function () {
                                record.set('credit_code', '');
                            }, 20);
                            return false;

                        }else {
                            return true;
                        }
                    }else {
                        Leaf.showMessage('提示', '请输入16位中征码');
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        setTimeout(function () {
                            record.set('credit_code', '');
                        }, 20);
                        return false;
                    }
                }
                //}
            }

            if (gird_ds_id == ds.id || gird_ds_id2 == ds.id) {
                if (name == 'relationship_with_bp') {
                    if (value == 'A7501') {
                        record.set('owership', $(f_bp_create_ds_id).getAt(0).get('bp_name'));
                    } else if (value == 'A7502') {
                        record.set('owership', $(f_bp_create_ds_id).getAt(0).get('bp_name_sp'));
                    } else {
                        record.set('owership', '');
                    }
                }
            }
            if (gird_ds_id3 == ds.id) {
                if (name == 'relationship_with_bp') {
                    if (value == 'A7501') {
                        record.set('owner_name', $(f_bp_create_ds_id).getAt(0).get('bp_name'));
                    } else if (value == 'A7502') {
                        record.set('owner_name', $(f_bp_create_ds_id).getAt(0).get('bp_name_sp'));
                    } else {
                        record.set('owner_name', '');
                    }
                }
            }

            var role_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_role');
            if (role_ds == ds.id) {
                var primary_flag = record.get('primary_flag');
                if (primary_flag == 'Y') {
                    var bm_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
                    var bm_record = $(bm_ds_id).getCurrentRecord();
                    bm_record.set('bp_type', record.get('bp_type'));
                    bm_record.set('bp_type_n', record.get('bp_type_n'));
                    bm_record.set('bp_category', record.get('bp_category'));
                    bm_record.set('bp_category_n', record.get('bp_category_n'));
                }

            }

            var hls_bp_master_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            var hls_bank_acc_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_bank_account');
            var hls_bp_master_credit_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_credit');
            var bp_record = $(hls_bp_master_ds_id).getCurrentRecord();
            if ((ds.id).indexOf('hls_bp_master') != -1 && (ds.id).indexOf('F_BASIC') != -1) {

                if (name == 'bp_name') {
                    new_bp_name = record.get('bp_name');
                }

                if (name == 'agent_type') {
                    if (value == 'AGENT_NO_REBATE' || value == 'AGENT_EE') {
                        record.getField('parent_id_n').setReadOnly(false);
                    } else {
                        record.getField('parent_id_n').setReadOnly(true);
                    }
                }
                if (name == 'social_code' && value) {
                    if (!CheckSocialCreditCode(value)) {
                        Leaf.showMessage('提示', '统一社会信用代码有误，请重新输入！');
                        setTimeout(function () {
                            record.set('social_code', '');
                        }, 20);
                        return false;
                    }
                }
            }
            if (ds.id == hls_bp_master_ds_id) {
                if ($L.CmpManager.get(hls_bp_master_ds_id)) {
                    if (name == 'province_id') {
                        record.set('city_sp', '');
                        record.set('city_sp_n', '');
                    }
                }
            }
            if (ds.id == hls_bank_acc_ds_id) {
                var bank_account_num = record.get('bank_account_num');
                if (name == 'bank_account_num') {
                    Leaf.request({
                        url: $('bank_account_num_link').getUrl(),
                        para: {
                            bank_account_num: bank_account_num
                        },
                        success: function (res) {
                            var number = res.result.num;
                            //alert(number);
                            if (number > 0) {
                                Leaf.showMessage('提示', '该银行账号在系统中已存在！');
                            }
                        },
                        failure: function (res) {
                        },
                        error: function () {
                        },
                        scope: this
                    });
                }
            }


            if ((ds.id).indexOf('hls_bp_master') != -1) {
                // //身份证验证
                // if (ds.fields.id_card_no &&  bp_record.get('bp_class') == 'NP' && bp_record.get('id_type') == 'ID_CARD') {

                // ds.fields.id_card_no.pro.validator = id_card_no_validate;
                // ds.fields.id_no_sp.pro.validator = id_card_no_validate;
                // }
                if (name == 'cell_phone' && value) {
                    if (!checkMobile(value)) {
                        Leaf.showMessage('提示', '基本信息中，请输入正确格式的手机号码！');
                        setTimeout(function () {
                            record.set('cell_phone', '');
                        }, 20);
                        return false;
                    }
                }
                if (name == 'leader_mobile_number' && value) {
                    if (!checkMobile(value)) {
                        Leaf.showMessage('提示', '公司负责人中，请输入正确格式的手机号码！');
                        setTimeout(function () {
                            record.set('leader_mobile_number', '');
                        }, 20);
                        return false;
                    }
                }

                var  company_ds_id= get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_company_info');
                if(company_ds_id=ds.id){
                    if (name == 'id_type' && value) {
                        if (value == '110'&&record.get('associate_id_no')) {
                            var associate_id_no =record.get('associate_id_no');
                            if (!checkCard(associate_id_no)) {
                                Leaf.showMessage('提示', '个人身份证号错误！');
                                setTimeout(function () {
                                    record.set('associate_id_no', '');
                                }, 20);
                                return false;
                            } else if (associate_id_no.length == 18) {
                                new_id_card = record.get('associate_id_no');
                                //自动带出籍贯
                                //record.set('resident_addres', get_native_place(value));
                                record.set('date_of_birth', new Date(associate_id_no.substr(6, 4) + '/' + associate_id_no.substr(10, 2) + '/' + associate_id_no.substr(12, 2)));
                                record.set('age', new Date().getFullYear() - associate_id_no.substr(6, 4));
                                if (associate_id_no.substr(16, 1) % 2 == 1) {
                                    record.set('gender', 'MALE');
                                    record.set('gender_n', '男');
                                } else if (associate_id_no.substr(16, 1) % 2 == 0) {
                                    record.set('gender', 'FEMALE');
                                    record.set('gender_n', '女');
                                }

                            }
                        }else if(value == '140'&&record.get('associate_id_no')){
                            //护照
                            var associate_id_no =record.get('associate_id_no');
                            if (!Leaf.isEmpty(associate_id_no)) {
                                associate_id_no = associate_id_no.trim();
                                associate_id_no = associate_id_no.replace(/[\t\r\f\n\s]*/g,"");
                                var sub_no=associate_id_no.substring(0,3);
                                if(!(/^[A-Z]{3}/).test(sub_no)){
                                    Leaf.showMessage('提示', '护照证件号码格式前三位需为国籍代码！');
                                    setTimeout(function () {
                                        record.set('associate_id_no', '');
                                    }, 20);
                                    return false;
                                }
                                if(!(/^[A-Z]{3}.{0,9}$/).test(associate_id_no)){
                                    Leaf.showMessage('提示', '护照格式错误');
                                    setTimeout(function () {
                                        record.set('associate_id_no', '');
                                    }, 20);
                                    return false;
                                }
                            }
                        }else if(value == '210'&&record.get('associate_id_no')){
                            //护照
                            var credit_code =record.get('associate_id_no');
                            if (!Leaf.isEmpty(credit_code)) {
                                credit_code = credit_code.trim();
                                credit_code = credit_code.replace(/[\t\r\f\n\s]*/g,"");
                                if (credit_code.length == '16'){
                                    let financeCode = new Array(16);
                                    for (let i = 0; i < credit_code.length && i < 16; i++) {
                                        financeCode[i] = credit_code.charCodeAt(i);
                                    }
                                    if(!checkDKK(financeCode)){
                                        Leaf.showMessage('提示', '中征码错误');
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                        setTimeout(function () {
                                            record.set('associate_id_no', '');
                                        }, 20);
                                        return false;

                                    }else {
                                        return true;
                                    }
                                }else {
                                    Leaf.showMessage('提示', '请输入16位中征码');
                                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    setTimeout(function () {
                                        record.set('associate_id_no', '');
                                    }, 20);
                                    return false;
                                }
                            }
                        } else if(value == '220'&&record.get('associate_id_no')){
                            //护照
                            var soc_code =record.get('associate_id_no');
                            if (soc_code) {
                                if (!CheckSocialCreditCode(soc_code)) {
                                    Leaf.showMessage('提示', '统一社会信用代码有误，请重新输入！');
                                    setTimeout(function () {
                                        record.set('associate_id_no', '');
                                    }, 20);
                                    // window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    return false;
                                }
                            }
                        }
                    }

                    if (name == 'associate_id_no'&&value) {
                        if (record.get('id_type') == '110') {
                            if (!checkCard(value)) {
                                Leaf.showMessage('${l:HLS.PROMPT}', '个人身份证号错误!');
                                setTimeout(function () {
                                    record.set('associate_id_no', '');
                                }, 20);
                                return false;
                            } else {
                                if (value.length == 18) {
                                    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', '女');
                                    }

                                }
                            }
                        }else if(record.get('id_type') == '140'){
                            //护照
                            if (!Leaf.isEmpty(value)) {
                                value = value.trim();
                                value = value.replace(/[\t\r\f\n\s]*/g,"");
                                var sub_no=value.substring(0,3);
                                if(!(/^[A-Z]{3}/).test(sub_no)){
                                    Leaf.showMessage('提示', '护照证件号码格式前三位需为国籍代码！');
                                    setTimeout(function () {
                                        record.set('associate_id_no', '');
                                    }, 20);
                                    return false;
                                }
                                if(!(/^[A-Z]{3}.{0,9}$/).test(value)){
                                    Leaf.showMessage('提示', '护照格式错误');
                                    setTimeout(function () {
                                        record.set('associate_id_no', '');
                                    }, 20);
                                    return false;
                                }
                            }
                        }else if(record.get('id_type') == '210'&&value){
                            //护照
                            var credit_code =record.get('associate_id_no');
                            if (!Leaf.isEmpty(value)) {
                                value = value.trim();
                                value = value.replace(/[\t\r\f\n\s]*/g,"");
                                if (value.length == '16'){
                                    let financeCode = new Array(16);
                                    for (let i = 0; i < value.length && i < 16; i++) {
                                        financeCode[i] = value.charCodeAt(i);
                                    }
                                    if(!checkDKK(financeCode)){
                                        Leaf.showMessage('提示', '中征码错误');
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                        setTimeout(function () {
                                            record.set('associate_id_no', '');
                                        }, 20);
                                        return false;

                                    }else {
                                        return true;
                                    }
                                }else {
                                    Leaf.showMessage('提示', '请输入16位中征码');
                                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    setTimeout(function () {
                                        record.set('associate_id_no', '');
                                    }, 20);
                                    return false;
                                }
                            }
                        } else if(record.get('id_type') == '220'&&value){
                            //护照
                            var soc_code =record.get('associate_id_no');
                            if (value) {
                                if (!CheckSocialCreditCode(value)) {
                                    Leaf.showMessage('提示', '统一社会信用代码有误，请重新输入！');
                                    setTimeout(function () {
                                        record.set('associate_id_no', '');
                                    }, 20);
                                    // window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    return false;
                                }
                            }
                        }
                    }
                }

                //法人身份证号校验
                if (name == 'id_card_no_leg' && value){
                    var id_card_no_leg = record.get('id_card_no_leg');
                    if (!checkCard(id_card_no_leg)) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '法人代表身份证号格式错误!');
                        setTimeout(function () {
                            record.set('id_card_no_leg', '');
                        }, 20);
                        return false;
                    }
                }

                if (name == 'id_type' && value) {
                    if (value == 'ID_CARD'&&record.get('id_card_no')) {
                        var id_card_no =record.get('id_card_no');
                        if (!checkCard(id_card_no)) {
                            Leaf.showMessage('提示', '基本信息中，请输入正确格式的身份证！');
                            setTimeout(function () {
                                record.set('id_card_no', '');
                            }, 20);
                            return false;
                        } else if (id_card_no.length == 18) {
                            new_id_card = record.get('id_card_no');
                            //自动带出籍贯
                            //record.set('resident_addres', get_native_place(value));
                            record.set('date_of_birth', new Date(id_card_no.substr(6, 4) + '/' + id_card_no.substr(10, 2) + '/' + id_card_no.substr(12, 2)));
                            record.set('age', new Date().getFullYear() - id_card_no.substr(6, 4));
                            if (id_card_no.substr(16, 1) % 2 == 1) {
                                record.set('gender', 'MALE');
                                record.set('gender_n', '男');
                            } else if (id_card_no.substr(16, 1) % 2 == 0) {
                                record.set('gender', 'FEMALE');
                                record.set('gender_n', '女');
                            }

                        }
                    }else if(value == 'PASSPORT'&&record.get('id_card_no')){
                        //护照
                        var id_card_no =record.get('id_card_no');
                        if (!Leaf.isEmpty(id_card_no)) {
                            id_card_no = id_card_no.trim();
                            id_card_no = id_card_no.replace(/[\t\r\f\n\s]*/g,"");
                            var sub_no=id_card_no.substring(0,3);
                            if(!(/^[A-Z]{3}/).test(sub_no)){
                                Leaf.showMessage('提示', '护照证件号码格式前三位需为国籍代码！');
                                setTimeout(function () {
                                    record.set('id_card_no', '');
                                }, 20);
                                return false;
                            }
                            if(!(/^[A-Z]{3}.{0,9}$/).test(id_card_no)){
                                Leaf.showMessage('提示', '护照格式错误');
                                setTimeout(function () {
                                    record.set('id_card_no', '');
                                }, 20);
                                return false;
                            }
                        }
                    }
                }



                if (name == 'id_card_no' && value) {
                    if (record.get('id_type') == 'ID_CARD') {
                        if (!checkCard(value)) {
                            Leaf.showMessage('提示', '基本信息中，请输入正确格式的身份证！');
                            setTimeout(function () {
                                record.set('id_card_no', '');
                            }, 20);
                            return false;
                        } else if (value.length == 18) {
                            new_id_card = record.get('id_card_no');
                            //自动带出籍贯
                            //record.set('resident_addres', get_native_place(value));
                            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', '女');
                            }

                        }
                    }else if(record.get('id_type') == 'PASSPORT'){
                        //护照
                        if (!Leaf.isEmpty(value)) {
                            value = value.trim();
                            value = value.replace(/[\t\r\f\n\s]*/g,"");
                            var sub_no=value.substring(0,3);
                            if(!(/^[A-Z]{3}/).test(sub_no)){
                                Leaf.showMessage('提示', '护照证件号码格式前三位需为国籍代码！');
                                setTimeout(function () {
                                    record.set('id_card_no', '');
                                }, 20);
                                return false;
                            }
                            if(!(/^[A-Z]{3}.{0,9}$/).test(value)){
                                Leaf.showMessage('提示', '护照格式错误');
                                setTimeout(function () {
                                    record.set('id_card_no', '');
                                }, 20);
                                return false;
                            }
                        }
                    }
                }


                if (name == 'card_type_sp' && value) {
                    if (value == 'ID_CARD'&&record.get('id_no_sp')) {
                        var id_no_sp =record.get('id_no_sp');
                        if (!checkCard(id_no_sp)) {
                            Leaf.showMessage('提示', '配偶信息中，请输入正确格式的身份证！');
                            setTimeout(function () {
                                record.set('id_no_sp', '');
                            }, 20);
                            return false;
                        } else if (id_no_sp.length == 18) {
                            new_id_card = record.get('id_no_sp');
                            //自动带出籍贯
                            //record.set('resident_addres', get_native_place(value));
                            record.set('date_of_birth', new Date(id_no_sp.substr(6, 4) + '/' + id_no_sp.substr(10, 2) + '/' + id_no_sp.substr(12, 2)));
                            record.set('age', new Date().getFullYear() - id_no_sp.substr(6, 4));
                            if (id_no_sp.substr(16, 1) % 2 == 1) {
                                record.set('gender', 'MALE');
                                record.set('gender_n', '男');
                            } else if (id_no_sp.substr(16, 1) % 2 == 0) {
                                record.set('gender', 'FEMALE');
                                record.set('gender_n', '女');
                            }

                        }
                    }else if(value == 'PASSPORT'&&record.get('id_no_sp')){
                        //护照
                        var id_no_sp =record.get('id_no_sp');
                        if (!Leaf.isEmpty(id_no_sp)) {
                            id_no_sp = id_no_sp.trim();
                            id_no_sp = id_no_sp.replace(/[\t\r\f\n\s]*/g,"");
                            var sub_no=id_no_sp.substring(0,3);
                            if(!(/^[A-Z]{3}/).test(sub_no)){
                                Leaf.showMessage('提示', '护照证件号码格式前三位需为国籍代码！');
                                setTimeout(function () {
                                    record.set('id_no_sp', '');
                                }, 20);
                                return false;
                            }
                            if(!(/^[A-Z]{3}.{0,9}$/).test(id_no_sp)){
                                Leaf.showMessage('提示', '护照格式错误');
                                setTimeout(function () {
                                    record.set('id_no_sp', '');
                                }, 20);
                                return false;
                            }
                        }
                    }
                }

                if (name == 'id_no_sp' && value) {
                    //
                    if (record.get('card_type_sp') == 'ID_CARD') {
                        if (!checkCard(value)) {
                            Leaf.showMessage('提示', '配偶信息中，请输入正确格式的身份证！');
                            setTimeout(function () {
                                record.set('id_no_sp', '');
                            }, 20);
                            return false;
                        } else if (value.length == 18) {

                            new_id_card = record.get('id_card_no_leg');

                            //record.set('resident_addres_sp', get_native_place(value));
                            record.set('date_of_birth_sp', 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', '女');
                            }*/

                        }
                    }else if(record.get('card_type_sp') == 'PASSPORT'){
                        //护照
                        if (!Leaf.isEmpty(value)) {
                            value = value.trim();
                            value = value.replace(/[\t\r\f\n\s]*/g,"");
                            var sub_no=value.substring(0,3);
                            if(!(/^[A-Z]{3}/).test(sub_no)){
                                Leaf.showMessage('提示', '护照证件号码格式前三位需为国籍代码！');
                                setTimeout(function () {
                                    record.set('id_card_no', '');
                                }, 20);
                                return false;
                            }
                            if(!(/^[A-Z]{3}.{0,9}$/).test(value)){
                                Leaf.showMessage('提示', '配偶护照格式错误');
                                setTimeout(function () {
                                    record.set('id_no_sp', '');
                                }, 20);
                                return false;
                            }
                        }
                    }

                }
                //征信添加限制
                if(name == 'work_status'){
                    //当“就业状况”为“11 国家公务员”、“ 13 专业技术人员”、“ 17 职员”、“ 21 企业管理人员”、“ 24 工人”或“ 91 在职”时，
                    // “单位名称”、“单位性质”、“单位所属行业”、“职业类型 、“职务”、“职称”、“入职年份”、单位地址、“单位所在地邮编”、“单位所在地行政区划”、“单位电话”必填。
                    // 其余情况，这些字段为空只读
                    if(value == '11'||value == '13'||value == '17'||value == '21'||value == '24'||value == '91'){
                        record.getField('work_unit').setReadOnly(false);
                        record.getField('work_unit').setRequired(true);
                        record.getField('unit_properties_n').setReadOnly(false);
                        record.getField('unit_properties_n').setRequired(true);
                        record.getField('occuption_n').setReadOnly(false);
                        record.getField('occuption_n').setRequired(true);
                        record.getField('position_n').setReadOnly(false);
                        record.getField('position_n').setRequired(true);
                        record.getField('positional_titles').setReadOnly(false);
                        record.getField('positional_titles').setRequired(true);
                        record.getField('entry_date').setReadOnly(false);
                        record.getField('entry_date').setRequired(true);
                        record.getField('work_unit_address').setReadOnly(false);
                        record.getField('work_unit_address').setRequired(true);
                        record.getField('work_unit_zip').setReadOnly(false);
                        record.getField('work_unit_zip').setRequired(true);
                        record.getField('work_province_n').setReadOnly(false);
                        record.getField('work_province_n').setRequired(true);
                        record.getField('work_city_n').setReadOnly(false);
                        record.getField('work_city_n').setRequired(true);
                        record.getField('work_district_n').setReadOnly(false);
                        record.getField('work_district_n').setRequired(true);
                        record.getField('work_unit_phone').setReadOnly(false);
                        record.getField('work_unit_phone').setRequired(true);
                        record.getField('industry_a_n').setReadOnly(false);
                        record.getField('industry_a_n').setRequired(true);
                    }else{
                        record.getField('work_unit').setReadOnly(true);
                        record.getField('work_unit').setRequired(false);
                        record.getField('unit_properties_n').setReadOnly(true);
                        record.getField('unit_properties_n').setRequired(false);
                        record.getField('occuption_n').setReadOnly(true);
                        record.getField('occuption_n').setRequired(false);
                        record.getField('position_n').setReadOnly(true);
                        record.getField('position_n').setRequired(false);
                        record.getField('positional_titles').setReadOnly(true);
                        record.getField('positional_titles').setRequired(false);
                        record.getField('entry_date').setReadOnly(true);
                        record.getField('entry_date').setRequired(false);
                        record.getField('work_unit_address').setReadOnly(true);
                        record.getField('work_unit_address').setRequired(false);
                        record.getField('work_unit_zip').setReadOnly(true);
                        record.getField('work_unit_zip').setRequired(false);
                        record.getField('work_province_n').setReadOnly(true);
                        record.getField('work_province_n').setRequired(false);
                        record.getField('work_city_n').setReadOnly(true);
                        record.getField('work_city_n').setRequired(false);
                        record.getField('work_district_n').setReadOnly(true);
                        record.getField('work_district_n').setRequired(false);
                        record.getField('work_unit_phone').setReadOnly(true);
                        record.getField('work_unit_phone').setRequired(false);
                        record.getField('industry_a_n').setReadOnly(true);
                        record.getField('industry_a_n').setRequired(false);

                    }
                }
                //征信add end
            }

            var test_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC', 'hls_bp_master');
            var test_ds_id1 = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_SPOUSE_1', 'hls_bp_master');
            var test_ds_id2 = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_SPOUSE', 'hls_bp_master');

            if (ds.id == f_bp_create_ds_id) {

                var hd_ds = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC', 'hls_bp_master');
                record = $(hd_ds).getCurrentRecord();
                if(record.get('bp_class')=='NP'){
                    if (name == 'marital_status' && value) {

                        if (value == '30' || value == '40') {
                            document.getElementById('${/parameter/@layout_code}_F_SPOUSE_1_component_id').style.display = 'block';
                            record.getField('bp_name_sp').setRequired(true);
                            record.getField('card_type_sp').setRequired(true);
                            record.getField('card_type_sp_n').setRequired(true);
                            record.getField('id_no_sp').setRequired(true);
                            if (!record.get('card_type_sp')) {
                                record.set('card_type_sp', 'ID_CARD');
                                record.set('card_type_sp_n', '身份证');
                            }

                        } else {
                            document.getElementById('${/parameter/@layout_code}_F_SPOUSE_1_component_id').style.display = 'none';
                            record.getField('bp_name_sp').setRequired(false);
                            record.getField('card_type_sp').setRequired(false);
                            record.getField('card_type_sp_n').setRequired(false);
                            record.getField('id_no_sp').setRequired(false);
                            // record.set('bp_name_sp', null);
                            // record.set('card_type_sp', null);
                            // record.set('card_type_sp_n', null);
                            // record.set('id_no_sp', null);
                            // record.set('date_of_birth_sp', null);
                            // record.set('cell_phone_sp', null);
                            // record.set('work_unit_phone_sp', null);
                            // record.set('work_unit_name_sp', null);
                            // record.set('work_unit_address_sp', null);
                        }
                    }
                }
                if (name == 'bp_name'){
                    // alert(record.get('bp_name')+'2222');
                    record.set('invoice_title',record.get('bp_name'));
                }else if (name == 'social_code'){
                    // alert(record.get('social_code')+'2222');
                    record.set('tax_registry_num',record.get('social_code'));
                }
            }
            var role_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master_role');
            if (role_ds == ds.id) {
                var bp_type_flag='N';
                var records = $(ds.id).getAll();
                if("${/model/role_info/record/@role_code}"!="0017"&&"${/model/role_info/record/@role_code}"!="HAND"){
                    if(name=='bp_type'){
                        for (var i = 0;i < records.length;i++) {
                            if(records[i].get('bp_type')=='TENANT'){
                                bp_type_flag='Y';
                            }
                        }
                        if(bp_type_flag=='Y'){
                            for (var i = 0;i < records.length;i++) {
                                if(records[i].get('bp_type')=='TENANT'){
                                    records[i].set('primary_flag','Y')
                                }else{
                                    records[i].set('primary_flag','N')
                                }
                            }
                        }
                    }
                }
            }



        };

        function upload_file(id, name, query_only) {
            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
            if (record.get('check_id')) {
                var url;
                if (query_only == 'Y') {
                    url = $('hls214N_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                } else {
                    url = $('hls214N_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                }

                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'prj500_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });

                win.on('close', function () {
                    record.ds.query();
                });
            } else {
                Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');

            }
        }

        function upload_signer_file(id, name, query_only) {
            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
            if (record.get('hls_bp_signer_id')) {
                var url;
                if (query_only == 'Y') {
                    url = $('hls214N_cdd_downloadFile_id').getUrl() + '?table_name=HLS_BP_MASTER_SIGNER&header_id=' + record.get('hls_bp_signer_id');
                } else {
                    url = $('hls214N_cdd_uploadFile_id').getUrl() + '?table_name=HLS_BP_MASTER_SIGNER&header_id=' + record.get('hls_bp_signer_id');
                }

                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'prj500_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });

                win.on('close', function () {
                    record.ds.query();
                });
            } else {
                Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');

            }
        }
        //超链接渲染
        window['${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record) {
            //
            window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
            if (name == 'attachment') {
                link_function = 'upload_file';
                if (record.get('attach_count') == 0 || !record.get('attach_count')) {
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                } else {
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '(' + record.get('attach_count') + ')' + '</a>';
                }
            } else if (name == 'attach_file_name') {
                if (value != null) {
                    var link = '${/request/@context_path}/atm_download.lsc?attachment_id=';
                    var str = value.split(';;');
                    var url = '';
                    for (var i = 0; i < str.length; i++) {
                        var temp = str[i].split('--');
                        if (!Leaf.isEmpty(temp[0])) {
                            var file_name = temp[0].toUpperCase();
                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_name.indexOf('.PDF') >= 0) {
                                url = url + '<a href=javascript:view_pdf(\'' + temp[1] + '\')>' + temp[0] + '</a>' + ',';
                            } else if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;

                }
            } else if (name == 'description') {
                if (record.get('important_flag') == 'Y') {
                    return '<font color="RED">' + value + '</font>';
                }
                return value;
            } //签约人授权书附件
            else if(name == 'signer_attachment'){
                var signer_link_function = 'upload_signer_file';
                return '<a href="javascript:window[\'' + signer_link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
            }
        };


        //经销商准入
        window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function () {

            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            var record = $(ds_id).getCurrentRecord();
            var agent_instance_status = record.get('agent_instance_status');
            if (agent_instance_status == 'APPROVED') {
                Leaf.showMessage('提示', '该商业伙伴已进行过经销商准入流程，不允许再次操作！');
                return;
            } else if (agent_instance_status == 'APPROVING') {
                Leaf.showMessage('提示', '该商业伙伴已经在准入流程中，不允许再次操作！');
                return;
            } else if (agent_instance_status == 'REJECT') {
                Leaf.showMessage('提示', '该商业伙伴准入流程已被拒绝，不允许再次操作！');
                return;
            }
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            Leaf.request({
                url: $('hls214_bp_master_save_link_id').getUrl(),
                para: {
                    'bp_id': record.get('bp_id')
                },
                success: function (res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    var param = {};
                    param['function_code'] = 'HLS303';
                    param['function_usage'] = 'MODIFY';
                    param['maintain_type'] = 'MODIFY';
                    param['url_title'] = '经销商准入';
                    param['bp_id'] = record.get('bp_id');
                    param['bp_class'] = record.get('bp_class');
                    param['bp_type'] = record.get('bp_type');
                    param['agent_instance_flag'] = 'Y';

                    hls_doc_get_layout_code('${/parameter/@layout_code}_get_layout_code_link_id', param, 'bp_agent_modify_link', ds_id, '${/parameter/@layout_code}');

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


        };
        //add by  zhuxianfei 20180103

        // function id_card_no_validate(record, name, value) {
        // if(name == 'id_card_no' && record.get('id_type') != 'ID_CARD'){
        // return true;
        // }else if(name == 'id_no_sp' && record.get('card_type_sp') != 'ID_CARD'){
        // return true;
        // }
        // if (!checkCard(value)) {
        // Leaf.showMessage('提示', '请输入正确格式的身份证！');
        // return '请输入正确格式的身份证';
        // }
        // if (value.length == 18) {
        // 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;
        // }

        /*Leaf.onReady(init);

        function init() {
            var bp_class = '${/parameter/@bp_class}';
            if (bp_class != 'ORG') {
                var user_button4 = document.getElementById('${/parameter/@layout_code}' + '_user_button4');
                user_button4.style.display = 'none';
            }
        }*/

        //征信 add start 财报查询按钮
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            var bp_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            var record = $(bp_ds_id).getAt(0)
            if (Ext.isEmpty(record.get('bp_code'))) {
                Leaf.showMessage('${l:PROMPT}', '请先保存商业伙伴数据！');
                return;
            }

            new Leaf.Window({
                id: 'rsc303_fin_statement_query',
                url: $('rsc303_fin_statement_link').getUrl(),
                title: '查看财报',
                fullScreen: true,
                params: {
                    bp_id: record.get('bp_id') ,
                    bp_code:record.get('bp_code')
                }

            });
        }

        Leaf.onReady(function () {
            //自然人不展示财报按钮
            if('${/parameter/@bp_class}' == 'NP' &&  document.getElementById('${/parameter/@layout_code}_user_button2') ){
                document.getElementById('${/parameter/@layout_code}_user_button2').style.display = 'none';
            }
        });

        //征信 add end
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
