<?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:view>
        <a:link id="bank_account_num_link" model="hls.HLS214.hls_bp_bank_account_num" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_downloadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <script type="text/javascript"><![CDATA[
            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;
            }
            
            //新增和加载时调用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;
                     }
                 }
            };
            
            
            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);
                }
            };
            
            //更新时调用 add by liukang
            //填写银行账号时 允许银行账号相同 但是给一个提示(提示一下而已)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                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');
                if ((ds.id).indexOf('hls_bp_master') != -1 && (ds.id).indexOf('F_BASIC') != -1) {
                    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 (ds.id == hls_bp_master_credit_ds_id){
                    if (name == 'trade_type_code'){
                        var trade_type_code = record.get('trade_type_code');
                        if(trade_type_code != trade_type_code.toLowerCase()){
	                        record.set('trade_type_code',trade_type_code.toLowerCase());
	                        setTimeout(function() {Leaf.Masker.unmask(Ext.getBody());
                    }, 500);
                        }
                    }
                }
                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
                        });
                    }
                }
            };
            
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record, bp_seq) {
                if (name == 'attachment') {
                    link_function = '${/parameter/@layout_code}_attachtment_upload';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                }
            };
            
            window['${/parameter/@layout_code}_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                if (record.get('bank_account_id')) {
                    var url = $('${/parameter/@layout_code}_downloadFile_id').getUrl() + '?table_name=HLS_BP_MASTER_BANK_ACCOUNT&header_id=' + record.get('bank_account_id');
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: '${/parameter/@layout_code}${/parameter/@tree_code}_uploadFile_screen_id',
                        width: 850,
                        height: 400
                    });
            
                    win.on('close', function() {
                        record.ds.query();
                    });
                }
            };
        ]]></script>
    </a:view>
</a:screen>