<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei  
    $Date: 2016-12-20 上午11:57:52  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" dynamiccreateenabled="true" trace="true">
    <a:view>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="con640_update_con_collection_recived_flag_link_id" model="cont.CON640.con_collection_tool" modelaction="insert"/>
        <a:link id="con640_trans_con_collection_realize_link_id" model="cont.CON640.con_collection_tool" modelaction="update"/>
        <a:link id="con640_trans_con_collection_letter_submit_link_id" model="cont.CON640.con_collection_tool" modelaction="delete"/>
        <a:link id="con640_cob_collection_add_bp_link_id" url="${/request/@context_path}/modules/cont/CON640/con_contract_bp_add.lview"/>
        <a:link id="${/parameter/@layout_code}_car_modify_special_link" url="${/request/@context_path}/modules/prj/PRJ500N/prj_project_create_special_wfl.lview"/>
        <a:link id="${/parameter/@layout_code}_con_collection_call_patter_link_id" url="${/request/@context_path}/modules/cont/CON632/con_collection_call_patter.lview"/>
        <script type="text/javascript"><![CDATA[
        
        
         //保存前调用，前台校验
            window['${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function(ds, record) {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var ds_id=get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_TOOL_INFO', 'con_collection_tool');
               if($(ds_id).validate()){
                  var records=$(ds_id).getAt(0);
                  if(records.get('car_out_day')-records.get('car_storage_day')<0){
                       Leaf.showMessage('${l:PROMPT}','车辆入库日与车辆出库日校验错误！');
                       window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                       return false;
                  }else{
                      window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                       return true;
                  }
               }else{
                   window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                       return false;
               }
            };
        
           //dataset字段跟新事件
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {

                    //收车根据内外控制必输
                    if (name == 'car_storage_day'||name=='car_out_day') {

                       if(!Ext.isEmpty(record.get('car_out_day'))&&!Ext.isEmpty(record.get('car_storage_day'))){
                        if((record.get('car_out_day')-record.get('car_storage_day'))/(60*60*24*1000)<0){    
                            record.set('car_duration_day','');
                             Leaf.showMessage('${l:PROMPT}','车辆入库日与车辆出库日校验错误！');
                             
                        }else{
                            record.set('car_duration_day',(record.get('car_out_day')-record.get('car_storage_day'))/(60*60*24*1000));
                        }
                       }
            
                    }
            
            
            }
            
            //确认收车
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var ds_id=get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
                Leaf.showConfirm('提示','确认车辆已经收回吗？',function(){
        	        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
        	        Leaf.request({
		                url: $('con640_update_con_collection_recived_flag_link_id').getUrl(),
		                para: {
		                    col_id :'${/parameter/@col_id}'
		                },
		                success: function(res) {
		                    
		    	            Leaf.SideBar.show({
		    	            	msg:'收车确认成功！',
		    	            	duration:2000
		    	            });
		    	            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                failure:function(){
		                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                error:function(){
		                   window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                scope: this
	            	}); 
        	    });
            };
            
            //变现
            window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
                var ds_id=get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
                Leaf.showConfirm('提示','确认提交变现吗？',function(){
        	        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
        	        Leaf.request({
		                url: $('con640_trans_con_collection_realize_link_id').getUrl(),
		                para: {
		                    col_id :'${/parameter/@col_id}',
		                    document_type:'REALIZE',
		                },
		                success: function(res) {
		                    
		    	            Leaf.SideBar.show({
		    	            	msg:'提交成功！',
		    	            	duration:2000
		    	            });
		    	            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                    $('${/parameter/@winid}').close();
		                },
		                failure:function(){
		                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                error:function(){
		                   window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                scope: this
	            	}); 
        	    });
            };
            
             //赎回
            window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
                var ds_id=get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
                Leaf.showConfirm('提示','确认提交赎回吗？',function(){
        	        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
        	        Leaf.request({
		                url: $('con640_trans_con_collection_letter_submit_link_id').getUrl(),
		                para: {
		                    col_id :'${/parameter/@col_id}'
		                },
		                success: function(res) {
		                    
		    	            Leaf.SideBar.show({
		    	            	msg:'提交成功！',
		    	            	duration:2000
		    	            });
		    	            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                    $('${/parameter/@winid}').close();
		                },
		                failure:function(){
		                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                error:function(){
		                   window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                scope: this
	            	}); 
        	    });
            };
            
            //诉讼
            window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function() {
                var ds_id=get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
                Leaf.showConfirm('提示','确认提交诉讼吗？',function(){
        	        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
        	        Leaf.request({
		                url: $('con640_trans_con_collection_realize_link_id').getUrl(),
		                para: {
		                    col_id :'${/parameter/@col_id}',
		                    document_type:'LAWSUIT',
		                },
		                success: function(res) {
		                    
		    	            Leaf.SideBar.show({
		    	            	msg:'提交成功！',
		    	            	duration:2000
		    	            });
		    	            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                    $('${/parameter/@winid}').close();
		                },
		                failure:function(){
		                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                error:function(){
		                   window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                scope: this
	            	}); 
        	    });
            };
            
            
            //诉讼
            window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function() {
                var ds_id=get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
                Leaf.showConfirm('提示','确认提交诉讼吗？',function(){
        	        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
        	        Leaf.request({
		                url: $('con640_trans_con_collection_realize_link_id').getUrl(),
		                para: {
		                    col_id :'${/parameter/@col_id}',
		                    document_type:'LAWSUIT',
		                },
		                success: function(res) {
		                    
		    	            Leaf.SideBar.show({
		    	            	msg:'提交成功！',
		    	            	duration:2000
		    	            });
		    	            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                    $('${/parameter/@winid}').close();
		                },
		                failure:function(){
		                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                error:function(){
		                   window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
		                },
		                scope: this
	            	}); 
        	    });
            };
            
            
             //增加担保
            window['${/parameter/@layout_code}_user_button5_layout_dynamic_click'] = function() {
                var coll_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
                var record=$(coll_ds_id).getAt(0);
                param={};
                if('${/parameter/@function_code}'!='CON640D_GUARANTEE_QUERY'){
                param['col_id'] = record.get('col_id');
                param['contract_id'] = record.get('contract_id');
                param['function_code'] = 'CON640D_ADD_BP';
                param['function_usage'] = 'MODIFY';
                param['maintain_type'] = 'UPDATE';
                param['url_title'] = '增加担保';
                param['winid'] = 'con640_con_collection_add_bp_winid';
                }else{
                param['col_id'] = record.get('col_id');
                param['contract_id'] = record.get('contract_id');
                param['function_code'] = 'CON640D_GUARANTEE_ADD_QUERY';
                param['function_usage'] = 'READONLY';
                param['maintain_type'] = 'QUERY';
                param['url_title'] = '增加担保明细';
                param['winid'] = 'con640_con_collection_add_bp_query_winid';    
                }
                hls_doc_get_layout_code('prj_project_get_layout_code_link_id', param, 'con640_cob_collection_add_bp_link_id');
            };
            
            
            
              function open_project_Window(record_id, ds_id) {
                var record = $(ds_id).findById(record_id);
                var maintain_type = 'QUERY';
                var param = {};
                param['company_id'] = record.get('company_id');
                param['project_id'] = record.get('project_id');
                param['function_code'] = 'PRJ502D';
                param['function_usage'] = 'QUERY';
                param['bp_class'] = record.get('bp_class');
                param['maintain_type'] = maintain_type;
                /* param['window_open_flag'] = 'Y';
                 param['show_history_flag'] = 'Y'; */
                param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
                hls_doc_get_layout_code('prj_project_get_layout_code_link_id', param, '${/parameter/@layout_code}_car_modify_special_link', ds_id, '${/parameter/@layout_code}');
            }
            
               function visit_patter_detail(call_ln_id){
                            var win = new Leaf.Window({
                                id: '${/parameter/@layout_code}_con_collection_call_patter_win_id',
                                url: $('${/parameter/@layout_code}_con_collection_call_patter_link_id').getUrl(),
                                params: {
                                    winid: '${/parameter/@layout_code}_con_collection_call_patter_win_id',
                                    call_ln_id: call_ln_id,
                                    query_flag:'Y'
                                },
                                title: '话术详情',
                                width: 1050,
                                height: 550
                            });                  
          }
            
              //超链接渲染
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
               if (name == 'attachment') {
                    link_function = '${/parameter/@layout_code}_prj500_cdd_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>';
                }else if (name == 'project_number') {
                        return '<a href="javascript:open_project_Window(\'' + record.id + '\',\'' + record.ds.id + '\');">' + value + '</a>';
                    }else if(name=='patter_detail') {
                         link_function='visit_patter_detail';
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.get('call_ln_id') + '\');">话术详情</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_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                                if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                    url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                                } else {
                                    url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                                }
                            }
                        }
                        return url;
                    }
                    
                } 
            };
        
         //附件上传
            window['${/parameter/@layout_code}_prj500_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                
                if (record.get('check_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    } else {
                        url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_cdd_uploadFile_screen_id',
                        width: 850,
                        height: 400
                    });
            
                    win.on('close', function() {
                        record.ds.query();
                    });
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                }
            }; 
   ]]></script>
    </a:view>
</a:screen>
