<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: lpc 9874
    $Date: $
    $Revision: 1.0 $
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <s:server-script import="contract_print_path.js"><![CDATA[
           $ctx.parameter.file_path = con_print_path['con_print_path'];
           $ctx.parameter.tomcat_source = con_print_path['tomcat_source'];
        ]]></s:server-script>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>
        <a:link id="ast_claims_detail_screen_id" url="${/request/@context_path}/modules/cont/CON308/con_car_insurance.lview"/>
        <a:link id="con308_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="con308_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script src="${/request/@context_path}/javascripts/jquery-1.6.4.min.js" type="text/javascript"/>
        <a:link id="con_car_ins_batch_save_update" model="db.con_car_insurance_pkg.con_car_ins_save_update" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
            Ext.ux.Lightbox.register('a[ref=img]', true);
            //给自定义删除按钮新增图标
            jQuery.noConflict();
            
            jQuery(document).ready(function() {
                var table_id = "#${/parameter/@layout_code}_G_INSUR_INFO_USER_BUTTON1_layout_dynamic_button_id";
                var btn_id = "#ext-gen101";
                var div_id = "ext-gen102";
                jQuery(btn_id).addClass("grid-delete");
                // $("#wde").css("background-image":"url(p3.jpg)");
                // Ext.get(id).setStyle({
                    // background-image:url(../toolbar/toolbar_btn.gif)
                // });
                // Ext.get('failure_form').setStyle('display', 'none');
                 Ext.get(div_id).setStyle('background-position','0px -35px');
                // jQuery(btn_id).addStyle("background-image:url(../toolbar/toolbar_btn.gif)");
                jQuery(table_id).removeClass("item-btn infor-btn").addClass('item-btn item-btn-icon-text infor-btn');
                jQuery("div").unbind(); //移除所有
            });
            //理赔信息
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                var record = $(ds_id).getSelected()[0];
                var param = {};
                param['function_code'] = 'CON308Q';
                param['function_usage'] = 'MODIFY';
                param['url_title'] = '理赔信息';
                param['contract_lease_item_id'] = record.get('contract_lease_item_id');
                param['winid'] = 'con308n_con_contract_lease_item_modify_winid';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'ast_claims_detail_screen_id', ds_id);
            
            };
            
            //PDF预览
            
            function view_pdf(attachment_id) {
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/fnd.fnd_atm_attachment/query',
                    para: {
                        attachment_id: attachment_id
                    },
                    success: function(res) {
                        var path = res.result.record.file_path;
                        path = path.substr(path.indexOf('hls_attachment'));
                        var tomcat_source = '${/parameter/@tomcat_source}';
                        var source_path = 'http://' + window.location.host + '/' + tomcat_source + '/' + path;
                        var oWin = window.open(source_path);
                    },
                    scope: this
                });
            }
            
            function upload_file(id, name, query_only) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
                if (record.get('con_car_insurance_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('con308_cdd_downloadFile_id').getUrl() + '?table_name=CON_CAR_INSURANCE&header_id=' + record.get('con_car_insurance_id');
                    } else {
                        url = $('con308_cdd_uploadFile_id').getUrl() + '?table_name=CON_CAR_INSURANCE&header_id=' + record.get('con_car_insurance_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}', '请先保存!');
            
                }
            }
            
            //grid删除 保险
            window['${/parameter/@layout_code}_G_INSUR_INFO_USER_BUTTON1_layout_dynamic_tab_click'] = function() {
                //
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_car_insurance');
                var records = $(ds_id).getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                    return;
                }
                var param_list = [];
                var param = {};
                for (var i = 0;i < records.length;i++) {
                    param = records[i].data;
                    if (records[i].get('actual_premium_flag') == 'N') {
                        Leaf.showMessage('${l:HLS.PROMPT}', '实际保费存在核销，不允许删除！');
                        return;
                    }
                    param['_status'] = 'delete';
                    param_list.push(param);
                }
            
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                //如果是未保存的直接移除
                if (!records[0].get('con_car_insurance_id')) {
                    var grid_id = '${/parameter/@layout_code}_G_INSUR_INFO_con_car_insurance_layout_grid_id';
                    $(grid_id).clear();
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                } else {
                    Leaf.showConfirm('提示', '是否确认删除选中记录？', function() {
                        Leaf.request({
                            url: $('con_car_ins_batch_save_update').getUrl(),
                            para: param_list,
                            success: function(res) {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                $(ds_id).query();
                                Leaf.SideBar.show({
                                    html: '<div style="background-color:#ccfbd5;position:absolute;padding:3px;border:1px solid #009900">' + '删除成功' + '</div>',
                                    duration: 1000
                                });
            
                            },
                            error: function() {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            failure: function() {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            sync: true,
                            scope: this
                        });
                    }, window['${/parameter/@layout_code}_unlock_layout_dynamic_window']());
                }
            
            }
            
            //加载时调用(grid,table,gridBox)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
                var con_car_insurance_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_car_insurance');
                var records = $(con_car_insurance_ds_id).getAll();
                if (records.length == 0) {
                    return;
                }
                if (con_car_insurance_ds_id == ds.id) {
                    //
                    if (record.get('actual_premium_flag') == 'N') {
                        record.getField('actual_premium').setReadOnly(true);
                        record.getField('actual_premium').setRequired(false);
            
                        record.getField('insure_handle_method').setReadOnly(true);
                        record.getField('insure_handle_method').setRequired(false);
                        record.getField('insure_handle_method_n').setReadOnly(true);
                        record.getField('insure_handle_method_n').setRequired(false);
                    }
            
                }
            
            };
            
            //更新时调用
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                var con_car_insurance_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_car_insurance');
                if (con_car_insurance_ds_id == ds.id) {
                    var insurance_date_from = record.get('insurance_date_from');
                    var insurance_date_to = record.get('insurance_date_to');
                    //
                    if (insurance_date_from && insurance_date_to) {
                        if (name = 'insurance_date_from') {
                            if (insurance_date_from > insurance_date_to) {
                                Leaf.showMessage('${l:HLS.PROMPT}', '保险起保日需小于保险到期日!');
                                return true;
                            }
                        }
                        if (name == 'insurance_date_to') {
                            if (insurance_date_from > insurance_date_to) {
                                Leaf.showMessage('${l:HLS.PROMPT}', '保险起保日需小于保险到期日!');
                                return true;
                            }
                        }
                    }
                }
            };
            
            //保存submitsuccess调用
            window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function(ds, record, res, bp_seq) {
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_car_insurance');
                var records = $(ds_id).getAll();
                if (records.length == 0) {
                    return;
                }
            
                var param_list = [];
                var param = {};
                for (var i = 0;i < records.length;i++) {
                    param = records[i].data;
                    param['_status'] = 'update';
                    param_list.push(param);
                }
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('con_car_ins_batch_save_update').getUrl(),
                    para: param_list,
                    success: function(res) {
                        ds.query();
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            
            
            
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    sync: true,
                    scope: this
                });
            
            
            
            
            };
            
            //超链接渲染
            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';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</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;
            
                    }
                }
            };
        window['${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
            
                if (ds == $(ds_id)) {
                    aut_authority_list_validate_query(ds, qpara);
            
                }
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CON308&amp;"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
