<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ZLF  
    $Date: 2014-11-20 下午8:50:38  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" customizationEnabled="true"
          trace="true">
    <a:init-procedure>
        <s:server-script import="con_print_path.js"><![CDATA[
            set_parameter_file_path();
        ]]></s:server-script>
        <a:model-query model="cont.CON620.get_sys_role" rootPath="role_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_content_asset_detail_link_id"
                url="${/request/@context_path}/modules/cont/CON505/con_contract_content_asset_detail.lview"/>
        <a:link id="con_doc_batch_create_link_id"
                url="${/request/@context_path}/modules/cont/CON500/con_doc_batch_create.lsc"/>
        <a:link id="con301n_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="con301n_print_excel_link"
                url="${/request/@context_path}/modules/cont/CON301N/con_contract_print_atm.lsc"/>
        <a:link id="con301n_print_pdf_link"
                url="${/request/@context_path}/modules/cont/CON301N/con_contract_print_pdf.lsc"/>
        <script type="text/javascript"><![CDATA[


        function lock_current_window() {
            Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
        }

        function unlock_current_window() {
            Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
        }

        function con_print_excel_create() {
            Leaf.Masker.mask(Ext.getBody(), '请稍等......');
            // var file_name = '对账单(' +'${/parameter/@tenant_name}'+'+'+'${/parameter/@contract_number}'+').doc';
            // var file_dir  = '$ctx.parameter.file_path';
            // var contract_id = '${/parameter/@contract_id}';
            // var url;
            // url ='${/request/@context_path}/con/contract/conExportExcel?contractId=' + contract_id;
            // window.open(href = url);
            var contract_id = '${/parameter/@contract_id}';
            var contract_number = '${/parameter/@contract_number}';
            var tenant_name = '${/parameter/@tenant_name}';
            var file_path  = '${/parameter/@file_path}';
            //var file_name  = '对账单('+ tenant_name + '_'+contract_number+').xlsx';
            var file_name  = '对账单('+ tenant_name + '_'+contract_number+')';
            Leaf.request({
                url: $('con301n_print_excel_link').getUrl(),
                para: {
                    contract_id : contract_id,
                    contract_number : contract_number,
                    file_path : file_path,
                    file_name : file_name
                },
                success: function(res) {
                    Leaf.Masker.unmask(Ext.getBody());
                    $('con_contract_print_detail_line_ds').query();
                },
                failure: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                    $('con_contract_print_detail_line_ds').query();
                },
                error: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                    $('con_contract_print_detail_line_ds').query();
                }
            });


        }

        function con_print_signatures_create() {
            Leaf.Masker.mask(Ext.getBody(), '请稍等......');
            var contract_id = '${/parameter/@contract_id}';
            var contract_number = '${/parameter/@contract_number}';
            var tenant_name = '${/parameter/@tenant_name}';
            var file_path  = '${/parameter/@file_path}';
            //var file_name  = '对账单('+ tenant_name + '_'+contract_number+').xlsx';
            var file_name  = '对账单('+ tenant_name + '_'+contract_number+')';
            Leaf.request({
                url: $('con301n_print_pdf_link').getUrl(),
                para: {
                    contract_id : contract_id,
                    contract_number : contract_number,
                    file_path : file_path,
                    file_name : file_name
                },
                success: function(res) {
                    Leaf.Masker.unmask(Ext.getBody());
                    $('con_contract_print_detail_line_ds').query();
                },
                failure: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                    $('con_contract_print_detail_line_ds').query();
                },
                error: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                    $('con_contract_print_detail_line_ds').query();
                }
            });
        }

        function update_attachment_renderer(value, record, name) {
            var content_id = record.get('content_id');
            return '<a href="javascript:open_uploadfile_win(' + content_id + ')">附件</a>';
        }


        function attachment_download(val,rec,name) {
            return '<a href=javascript:detail_download_window('+rec.get('print_id')+')>下载</a>';}

        function detail_download_window(record_id) {
            var url = $('con301n_downloadFile_id').getUrl() + '?table_name=CUX_CONTRACT_PRINT&header_id=' + record_id;
            var win = new Leaf.Window({
                url: url,
                title: '${l:HLS.SUPPORTING_DOCUMENT}',
                id: 'con301n_records_uploadFile_id',
                width: 850,
                height: 400
            });
            win.on('close', function() {
            });
        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="con_contract_update_print_detail_header_ds" autoCreate="true">
                <a:fields>
                    <a:field name="contract_number" defaultValue="${/parameter/@contract_number}" readOnly="true"/>
                    <a:field name="contract_name" defaultValue="${/parameter/@contract_name}" readOnly="true"/>
                </a:fields>

            </a:dataSet>
            <a:dataSet id="con_contract_print_detail_line_ds" autoQuery="true" fetchAll="true" pageSize="100"
                       queryUrl="${/request/@context_path}/autocrud/cont.CON301N.con_statement_of_account_print/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="contract_id"/>
                    <a:field name="content_number" readOnly="true"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <div id="screenTopToolbardiv">
                <a:screenTopToolbar style="width:700px">
                    <a:gridButton id="con_print_id" click="con_print_excel_create" text="生成对账单excel"/>
                    <a:gridButton id="con_print_signatures_id" click="con_print_signatures_create" text="生成对账单PDF"/>
                </a:screenTopToolbar>
                <a:form column="2"  width="700">
                    <a:textField name="contract_number" bindTarget="con_contract_update_print_detail_header_ds"
                                 prompt="HLS.CONTRACT_NUMBER"/>
                    <a:textField name="contract_name" bindTarget="con_contract_update_print_detail_header_ds"
                                 prompt="HLS.CONTRACT_NAME" width="330"/>
                </a:form>
            </div>
            <a:grid id="con_contract_update_print_detail_grid_id" bindTarget="con_contract_print_detail_line_ds"
                    height="350" navBar="true" width="700">
                <a:toolBar>
                    <a:button prompt="PROMPT.EXPORT_EXCEL" type="excel"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="file_name" prompt="文本名称" width="260"/>
                    <a:column name="print_date" prompt="生成日期" width="180"/>
                    <a:column name="download" align="center" prompt="下载" renderer="attachment_download" width="50"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
        <script type="text/javascript"><![CDATA[
        Leaf.onReady(function() {
                if("${/model/role_info/record/@role_code}"!="0018"&&"${/model/role_info/record/@role_code}"!="0019") {
                    document.getElementById("con_print_signatures_id").style.display = "";
                } else {
                    document.getElementById("con_print_signatures_id").style.display = "none";
                }
        });
        ]]></script>
    </a:view>
</a:screen>
