<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangyu  
    $Date: 2015-12-19 下午19:17:13  
    $Revision: 1.0  
    $Purpose: 资金计划平衡头表(季度)
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="sdic2020_quarter_rpt_link" url="${/request/@context_path}/modules/sdic/SDIC2020/sdic_fin_plan_rpt_quarter_ln.lview"/>
        <a:link id="sdic2020_attach_upload_link" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="sdic2020_submit_link" model="sdic.SDIC2020.sdic_fin_plan_rpt_quarter_hd" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
            function sdic2020_result_hd_grid_add() {
                $('sdic2020_result_hd_ds').create();
            }
            
            function delete_result_hd() {
                Leaf.showConfirm('提示', '是否确认删除', function() {
                    var records = $('sdic2020_result_hd_ds').getSelected();
                    for (var i = 0;i < records.length;i++) {
                        var approval_status = records[i].get('status');
                        if (approval_status != 'NEW') {
                            Leaf.showMessage('${l:PROMPT}', '新建的报表才允许删除！');
                            return;
                        }
                        $('sdic2020_result_hd_ds').remove(records[i]);
                    }
                });
            }
            
            function sdic2020_result_hd_query() {
                $('sdic2020_result_hd_ds').query();
            }
            
            function rpt_create(hd_id) {
                new Leaf.Window({
                    id: 'sdic2020_quarter_rpt_winid',
                    url: $('sdic2020_quarter_rpt_link').getUrl(),
                    params: {
                        hd_id: hd_id,
                        win_id: 'sdic2020_quarter_rpt_winid'
                    },
                    title: '集团资金计划基础表（月度）',
                    fullScreen: true
                });
            }
            
            function ln_detail(value, record, name) {
                if (record.isNew) {
                    return '';
                } else {
                    return '<a href="javascript:rpt_create(' + value + ');">' + '生成报表' + '</a>';
                }
            }
            
            function atm_upload_renderer(value, record, name) {
                if (!Ext.isEmpty(record.get('hd_id'))) {
                    return '<a href="javascript:atm_upload_win(' + record.get('hd_id') + ')">' + '报表上传' + '</a>';
                }
            }
            
            function atm_upload_win(hd_id) {
                var url = $('sdic2020_attach_upload_link').getUrl() + '?table_name=SDIC_FIN_PLAN_RPT_QUARTER_HD&header_id=' + hd_id;
                new Leaf.Window({
                    url: url,
                    title: '${l:TRE510.ATTACHMENT_UPLOAD}',
                    id: 'sdic2020_fin_plan_rpt_quarter_win',
                    width: 850,
                    height: 400
                });
            }
            
            function editorFunc(record, name) {
                if (name == 'plan_year_n') {
                    if (record.isNew) {
                        return 'hd_editor_lov';
                    }
                    return '';
                }
            }
            
            function sdic2020_submit() {
                var records = $('sdic2020_result_hd_ds').getSelected();
                if (records.length < 1) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一张报表！');
                    return;
                }
                if (records.length > 1) {
                    Leaf.showMessage('${l:PROMPT}', '一次仅能提交一张报表！');
                    return;
                }
                if (records[0].get('status') != 'NEW') {
                    Leaf.showMessage('${l:PROMPT}', '只有新建状态的报表才能提交！');
                    return;
                }
                Leaf.showConfirm('提示', '确定提交吗？', function() {
                    Leaf.request({
                        url: $('sdic2020_submit_link').getUrl(),
                        para: {
                            hd_id: records[0].get('hd_id')
                        },
                        success: function(res) {
                            Leaf.Masker.unmask(Ext.getBody()); //解锁
                            $('sdic2020_result_hd_ds').query();
                        },
                        failure: function() {
                            Leaf.Masker.unFmask(Ext.getBody());
                        },
                        error: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
                });
            }
            
            function sdic2020_result_hd_grid_id_ave(){
                  var ds = $( 'sdic2020_result_hd_ds');
                if (ds.validate()) {
                    ds.submit();
                }
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="sdic2020_result_hd_ds" autoPageSize="true" autoQuery="true" model="sdic.SDIC2020.sdic_fin_plan_rpt_quarter_hd" selectable="true">
                <a:fields>
                    <a:field name="plan_year_n" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="tre.TRE1010.sdic_fin_plan_base_data_lov?plan_frequency=QUARTERLY" lovWidth="500" required="true" title="基础数据">
                        <a:mapping>
                            <a:map from="data_id" to="data_id"/>
                            <a:map from="plan_year" to="plan_year"/>
                            <a:map from="plan_year_n" to="plan_year_n"/>
                            <a:map from="plan_month" to="plan_month"/>
                            <a:map from="plan_month_n" to="plan_month_n"/>
                            <a:map from="plan_frequency" to="plan_frequency"/>
                            <a:map from="plan_frequency_n" to="plan_frequency_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="plan_month_n" readOnly="true"/>
                    <a:field name="plan_frequency_n" readOnly="true"/>
                    <a:field name="status" defaultValue="NEW"/>
                    <a:field name="status_n" defaultValue="新建" displayField="code_value_name" options="status_ds" returnField="status" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="sdic2020_result_hd_grid_add" text="HLS.NEW"/>
                <a:gridButton bind="sdic2020_result_hd_grid_id" type="save"/>
                <a:gridButton click="sdic2020_result_hd_grid_id_ave" text="保存"/>
                <a:gridButton click="delete_result_hd" text="删除"/>
                <a:gridButton click="sdic2020_result_hd_query" text="HLS.QUERY"/>
                <a:gridButton click="sdic2020_submit" text="提交审批"/>
            </a:screenTopToolbar>
            <a:form/>
            <a:grid id="sdic2020_result_hd_grid_id" bindTarget="sdic2020_result_hd_ds" marginHeight="200" marginWidth="200" navBar="true">
                <a:columns>
                    <a:column name="plan_year_n" align="center" editorFunction="editorFunc" prompt="年份" width="100"/>
                    <a:column name="plan_month_n" align="center" prompt="月份" width="100"/>
                    <a:column name="plan_frequency_n" align="center" prompt="频率" width="100"/>
                    <a:column name="description" editor="hd_editor_tf" prompt="说明" width="300"/>
                    <a:column name="status_n" align="center" prompt="状态" width="100"/>
                    <a:column name="hd_id" align="center" prompt="生成报表" renderer="ln_detail" width="100"/>
                    <a:column name="attachment_id" align="center" prompt="报表上传" renderer="atm_upload_renderer" width="100"/>
                </a:columns>
                <a:editors>
                    <a:lov id="hd_editor_lov"/>
                    <a:textField id="hd_editor_tf"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
