<?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>
        <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="con304_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="con304_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script src="${/request/@context_path}/javascripts/jquery-1.6.4.min.js" type="text/javascript"/>
        <style type="text/css"><![CDATA[
        .redBG{
            background-color:#FFC0CB;
            }
        .yellowBG{
            background-color:#FFFF00;
            }
    	]]></style>
        <script type="text/javascript"><![CDATA[
            jQuery.noConflict();
            
            var isLoaded = 'N';
            //	set单元格颜色  load事件无法实现效果
            var check_isload = setInterval(function() {
                //
                if (isLoaded == 'N') {
                    var ids = $('${/parameter/@layout_code}_G_CON_LEASEITEM_con_contract_lease_item_ds');
                    var idsRecord = ids.getAll();
                    for (var i = 0;i < idsRecord.length;i++) {
                        var rowData = idsRecord[i];
                        var mog_lease_overdue_flag = rowData.get('mog_lease_overdue_flag');
                        //mog_lease_overdue_flag将未完成抵押单据中的底色变为红色  车辆上牌后15天内未完成抵押则开始提醒
                        if (mog_lease_overdue_flag == 'Y') {
                            tr_id = '#${/parameter/@layout_code}_G_CON_LEASEITEM_con_contract_lease_item_layout_grid_id-u-' + rowData.id;
                            jQuery(tr_id).removeClass("row-selected").addClass('redBG');
                        }
                    }
            
                } else {
                    clearInterval(check_isload);
                }
            }, 1000);
            Ext.ux.Lightbox.register('a[ref=img]', true);
            //PDF预览
            // //新增时调用(grid,table,gridBox)
            // window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
            // var ds_id = '${/parameter/@layout_code}_G_MOR_INFO_NEW_con_contract_lease_mortgage_ds';
            //
            // var records = $(ds_id).getAll();
            // for(i = 0;i<records.length;i++){
            // var mortgage_flag = records[i].get('mortgage_flag');
            // if(mortgage_flag=='N'){
            // records[i].getField('mortgage_owner').setReadOnly('true');
            // records[i].getField('mortgage_date').setReadOnly('true');
            // records[i].getField('remortgage_date').setReadOnly('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 lease_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
            
                $(lease_ds_id).query();
            
            };
            
            //更新时调用
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
               var con_contract_lease_mortgage_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_mortgage');
                if (con_contract_lease_mortgage_ds_id == ds.id) {
                    if (name == 'mortgage_date') {
                        var remortgage_date = record.get('remortgage_date');
                        if (value > remortgage_date) {
                           Leaf.showMessage('${l:HLS.PROMPT}', '解除抵押日期需大于抵押日期!');
                           return true;
                        } 
                    }
                    if (name == 'remortgage_date') {
                        var mortgage_date = record.get('mortgage_date');
                        if (value < mortgage_date) {
                           Leaf.showMessage('${l:HLS.PROMPT}', '解除抵押日期需大于抵押日期!');
                           return true;
                        } 
                    }
                }
            };
            
            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('contract_mortgage_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('con304_cdd_downloadFile_id').getUrl() + '?table_name=CON_CONTRACT_LEASE_MORTGAGE&header_id=' + record.get('contract_mortgage_id');
                    } else {
                        url = $('con304_cdd_uploadFile_id').getUrl() + '?table_name=CON_CONTRACT_LEASE_MORTGAGE&header_id=' + record.get('contract_mortgage_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_file_new(id, name, query_only) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
                //
                if (record.get('invoice_manage_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('con304_cdd_downloadFile_id').getUrl() + '?table_name=ACR_INVOICE_MANAGE&header_id=' + record.get('invoice_manage_id');
                    } else {
                        url = $('con304_cdd_uploadFile_id').getUrl() + '?table_name=ACR_INVOICE_MANAGE&header_id=' + record.get('invoice_manage_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';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                } else if (name == 'attachment_new') {
                    link_function = 'upload_file_new';
                    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=CON304&amp;"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
