<?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="con301n_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>-->
        <a:link id="con301n_downloadFile_id" url="${/request/@context_path}/modules/cont/CON301N/con_downfile.lsc"/>
        <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"/>
        <a:link id="con_cashflow_print_link"
                url="${/request/@context_path}/modules/cont/CON620/create_content_for_collection.lsc"/>
        <a:link id="con_cashflow_print_signatures_link"
                url="${/request/@context_path}/modules/cont/CON620/create_content_for_collection_signatures.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_word_create() {
            debugger;
            Leaf.Masker.mask(Ext.getBody(), '请稍等......');
            var contract_id = '${/parameter/@contract_id}';
            var templet_code = '${/parameter/@templet_code}';
            var bp_name = '${/parameter/@bp_name}';
            var contract_number = '${/parameter/@contract_number}';
            var contract_name = '${/parameter/@contract_name}';
            var file_name  = '催收函-'+ bp_name;
            Leaf.request({
                url: $('con_cashflow_print_link').getUrl(),
                para: {
                    contract_id : contract_id,
                    contract_number : contract_number,
                    contract_name : contract_name,
                    templet_code : templet_code,
                    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 templet_code = '${/parameter/@templet_code}';
            var bp_name = '${/parameter/@bp_name}';
            var contract_number = '${/parameter/@contract_number}';
            var contract_name = '${/parameter/@contract_name}';
            var file_name  = '催收函'+ bp_name ;
            Leaf.request({
                url: $('con_cashflow_print_signatures_link').getUrl(),
                para: {
                    contract_id : contract_id,
                    contract_number : contract_number,
                    contract_name : contract_name,
                    templet_code : templet_code,
                    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() {
            // });

            var url = $('con301n_downloadFile_id').getUrl() + '?record_id=' + record_id + '&table_name=CUX_CONTRACT_PRINT';
            window.open(url, '_self');

        }

        ]]></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.CON620.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_word_create" text="生成催收函Word"/>
                    <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="user_name" prompt="打印人" width="160"/>
                    <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>
