<?xml version="1.0" encoding="UTF-8"?>
<!--
   create by xuls 
    for prj&con ata sign
    2014-10-15
 -->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query model="cont.CON544.prj_con_sign_lv" rootPath="con544_wfl_document_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_uploadfile" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="con544_contract_sign_save_date" model="cont.CON544.con_contract_sign_save_date" modelaction="execute"/>
        <a:link id="con544_batch_down_link" url="${/request/@context_path}/modules/batch_download/lease_atm_batch_dl.lsc"/>
        <a:link id="con544_submit_link" model="cont.CON544.lsh_prj_con_sign_submit" modelaction="execute"/>
        <a:link id="con544_cdd_uploadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="wfl_con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="wfl_con_contract_modify_link" url="${/request/@context_path}/modules/cont/CON501N/con_contract_modify.lview"/>
        <a:link id="wfl_prj_project_modify_link" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_create_tree_n.lview"/>
        <script type="text/javascript"><![CDATA[
    		/*链接单据明细*/    
    		function wfl_open_project_modify_win(record_id, ds_id) {
                var record = $(ds_id).findById(record_id);
                var maintain_type = 'UPDATE';
                var param = record.data;
                param['declare_flag'] = 'Y';
                param['document_id'] = ${/parameter/@document_id};
                param['function_code'] = 'PRJ502';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = maintain_type;
                param['company_id'] = '${/session/@company_id}';
                param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
                hls_doc_get_layout_code('wfl_con_contract_get_layout_code_link_id', param, 'wfl_prj_project_modify_link');
            }
            
            function wfl_open_contract_win(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
                param['document_id'] = ${/parameter/@document_id};
                param['function_code'] = 'CON301';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'UPDATE';
                param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
                hls_doc_get_layout_code('wfl_con_contract_get_layout_code_link_id', param, 'wfl_con_contract_modify_link', ds_id);
            }
    		
    		/**/
            
            function con544_detail_close() {
                $('con544_sign_detail_id').close();
            }
            
            function con544_detail_save() {
                if($('con544_sign_atm_header_ds').validate()) {
                    var url= $('con544_contract_sign_save_date').getUrl();
                    $('con544_sign_atm_header_ds').setSubmitUrl(url);
                    $('con544_sign_atm_header_ds').setSubmitParameter('signing_date',$('con544_sign_atm_header_ds').getCurrentRecord().get('signing_date'));
                    $('con544_sign_atm_header_ds').setSubmitParameter('document_id',${/parameter/@document_id});
                    $('con544_sign_atm_header_ds').submit();
                    $('con544_sign_atm_detail_ds').submit();
                }
                
            }
            
            function submit_confirm() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                var document_id=${/parameter/@document_id};
                var document_table='${/parameter/@document_table}';
                Leaf.request({
                    url: $('con544_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(){
                          con544_detail_close();  
                        });
                        
                    },
                    failure: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });
            }
            
            function con544_detail_submit(){
                Leaf.showConfirm('提示','确认提交审批?',submit_confirm,function(){});
            }
            
            function con544_sign_atm_detail_query(){
                $('con544_sign_atm_detail_ds').query();
            }
            
            /*
             附件批量下载
             */
            function con44_batch_down() {
                var document_id = ${/parameter/@document_id};
                var document_table = '${/parameter/@document_table}';
                var document_number ='${/parameter/@document_number}';
                var url = $('con544_batch_down_link').getUrl()+'?table_name='+document_table+'&table_pk_value=' + document_id + '&doc_code=' + document_number;
                window.open(url);
            }
            function con544_cdd_editorFunction(record, name) {
                if (record.get('sys_flag') == 'N') {
                    return 'con544_cdd_tf_id';
                }
                return '';
            }
            
           function con544_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;
                }
            }
            function con544_cdd_attachtment_upload(check_id, file_name, record_id) {
                //
                var url = $('con544_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + check_id;
                
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'con544_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });
                win.on('close', function() {
                	con544_sign_atm_detail_query();           
                });
            }
            function detail_upload_window(record_id) {
        	 
        	    var url = $('con_contract_uploadfile').getUrl() + '?table_name=CON_CONTRACT_CONTENT_SIGN&header_id=' + record_id;
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'insurance_records_uploadFile_id',
                    width: 850,
                    height: 400
                });
                win.on('close', function() {
                     $('con544_sign_atm_detail_ds').query();
                });
        	} 
            
           function attachment_upload(val,rec,name) {
        	    return '<a href=javascript:detail_upload_window('+rec.get('content_id')+')>附件查看</a>';
        	}
            
             function con544_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 con544_detail_add(){
                 $('con544_sign_detail_gd').showEditorByRecord($('con544_sign_atm_detail_ds').create());
            }
            function con544_detail_delete(){
                 $('con544_sign_detail_gd').remove();
            }
            function con544_cdd_selectFunc(record) {
                if (record.get('sys_flag') == 'Y') {
                    return false;
                }
                return true;
            }
            function con544_detail_document_link(value,record,name){
                var document_table = '${/parameter/@document_table}';

                if (document_table == 'CON_CONTRACT' && value) {
                    return '<a href="javascript:wfl_open_contract_win(\''+record.ds.id+'\',\''+record.id+'\')">'+value+'</a>';
                }else if(document_table=='PRJ_PROJECT' &&value){
                    return '<a href="javascript:wfl_open_project_modify_win(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
                }
                return value;
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="adjust_rate_type_ds" lookupCode="ADJUST_RATE_TYPE"/>
            <a:dataSet id="con544_sign_atm_header_ds">
                <a:datas dataSource="/model/con544_wfl_document_info"/>
                <a:fields>
                    <a:field name="document_number" defaultValue="${/parameter/@document_number}" readOnly="true"/>
                    <a:field name="contract_name" readOnly="true"/>
                    <a:field name="signing_date" datatype="java.util.Date" readOnly="true"/>
                    <a:field name="adjust_rate_type_desc" displayField="code_value_name" options="adjust_rate_type_ds" readOnly="true" returnField="adjust_rate_type" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con544_sign_atm_detail_ds" autoPageSize="true" autoQuery="true" model="cont.CON544.con_contract_sign_detail_for_nanshan" queryUrl="${/request/@context_path}/autocrud/cont.CON544.con_contract_sign_detail_for_nanshan/query?contract_id=${/parameter/@document_id}" selectFunction="con544_cdd_selectFunc" selectable="true">
                <a:fields>
                    <a:field name="document_table" defaultValue="${/parameter/@document_table}"/>
                    <a:field name="sys_flag" defaultValue="N"/>
                    <a:field name="document_id" defaultValue="${/parameter/@document_id}"/>
                    <a:field name="cdd_list_id" defaultValue="${/parameter/@cdd_list_id}"/>
                    <a:field name="send_date" datatype="java.util.Date"/>
                    <a:field name="receive_date" datatype="java.util.Date"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:form column="3" marginWidth="30" title="附件信息">
                <a:label name="document_number" bindTarget="con544_sign_atm_header_ds" prompt="单据编号" renderer="con544_detail_document_link"/>
                <a:textField name="contract_name" bindTarget="con544_sign_atm_header_ds" prompt="合同名称"/>
                <a:numberField name="lease_item_amount" bindTarget="con544_sign_atm_detail_ds" prompt="租赁物金额" readOnly="true"/>
                <a:datePicker name="signing_date" bindTarget="con544_sign_atm_header_ds" prompt="签约日期"/>
                <a:comboBox name="adjust_rate_type_desc" bindTarget="con544_sign_atm_header_ds" prompt="调息类型"/>
            </a:form>
            <a:grid id="con544_sign_detail_gd" bindTarget="con544_sign_atm_detail_ds" marginHeight="250" marginWidth="38" navBar="true">
                <a:columns>
                    <a:column name="description" prompt="HLS.DOCUMENT_NAME" width="200"/>
                    <a:column name="tax_type_rate" align="right" prompt="印花税率" width="100"/>
                    <a:column name="stamp_tax" align="right" prompt="印花税" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="attachment" align="center" prompt="附件" renderer="attachment_upload" width="60"/>
                    <a:column name="file_name" align="center" prompt="附件名" renderer="con544_link_render" width="400"/>
                    <a:column name="ref_v01" prompt="备注" width="300"/>
                    <!-- <a:column name="note1" editor="con544_cdd_tf_id" prompt="初审意见" width="300"/>
                    <a:column name="note2" editor="con544_cdd_tf_id" prompt="复审意见" width="300"/>
                    <a:column name="express_number" editor="con544_cdd_tf_id" prompt="快递单号"/>
                    <a:column name="send_date" editor="con544_cdd_dated_id" prompt="寄送日期"/>
                    <a:column name="receive_date" editor="con544_cdd_dated_id" prompt="收到日期"/> -->
                </a:columns>
                <a:editors>
                    <a:datePicker id="con544_cdd_dated_id"/>
                    <a:checkBox id="con544_cdd_ck_id"/>
                    <a:textField id="con544_cdd_tf_id"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
        <script type="text/javascript"><![CDATA[

        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
