<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wutuansen  
    $Date: 2018-12-20 上午9:30:25  
    $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><![CDATA[
    ]]></a:init-procedure>
    <a:view>
        <a:link id="rpt5010_print_link_id" model="rpt.RPT5010.rpt5010_print" modelaction="update"/>
        <a:link id="rpt5010_run_job_link_id" model="rpt.RPT5010.rpt5010_print" modelaction="execute"/>
        <script><![CDATA[
            function rpt5110_reset() {
                $('rpt5110_query_ds').reset();
            }
            
            function ref_n01_time(record, name, value) {
                var reg = /^\d\d\d\d\d\d$/;
                if (reg.test(value)) {
                    return true;
                }
                return '时间格式应为【yyyymm】,举例【201812】';
            }
            
            function rpt5110_print() {
                debugger;
                Leaf.Masker.mask(Ext.getBody(), '${l:BEING_IMPLEMENTED}');
                var record = $('rpt5110_query_ds').getAt(0);
                if (!record) {
                    Leaf.Masker.unmask(Ext.getBody());
                    Leaf.showMessage('${l:PROMPT}', '年月未填写');
                    return;
                }
                var month = record.get('month');
                if (!month) {
                    Leaf.Masker.unmask(Ext.getBody());
                    Leaf.showMessage('${l:PROMPT}', '年月未填写');
                    return;
                }
            
                // var reg = /^\d\d\d\d\d\d$/;
                // if (reg.test(month)) {
                // } else {
                // Leaf.Masker.unmask(Ext.getBody());
                // Leaf.showMessage('${l:PROMPT}', '时间格式应为【yyyymm】,举例【201812】');
                // return;
                // }
                Leaf.request({
                    url: $('rpt5010_print_link_id').getUrl(),
                    para: {
                        month: month
                    },
                    success: function(res) {
                        var days = res.result.days;
                        Leaf.Masker.unmask(Ext.getBody());
                        var url = '${/request/@context_path}/modules/rpt/RPT5010/export_excel_sheets' + days + '.lsc?month=' + month + '&file_name=' + month + '每日合同未收本金表.xls';
                        window.open(encodeURI(url), '_self');
                    },
                    error: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    failure: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });
            
            
            }
            
            function rpt5110_run_job() {
                Leaf.showConfirm('${l:HLS.PROMPT}', '<font color="red">该任务需执行约1小时,请耐心等待!</font></br></br><font color="red">【特别注意】任务发起后1小时内请勿重复点击</font>', function() {
                    Leaf.Masker.mask(Ext.getBody(), '${l:BEING_IMPLEMENTED}');
                    Leaf.request({
                        url: $('rpt5010_run_job_link_id').getUrl(),
                        para: {},
                        success: function(res) {
                            Leaf.Masker.unmask(Ext.getBody());
                            Leaf.SideBar.show({
                                msg: '发起成功!',
                                duration: 2000
                            });
                        },
                        error: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        failure: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
                }, null, 300, 150);
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="four_month_date_ds" loadData="true" model="rpt.RPT5010.rpt5010_four_month"/>
            <a:dataSet id="rpt5110_query_ds">
                <a:fields>
                    <a:field name="month"/>
                    <a:field name="month_desc" displayField="value_name" options="four_month_date_ds" required="true" returnField="month" valueField="value_code"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="rpt5110_print" text="打印"/>
                <a:gridButton click="rpt5110_reset" text="HLS.RESET"/>
<!--                <a:gridButton click="rpt5110_run_job" text="发起校准任务"/>-->
            </a:screenTopToolbar>
            <a:form Width="250" column="1" labelWidth="100" title="条件" width="300">
                <a:comboBox name="month_desc" bindTarget="rpt5110_query_ds" prompt="年月"/>
            </a:form>
        </a:screenBody>
    </a:view>
</a:screen>