<?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.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 package="leaf.ui.std" template="default">
        <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.CON543.con_content_query_detail/query"/>
        <a:link id="con_contract_sign_link_id" model="cont.CON543.con_contract_save" modelaction="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_law_back_link" model="cont.CON543.contract_law_back_execute" modelaction="execute"/>
        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>
        <script type="text/javascript"><![CDATA[
            
            window['con555_cdd_editorFunction'] = function(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;
            }
            window['con555_cdd_attachment_render'] = function(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:window[\'con555_cdd_attachtment_upload\'](\'' + record.get('check_id') + '\',\'' + file_name + '\',\'' + record_id + '\')">${l:HLS.ATTACHMENT}</a>';
                }
            };
            
            window['con555_link_render'] = function(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] + ' ref="img">' + temp[0] + '</a>' + ',';
                        }
                    }
                    return url;
                }
            };
            
            window['con555_cdd_attachtment_upload'] = function(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_result_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_result_ds').query();
                            $('con555_detail_result1_ds').query();
            
                            //var newvalue = $('con555_detail_result_ds').findById(record_id).get('file_name');
                        },
                        sync: true
                    });
                });
            
            };
            window['con555_cdd_required_render'] = function(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_result_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_attach_update(ds, record, value, oldvalue, newvalue) {
            // // alert('con555_attach_update');
            // }
            
            // function con555_attach_query(ds) {
            // alert('con555_attach_refresh');
            // }
            
            function con555_con_contract_query() {
                $('con555_detail_result_ds').query();
            }
            
            function con555_con_contract_reset() {
                $('con555_detail_ds').reset();
            }
            
            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() {
                        //
                        var contract_id = record.get('contract_id');
                        var contract_number = record.get('contract_number');
                        var contractno = record.get('contractno');
                        var lease_channel = record.get('lease_channel');
                        var signing_location = record.get('signing_location');
                        // var url = '${/request/@context_path}/modules/inf/INF501/ali_confirm_done.lsc?contract_id='+contract_id+'&contractno='+contractno+'&contract_number='+contract_number+'&signing_location='+signing_location;
            
                        Leaf.request({
                            url: $('con_contract_sign_link_id').getUrl(),
                            para: {contract_id:contract_id},
                            success: function() {
                                Leaf.SideBar.show({
                                    msg: '审核成功',
                                    duration: 2000
                                });
                                con555_con_contract_back();
                            },
                            failure: function() {
                                Leaf.showMessage('提示', '合同审核失败,请重新审核该合同!');
                            },
                            scope: this
            
                        }, function() {
                            return;
                        }, null, 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 download() {
                        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 = 'N';
                        var lender_display_flag = 'N';
                        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() {
                        new Leaf.showConfirm('提示', '您确定退回该合同?', (function() {
                            var contract_id = $('con555_detail_ds').getCurrentRecord().get('contract_id');
                            Leaf.request({
                                url: $('contract_law_back_link').getUrl(),
                                para: {
                                    contract_id: contract_id
                                },
                                success: function(res) {
                                    Leaf.SideBar.show({
                                        msg: '退回成功',
                                        duration: 2000
                                    });
                                    con555_con_contract_back();
                                },
                                scope: this
                            });
                        }));
                    }
                     Ext.ux.Lightbox.register('a[ref=img]',true);
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con555_detail_ds" autoQuery="true" fetchAll="true" model="cont.CON543.con_contract_for_query" queryUrl="${/request/@context_path}/autocrud/cont.CON543.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="zero_times_date" 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="note_law" readOnly="true"/>
                    <a:field name="contractno" readOnly="true"/>
                    <a:field name="lease_channel" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con555_detail_result_ds" autoQuery="true" model="cont.CON543.con_content_query_detail" pageSize="8" queryUrl="${/request/@context_path}/autocrud/cont.CON543.con_content_query_detail/query?contract_id=${/parameter/@contract_id}" selectFunction="con555_cdd_selectFunc" selectable="true">
                <a:fields>
                    <a:field name="document_table" defaultValue="CON_CONTRACT"/>
                    <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="back" text="合同退回"/>
                <a:gridButton click="con555_con_contract_sign" text="通过审核"/>
            </a:screenTopToolbar>
            <a:form labelWidth="120" marginWidth="30" title="基础信息">
                <a:hBox labelWidth="120">
                    <a:textField name="contract_number" bindTarget="con555_detail_ds" prompt="合同编号"/>
                    <a:textField name="contract_status_desc" bindTarget="con555_detail_ds" prompt="合同状态"/>
                    <a:lov name="bp_name" bindTarget="con555_detail_ds" prompt="承租人名称"/>
                    <a:datePicker name="signing_date" bindTarget="con555_detail_ds" prompt="签约时间"/>
                    <a:textField name="signing_location" 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:hBox>
            </a:form>
            <a:form marginWidth="30" title="附件信息">
                <a:grid bindTarget="con555_detail_result_ds" height="300" marginWidth="38" navBar="true">
                    <a:toolBar>
                        <a:button type="add"/>
                        <a:button type="save"/>
                        <a:button type="delete"/>
                        <a:button click="download" icon="${/request/@context_path}/images/download.png" text="打包下载"/>
                    </a:toolBar>
                    <a:columns>
                        <a:column name="description" editorFunction="con555_cdd_editorFunction" 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="tex_area_e" prompt="审核意见1" width="200"/>
                        <a:column name="note2" editor="tex_area_e" prompt="审核意见2" width="200"/>
                        <a:column name="note3" editor="tex_area_e" prompt="审核意见3" width="200"/>
                        <a:column name="note4" editor="tex_area_e" prompt="审核意见4" width="200"/>
                        <a:column name="note5" editor="tex_area_e" prompt="审核意见5" width="200"/>
                    </a:columns>
                    <a:editors>
                        <a:checkBox id="con555_cdd_ck_id"/>
                        <a:textField id="con555_cdd_tf_id"/>
                        <a:textArea id="tex_area_e" height="100" width="300"/>
                    </a:editors>
                </a:grid>
            </a:form>
        </a:screenBody>
    </a:view>
</a:screen>