<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: nyl  
    $Date: 2014-8-4 下午01:58:31  
    $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="ins_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="bpQueryScreen_welcome" url="${/request/@context_path}/welcome.lview"/>
        <a:link id="ins_claims_create_link_id" model="ins.INS505.ins_cashflow_create" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
            //更新时调用
            window['${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'ins_insurance_policy');
                var claims_policy_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'cla_insurance_claims_policy');
                var records = $(ds_id).getAll();
                var param = records[0].data;
            
                if (name == 'policy_id' && ds.id == ds_id) {
            
                    var claims_record = $(claims_policy_ds_id).getAll()[0];
                    claims_record.set('policy_id', param['policy_id']);
            
                }
            };
            
            //保存submitsuccess调用
            window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function(ds, record, res, bp_seq) {
                var ds_id_1 = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'cla_insurance_claims_policy');
                $(ds_id_1).query();
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            };
            
            //生成理赔现金流
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'cla_insurance_claims_policy');
            	// $(ds_id).query();
                var records = $(ds_id).getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请选择数据');
                    return;
                }
                var param = new Object();
                var datas = [];
                for (var i = 0;i < records.length;i++) {
                    var record = records[i];
                    var claims_amount = record.get('claims_amount') == undefined ? 0 : record.get('claims_amount');
                    if (!record.get('contract_id')) {
                        Leaf.showMessage('${l:PROMPT}', '未创建合同,不能生成现金流!');
                        return;
                    }
                    
                    if (claims_amount <= 0) {
                        Leaf.showMessage('${l:PROMPT}', '理赔金额为维护或为零,不能生成现金流!');
                        return;
                    }
                    if (record.dirty == true) {
                        Leaf.showMessage('${l:PROMPT}', '请先保存再确认');
                        return;
                    }
            
                    //校验
            
                   /*  var status = record.get('status');
                    if (status == 'C') {
                        Leaf.showMessage("${l:PROMPT}", "已生成现金流的理赔不能再次生成!");
                        return;
                    } */
 
                    data = {};
                    data['claims_id'] = record.get('claims_id');
                    data['contract_id'] = record.get('contract_id');
                    data['policy_id'] = record.get('policy_id');
            
                    data['_status'] = 'update';
                    datas.push(data);
            
                }
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                param['details'] = datas;
                var url_l = $('ins_claims_create_link_id').getUrl();
                Leaf.request({
                    url: url_l,
                    para: datas,
                    success: function() {
                        Leaf.SideBar.enable = true;
                        Leaf.SideBar.show({
                            msg: '${l:FND501.SAVE_SUCCESS}',
                            duration: 2000
                        });
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $(ds_id).query();
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            };
            //新增和加载时调用(form)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'cla_insurance_claims_policy');
                if (ds.id == ds_id) {
                    if (!record) {
                        return;
                    }
            
                    //已确认的不可编辑
                    if (record.data['status'] == 'C') {
            
                        record.getField('claims_amount').setReadOnly(true);
                    }
            
                }
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>