<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qm  
    $Date: 2014-6-7
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query model="cont.CON541.get_sub_condition" rootPath="get_sub_condition"/>
        <a:model-query model="cont.CON555.con555_get_info" rootPath="con555_get_info"/>
        <a:model-execute model="db.prj_cdd_item_pkg.prj_cdd_item_extra_save"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con555_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="con555_cdd_download_id" url="${/request/@context_path}/atm_download.lsc"/>
        <a:link id="con555_cdd_query_link" url="${/request/@context_path}/autocrud/cont.CON555.con_content_query_detail/query"/>
        <a:link id="con_contract_sign_link_id" model="cont.CON544.con_contract_save" modelaction="batch_update"/>
        <a:link id="pageLink_prj_project_credit_report" url="${/request/@context_path}/modules/prj/PRJ502/prj_project_credit_report_combine.lview"/>
        <a:link id="contract_credit_back_link" model="cont.CON544.contract_credit_back_execute" modelaction="execute"/>
        <a:link id="contract_credit_confirm_link" model="cont.CON544.contract_credit_confirm_execute" modelaction="execute"/>
        <a:link id="contract_credit_reject_link" model="cont.CON544.contract_credit_reject_execute" modelaction="execute"/>
        <a:link id="con_contract_credit_back_msg_link" url="${/request/@context_path}/modules/cont/CON544/con_contract_credit_back_msg.lview"/>
        <script type="text/javascript"><![CDATA[
            function con555_cdd_editorFunction(record, name){
                if (record.get('sys_flag') == 'N') {
                    return 'con555_cdd_tf_id';
                }
                return '';
            }
            
            function con555_cdd_selectFunc(record) {
                if (record.get('sys_flag') == 'Y') {
                    return false;
                }
                return true;
            }
            
            function con555_cdd_attachment_render(value, record, name){
         
                 var check_id = record.get('check_id');
                var file_name = record.get('file_name');
                var record_id = record.id;
                if (!record.isNew && check_id) {
                    return '<a href="javascript:con555_cdd_attachtment_upload(\'' + record.get('check_id') + '\',\'' + file_name + '\',\'' + record_id + '\')">${l:HLS.ATTACHMENT}</a>';
                }
            }
            
            function con555_link_render(value, record, 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; 
                }
            }       
            
            function con555_cdd_attachtment_upload(check_id, file_name, record_id) {
                var url = $('con555_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + check_id;
                var record = $('con555_detail_result1_ds').getCurrentRecord();
                var oldvalue = file_name ? file_name : null;
                var contract_id = ${/parameter/@contract_id};
                paras = {
                    'contract_id': contract_id
                };
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'con555_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });
                win.on('close', function() {
                    //
                    Leaf.request({
                        url: $('con555_cdd_query_link').getUrl(),
                        para: paras,
                        success: function(data) {
                   
                            $('con555_detail_result1_ds').query();

                        },
                        sync: true
                    });           
                });
            }

            function con555_cdd_required_render(value, record, name){
                var project_required_flag = record.get('project_required_flag');
                if (project_required_flag == 'Y') {
                    return '<pan style="color:red">' + value + '</pan>';
                } else {
                    return value;
                }
            }
            // window['con555_attach_add'] = function(ds) {
                // var record = $('con555_detail_result1_ds').getAt(0);
                // var current_record = ds.getCurrentRecord();
                // current_record.data['document_table'] = 'PRJ_CDD_ITEM_CHECK';
                // current_record.data['cdd_list_id'] = record.get('cdd_list_id');
                // current_record.data['document_id'] = record.get('document_id');
                // current_record.data['note'] = record.get('note');
                // document_category = record.get('document_category');
                // if (document_category == 'CONTRACT') {
                    // current_record.data['contract_required_flag'] = 'N';
                    // current_record.data['contract_display_flag'] = 'Y';
                // } else if (document_category == 'PROJECT') {
                    // current_record.data['project_required_flag'] = 'N';
                    // current_record.data['project_display_flag'] = 'Y';
                // }
            // };
            // window['con555_attach_load'] = function(ds) {
                // var records = ds.getAll();
                // if (records.length) {
                    // for (var i = 0;i < records.length;i++) {
                        // var record = records[i];
                        // if (Ext.isEmpty(record.get('check_id'))) {
                            // record.dirty = true;
                        // }
                    // }
                // }
            // };
         
            function con555_con_contract_back()
            {
                $('con_contract_content_window').close();
            }
            
            // function con555_con_contract_sign() {
                // if ($('con555_detail_ds').validate()) {
                    // var record = $('con555_detail_ds').getCurrentRecord();
            		// record.set('_status', 'update');
            		// var saveData = [];
            		// saveData.push(record.data);
                    // Leaf.showConfirm('${l:PROMPT}', '确认通过?', function() {
                        // Leaf.request({
                            // url: $('con_contract_sign_link_id').getUrl(),
                            // para: saveData,
                            // success: function() {
                                // Leaf.SideBar.show({
                                    // msg: '确认成功',
                                    // duration: 2000
                                // });
                                // con555_con_contract_back();
                            // },
                            // scope: this
                        // });
                    // }, function() {
                        // return;
                    // }, null, null);
                // }
            // }
            function project_number_render(value, record, name) {
                return '<a href="javascript:openWindow(' + record.get('project_id') + ')">'+value+'</a>'; 
            }
            
            function openWindow(project_id) {
                var lease_channel = $('con555_detail_ds').getCurrentRecord().get('lease_channel');
                if(lease_channel=='70'){
                    Leaf.showMessage('提示','阿里巴巴的合同的案件编号为虚拟的，无法查看！');
                    return ;
                }
                new Leaf.Window({
                    id: 'prj_project_credit_report_id',
                    params: {
                        PROJECT_ID: project_id
                    },
                    url: $('pageLink_prj_project_credit_report').getUrl(),
                    title: '项目报告查看',
                    fullScreen: true
                });
            }
            
              
            function download1()
             {
                       var root_ds = $('con555_detail_ds');
                        var record = root_ds.getAt(0);
                        var document_id = record.get('contract_id');
                        var document_table = 'CON_CONTRACT';
                        var document_number = record.get('contract_number');
                        var tab_group = 'CONTRACT';
                        var grp_document_table = 'CON_CONTRACT_CREDIT';
                        var lender_required_flag = 'Y';
                        var lender_display_flag = 'Y';
                        var url = '${/request/@context_path}/modules/batch_download/lease_atm_batch_dl.lsc?table_name=' + document_table + '&table_pk_value=' + document_id + '&doc_code=' + document_number + '&tab_group='+tab_group + '&grp_document_table='+grp_document_table+'&lender_display_flag='+lender_display_flag+'&lender_required_flag='+lender_required_flag+'&type=ZIP';
                        window.open(url);
             }
             

             //退回
             function back(){   
                 var contract_id = $('con555_detail_ds').getCurrentRecord().get('contract_id');
                 new Leaf.Window({
                     id:'con_contract_credit_back_msg_win',
                     url:$('con_contract_credit_back_msg_link').getUrl(),
                     params:{
                         winId:'con_contract_credit_back_msg_win',
                         contract_id:contract_id
                     },
                     width:500,
                     height:300
                 });
                 
                 // new Leaf.showConfirm('提示','您确定退回该合同？',(function(){
                     // var contract_id = $('con555_detail_ds').getCurrentRecord().get('contract_id');
					 // Leaf.request({
		                // url: $('contract_credit_back_link').getUrl(),
		                // para: {contract_id:contract_id},
		                // success: function(res) {
		                    // Leaf.SideBar.show({
                                    // msg: '退回成功',
                                    // duration: 2000
                                // });
                           // con555_con_contract_back();
		                // },
		                // scope: this
		            // });
                 // }));             
             }
             
             function approve(){
                 new Leaf.showConfirm('提示','您确定审核通过？',(function(){
                     var contract_id = $('con555_detail_ds').getCurrentRecord().get('contract_id');
					 Leaf.request({
		                url: $('contract_credit_confirm_link').getUrl(),
		                para: {contract_id:contract_id},
		                success: function(res) {
		                    Leaf.SideBar.show({
                                    msg: '确认成功',
                                    duration: 2000
                                });
                           con555_con_contract_back();
		                },
		                scope: this
		            });
                 }));
             }
             function reject(){
                new Leaf.showConfirm('<font color="RED">警告</font>','<font color="RED">该合同将被拒绝，无法进行后续签约等操作，您确定？</font>',(function(){
					var contract_id = $('con555_detail_ds').getCurrentRecord().get('contract_id');
					 Leaf.request({
		                url: $('contract_credit_reject_link').getUrl(),
		                para: {contract_id:contract_id},
		                success: function(res) {
		                    Leaf.SideBar.show({
                                    msg: '拒绝成功',
                                    duration: 2000
                                });
                           con555_con_contract_back();
		                },
		                scope: this
		            });
				}));
             }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con555_detail_ds" autoQuery="true" fetchAll="true" model="cont.CON544.con_contract_for_query" queryUrl="${/request/@context_path}/autocrud/cont.CON544.con_contract_for_query/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="contract_id"/>
                    <a:field name="contract_number" readOnly="true"/>
                    <a:field name="bp_name" readOnly="true"/>
                    <a:field name="signing_date" readOnly="true"/>
                    <a:field name="signing_location" readOnly="true"/>
                    <a:field name="contract_status_desc" readOnly="true"/>
                    <a:field name="project_number" readOnly="true"/>
                    <a:field name="show_info" readOnly="true"/>
                    <a:field name="note_info" readOnly="true"/>
                    <a:field name="comment_text" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con555_detail_result1_ds" autoQuery="true" model="cont.CON544.con_content_query_detail_1" pageSize="8" queryUrl="${/request/@context_path}/autocrud/cont.CON544.con_content_query_detail_1/query?contract_id=${/parameter/@contract_id}" selectable="true">
                <a:fields>
                    <a:field name="document_table" defaultValue="CON_CONTRACT_CREDIT"/>
                    <a:field name="paper_required" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="sign_required_flag" checkedValue="Y" readOnly="true" uncheckedValue="N"/>
                    <a:field name="paper_required" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="attachment_required" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="sys_flag" defaultValue="N"/>
                    <a:field name="document_id" defaultValue="${/parameter/@contract_id}"/>
                    <a:field name="cdd_list_id" defaultValue="${/parameter/@cdd_list_id}"/>
                    <a:field name="note"/>
                    <a:field name="note2"/>
                    <a:field name="note3"/>
                    <a:field name="note4"/>
                    <a:field name="note5"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="con555_con_contract_back" text="返回"/>
                <!-- <a:gridButton click="con555_con_contract_sign" text="信审通过"/> -->
                <a:gridButton click="back" text="退回"/>
                <a:gridButton click="approve" text="通过"/>
                <!-- <a:gridButton click="reject" text="拒绝"/> -->
            </a:screenTopToolbar>
            <a:form labelWidth="100" title="基础信息" width="1300">
                <a:hBox labelWidth="100">
                    <a:textField name="contract_number" bindTarget="con555_detail_ds" prompt="合同编号"/>
                    <a:lov name="bp_name" bindTarget="con555_detail_ds" prompt="承租人名称"/>
                    <!-- <a:label name="project_number" bindTarget="con555_detail_ds" prompt="项目号" renderer="project_number_render" style="text-decoration:underline;font-weight:blod"/> -->
                    <a:textField name="signing_location" bindTarget="con555_detail_ds" prompt="签约地点"/>
                    <a:datePicker name="signing_date" bindTarget="con555_detail_ds" prompt="签约时间"/>
                    <a:textField name="show_info" bindTarget="con555_detail_ds" prompt="信审合同类型"/>
                </a:hBox>
            </a:form>
            <a:switch test="/model/get_sub_condition/record/@flag">
                <a:case value="Y">
                    <a:form column="4" labelWidth="100" title="附条件信息" width="1300">
                        <a:textField name="comment_text" bindTarget="con555_detail_ds" prompt="审批信息" width="500"/>
                    </a:form>
                </a:case>
            </a:switch>
            <a:tabPanel width="1300">
                <a:tabs>
                    <a:tab prompt="信审附件">
                        <a:grid bindTarget="con555_detail_result1_ds" height="280" navBar="true" width="1295">
                            <a:toolBar>
                                <a:button type="add"/>
                                <a:button type="save"/>
                                <a:button type="delete"/>
                                <a:button click="download1" icon="${/request/@context_path}/images/download.png" text="打包下载"/>
                            </a:toolBar>
                            <a:columns>
                                <a:column name="description" editor="con555_cdd_tf_id1" lock="true" prompt="HLS.DOCUMENT_NAME" renderer="con555_cdd_required_render" width="200"/>
                                <a:column name="attachment" align="center" lock="true" prompt="附件" renderer="con555_cdd_attachment_render" width="60"/>
                                <a:column name="file_name" align="center" lock="true" prompt="附件名" renderer="con555_link_render" width="400"/>
                                <a:column name="note" editor="con555_cdd_tf_id1" prompt="审核意见1" width="200"/>
                                <a:column name="note2" editor="con555_cdd_tf_id1" prompt="审核意见2" width="200"/>
                                <a:column name="note3" editor="con555_cdd_tf_id1" prompt="审核意见3" width="200"/>
                                <a:column name="note4" editor="con555_cdd_tf_id1" prompt="审核意见4" width="200"/>
                                <a:column name="note5" editor="con555_cdd_tf_id1" prompt="审核意见5" width="200"/>
                            </a:columns>
                            <a:editors>
                                <a:textField id="con555_cdd_tf_id1"/>
                            </a:editors>
                        </a:grid>
                    </a:tab>
                </a:tabs>
            </a:tabPanel>
            <!--  </a:form> -->
        </a:screenBody>
    </a:view>
</a:screen>
