<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author:   
    $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="ins_claims_create_link_id" model="ins.INS505.ins_cashflow_create" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'cla_insurance_claims_policy');
            
                var records = $(ds_id).getSelected();
            
                for (var i = 0;i < records.length;i++) {
                    if (records[i].dirty == true) {
                        Leaf.showMessage('${l:PROMPT}', '请先保存再确认');
                        return;
                    }
                }
            
                if (!records.length) {
                    Leaf.showMessage('${l:PROMPT}', '请至少选择一条记录');
                    return;
                }
            
                //校验
                for (var i = 0;i < records.length;i++) {
                    var status = records[i].get('status');
                    if (status == 'C') {
                        Leaf.showMessage("${l:PROMPT}", "已生成现金流的理赔不能再次生成!");
                        return;
                    }
                }
            
                var param = new Object();
                var datas = [];
            
                if (records.length == 0) {
                    Leaf.showInfoMessage('提示', '请至少选择一行!', null, 200, 100);
                }
            
                for (var i = 0;i < records.length;i++) {
                    if (records[i].get('claims_id')) {
            
                        data = {};
                        data['claims_id'] = records[i].get('claims_id');
                        data['contract_id'] = records[i].get('contract_id');
                        data['policy_id'] = records[i].get('policy_id');
            
                        data['_status'] = 'update';
                        datas.push(data);
            
                    }
                }
                param['details'] = datas;
                var url_l = $('ins_claims_create_link_id').getUrl();
                Leaf.request({
                    url: url_l,
                    para: datas,
                    success: function() {
                        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
                });
            };
            
            //删除
            window['${/parameter/@layout_code}_G_INS_RESULT_USER_BUTTON1_layout_dynamic_tab_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'cla_insurance_claims_policy');
            
            
                var records = $(ds_id).getSelected();
            
                if (records.length == 0) {
                    Leaf.showMessage("${l:PROMPT}", "请选择需要删除的记录!");
                    return;
                }
            
                //校验
                for (var i = 0;i < records.length;i++) {
                    var status = records[i].get('status');
                    if (status == 'C') {
                        Leaf.showMessage("${l:PROMPT}", "已生成现金流不能删除!");
                        return;
                    }
                }
            
                for (var i = 0;i < records.length;i++) {
                    $(ds_id).remove(records[i]);
                }
            
            
            };
            
            //加载时调用(grid,table,gridBox)
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_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) {
                    var records = $(ds_id).getAll();
            
                    if (!records.length) {
                        return;
                    }
            
                    for (var i = 0;i < records.length;i++) {
                        //已确认的不可编辑
                        if (records[i].data['status'] == 'C') {
            
                            records[i].getField('claims_amount').setReadOnly(true);
                        }
                    }
                }
            
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>