<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: xuls  
    $Date: 2016-12-9 下午5:28:34  
    $Revision: 1.0  
    $Purpose:
    $update:ZhuXianfei
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="ccb501_create_doc_link"
                url="${/request/@context_path}/modules/ccb/ccb501/ccb_manual_doc_create.lsc"/>
        <a:link id="init_abc_inteface_link" model="ccb.ccb501.ds_abc_trans_update" modelaction="insert"/>
        <a:link id="ds_abc_trans_link"
                url="${/request/@context_path}/modules/ccb/ccb501/ccb_abc_transaction_detail.lview"/>
        <script type="text/javascript"><![CDATA[
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            var param = {};
            var saveData = [];
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_cashflow');
            var cashflows_ds = $(ds_id);
            var records = cashflows_ds.getSelected();
            if (records.length == 0) {
                Leaf.showMessage('${l:PROMPT}', '请选择需要生成代扣单的记录');
                return;
            }
            Leaf.showConfirm('${l:PROMPT}', '是否确定生成代扣单?', function () {
                var detail_mask = Ext.getBody();
                Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                for (var i = 0; i < records.length; i++) {
                    var record = records[i];
                    saveData.push({
                        'manual_rec_amount': record.get('manual_rec_amount'),
                        'contract_id': record.get('contract_id'),
                        'cashflow_id': record.get('cashflow_id'),
                        '_status': 'insert'
                    });
                }
                param['details'] = saveData;
                Leaf.request({
                    url: $('ccb501_create_doc_link').getUrl(),
                    para: param,
                    success: function () {
                        Leaf.SideBar.show({
                            msg: '${l:HLS.SUBMIT_SUCCESS}',
                            duration: 2000
                        });
                        cashflows_ds.query(cashflows_ds.currentPage);
                        Leaf.Masker.unmask(detail_mask);
                    },
                    failure: function () {
                        Leaf.Masker.unmask(detail_mask);
                    },
                    error: function () {
                        Leaf.Masker.unmask(detail_mask);
                    },
                    scope: this
                });
            });

        };


        //生成农行扣款文件
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_cashflow');
            var cashflows_ds = $(ds_id);
            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            Leaf.request({
                url: $('init_abc_inteface_link').getUrl(),
                para: {
                    'session_id': '${/session/@session_id}',
                    'user_id': '${/session/@user_id}'
                },
                success: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                    open_csh_trans_detail(cashflows_ds);
                },
                failure: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                error: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                scope: this
            });

        };

        function open_csh_trans_detail(cashflows_ds) {

            var win = new Leaf.Window({
                id: 'ds_abc_trans_link_winId',
                url: $('ds_abc_trans_link').getUrl(),
                params: {
                    winId: 'ds_abc_trans_link_winId'
                },
                title: '生成代扣数据',
                fullScreen: true
            });
            win.on('close', function () {
                cashflows_ds.query(cashflows_ds.currentPage);

            });
        }


        //导入农行回盘文件
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {
            var param = {};
            var saveData = [];
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_cashflow');
            var cashflows_ds = $(ds_id);
            var records = cashflows_ds.getSelected();
            if (records.length == 0) {
                Leaf.showMessage('${l:PROMPT}', '请选择需要生成代扣单的记录');
                return;
            }
            Leaf.showConfirm('${l:PROMPT}', '是否确定生成代扣单?', function () {
                /*  var detail_mask = Ext.getBody();
                 Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                 for (var i = 0; i < records.length; i++) {
                 var record = records[i];
                 saveData.push({
                 'manual_rec_amount': record.get('manual_rec_amount'),
                 'contract_id': record.get('contract_id'),
                 'cashflow_id': record.get('cashflow_id'),
                 '_status': 'insert'
                 });
                 }
                 param['details'] = saveData;
                 Leaf.request({
                 url: $('ccb501_create_doc_link').getUrl(),
                 para: param,
                 success: function () {
                 Leaf.SideBar.show({
                 msg: '${l:HLS.SUBMIT_SUCCESS}',
                 duration: 2000
                 });
                 cashflows_ds.query(cashflows_ds.currentPage);
                 Leaf.Masker.unmask(detail_mask);
                 },
                 failure: function () {
                 Leaf.Masker.unmask(detail_mask);
                 },
                 error: function () {
                 Leaf.Masker.unmask(detail_mask);
                 },
                 scope: this
                 });*/
            });
        };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>