<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author:  Yimeng
    $Date: 2014-11-27 下午01:58:31  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.specify_code=&apos;PROJECT_DOC_APPROVER&apos;" model="cont.CON543.lsh_hls_specify_define" rootPath="hls_specify_define_info"/>
        <!-- <a:model-query model="cont.CON543.prj_project" rootPath="prj_project" /> -->
        <!-- <a:model-query defaultWhereClause="" model="cont.CON543.con_contract_for_query" rootPath="" /> -->
    </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"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@tree_code}_con543_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@tree_code}_con543_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="con_batch_dl_link_id" url="${/request/@context_path}/modules/cont/CON505/con_atm_batch_dl.lsc"/>
        <a:link id="con543_submit_link" model="cont.CON543.lsh_con_sign_submit" modelaction="execute"/>
        <a:link id="con543_cdd_update_link" model="cont.CON543.lsh_hls_contract_review_info" modelaction="batch_update"/>
        <a:link id="con543_con_contract_update_print_detail_link_id" url="${/request/@context_path}/modules/cont/CON500/con_contract_update_print_detail.lview"/>
        <a:link id="con543_prj_secify_approver_link" url="${/request/@context_path}/modules/prj/PRJ501N/lsh_hls_specify_approver.lview"/>
        <a:link id="lsh_vender_attachment_link" url="${/request/@context_path}/modules/cont/CON545/con_contract_attachment.lview"/>
        <a:link id="prj_project_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="prj_project_modify_link" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_create_tree_n.lview"/>
        <script type="text/javascript"><![CDATA[
        
            function open_attachment_win(ds_id,record_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
                
                param['function_code'] = 'CON545';
                param['function_usage'] = 'MODIFY';
              //  param['layout_code'] = 'VENDOR_ATTACHMENT';
                param['url_title'] = '供应商附件';
 
               hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'lsh_vender_attachment_link', ds_id);
            
            }
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
                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])) {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                        return url;
            
                    }
                } else if (name == 'attachment') {
                    link_function = '${/parameter/@layout_code}_con543_cdd_attachtment_upload';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\',\'' + record.ds.id + '\');">' + config_record.get('prompt') + '</a>';
                } else if (name == 'file') {
                    link_function = '${/parameter/@layout_code}_downloadfile_link';
                    var content_id = record.get('content_id');
                    var content_print_flag = record.get('content_print_flag');
                    if (content_id && content_print_flag == 'Y') {
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + content_id + '\');">' + config_record.get('prompt') + '</a>';
                    } else {
                        return;
                    }
                }
                if (name == 'vender_attach' && record.get('bp_category') == 'VENDER') {
                     return '<a href="javascript:open_attachment_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + '供应商附件' + '</a>'; 
                }
            };
            
            function unlock_tree_window() {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            }
            
            function lock_tree_window() {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            }
            
            window['${/parameter/@layout_code}_con543_cdd_attachtment_upload'] = function(id, name, query_only, ds_id) {
                var record = $(ds_id).findById(id);
                if (record.get('check_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}${/parameter/@tree_code}_con543_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    } else {
                        url = $('${/parameter/@layout_code}${/parameter/@tree_code}_con543_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}', '请先保存!');
                }
            };
            window['${/parameter/@layout_code}_downloadfile_link'] = function(content_id) {
                var url = $('con_batch_dl_link_id').getUrl() + '?content_id=' + content_id + '&contract_id=' + '${/parameter/@contract_id}';
                window.open(url, '_self');
            };
            
            
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                birturl = '${/request/@context_path}/reports?__report=reports/contract/OTHER_CONTRACT.rptdesign&__format=pdf&contract_id=' + ${/parameter/@contract_id};
                window.open(birturl);
            };
            
            function con543_window_close() {
                $('hls_doc_get_layout_code_winid').close();
            }
            
            function submit_confirm(){
                var document_id = ${/parameter/@contract_id};
                var document_table = 'CON_CONTRACT';
                var title = '${/model/hls_specify_define_info/record/@description}';
                // var win = new Leaf.Window({
                    // id: 'lsh_prj_secify_approver_screen',
                    // url: $('con543_prj_secify_approver_link').getUrl(),
                    // params: {
                        // document_id: document_id,
                        // specify_code: 'PROJECT_DOC_APPROVER'
                    // },
                    // title: title,
                    // width: 550,
                    // heigh: 650
                // });
                // win.on('close', function() {
                    ajax_flag = 'Y';
            
                    /* parent.Leaf.SideBar.enable = true;
                     parent.Leaf.SideBar.show({
                     msg: '${l:HLS.SUBMIT_SUCCESS}',
                     duration: 2000
                     }); */
                    Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            
                    Leaf.request({
                        url: $('con543_submit_link').getUrl(),
                        para: {
                            document_id: document_id,
                            document_table: document_table
                        },
                        success: function(res) {
                            Leaf.Masker.unmask(Ext.getBody());
            
            
                            Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.SUBMIT_SUCCESS}', function() {
                                con543_window_close();
                            });
            
                        },
                        failure: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
            }
            
            window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
                Leaf.showConfirm('提示','确认提交审批?',submit_confirm,function(){});
                
                // });
            };
            
            
            
            function con505_con_contract_content_print() {
                var records = $('con505_contract_result_ds').getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                    return;
                }
                var record = records[0];
                new Leaf.Window({
                    id: 'con_contract_update_print_detail_winid',
                    params: {
                        contract_id: record.get('contract_id'),
                        document_category: record.get('document_category'),
                        business_type: record.get('business_type'),
                        winid: 'con_contract_update_print_detail_winid'
                    },
                    url: $('con543_con_contract_update_print_detail_link_id').getUrl(),
                    title: '${l:CON505.CON_CONTENT_PRINT}',
                    width: 900,
                    height: 450
                });
            }
            
            //保存前调用
            window['${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function(ds, record) {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var cdd_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_cdd_item_doc_ref');
               
                if(cdd_ds){  
                var records = $(cdd_ds).getAll();
                if ('${/parameter/@layout_code}' == 'CON_CONTEXT_CONFIRM_1') {
                    for (var i = 0;i < records.length;i++) {
            
            
                        var note2 = records[i].get('note2') == undefined ? '' : records[i].get('note2');
            
                        var note = records[i].get('note') == undefined ? '' : records[i].get('note');
            
                        if (note2 == '') {
                            records[i].set('note2', note);
                            records[i].set('note', '');
            
                        }
                        records[i].set('_status', 'update');
                    }
            
                }
                var check_flag = true;
                return check_flag;
                }
                return true;
            };
            
            
            window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
                //
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var cdd_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_cdd_item_doc_ref');
                var record = $(ds_id).getAt(0);
                var win = new Leaf.Window({
                    id: 'con_contract_update_print_detail_winid',
                    params: {
                        contract_id: record.get('contract_id'),
                        document_category: record.get('document_category'),
                        business_type: record.get('business_type'),
                        content_type: 'AUDIT',
                        winid: 'con_contract_update_print_detail_winid'
                    },
                    url: $('con543_con_contract_update_print_detail_link_id').getUrl(),
                    title: '${l:CON505.CON_CONTENT_PRINT}',
                    width: 900,
                    height: 450
                });
                win.addListener('close', function() {
                    if (cdd_ds) {
                        $(cdd_ds).query();
                    }
                });
            };
            
        	//查看项目信息
            window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {

                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                if('${/parameter/@function_code}' == 'CON543RE'||'${/parameter/@function_code}' == 'CON543W'){
                    var record = $(ds_id).getAt(0);
                    var project_id = record.get('project_id');
                    if(project_id){
		                var param = {
		                    'document_id': project_id,
		                    'project_id': project_id,
		                    'lease_channel': record.get('lease_channel'),
		                    'division': record.get('division'),
		                    'business_type': record.get('business_type'),
		                    'bp_class': record.get('bp_class'),
		                    'bp_tenant_type': record.get('bp_tenant_type_p'),
		                    'bp_vender_type': record.get('bp_vender_type_p'),
		                    'bp_category': record.get('bp_category'),
		                    'cond_para2': record.get('bp_tenant_type_p'),
		                    'cond_para3': record.get('bp_vender_type_p'),
		                    'function_code': 'PRJ502D',
		                    'function_usage': 'QUERY',
		                    'maintain_type': 'UPDATE',
		                    'url_title': '${l:HLS.PROJECT_VIEW}',
		                    'prj_report_read_flag': 'Y',
		                    'winid': 'con_view_project_win',
		                    'company_id': '${/session/@company_id}',
		                    'document_type':record.get('document_type_p'),
		                    'document_category':'PROJECT',
		                    'lease_organization':'1000',
		                    'number_of_guarantor':1
		                };
		                hls_doc_get_layout_code('prj_project_get_layout_code_link_id', param, 'prj_project_modify_link');
                    }
                }
            }
            
            function zjwfl_before_approve_procedure(out_type) {
                var document_id = '${/parameter/@contract_id}';
                var appoint_check = '${/parameter/@appoint_check}';
                var specify_code = '${/parameter/@specify_code}'||'PROJECT_DOC_APPROVER';
                var params;
                out_type = 'no_win';
                var out_object = 'out_object';
                if (appoint_check) {
                    var document_table = 'CON_CONTRACT';
                    var title = '${/model/hls_specify_define_info/record/@description}';
                    var win = new Leaf.Window({
                        id: 'lsh_prj_secify_approver_screen',
                        url: $('con543_prj_secify_approver_link').getUrl(),
                        params: {
                            document_id: document_id,
                            specify_code: specify_code
                        },
                        title: title,
                        width: 550,
                        heigh: 650
                    });
                    out_type = 'win';
                    out_object = win;
                }
            
                params = {
                    out_type: out_type,
                    out_object: out_object
                };
                return params;
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>