<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:view>
        <a:link id="hsbc_paying_batch_create_link_id" url="${/request/@context_path}/modules/hsbc/HSBC100/hsbc_paying_batch_create.lsc"/>
        <a:link id="hsbc_paying_batch_create_return_link_id" url="${/request/@context_path}/modules/hsbc/HSBC100/hsbc_paying_batch_create_return.lsc"/>
        <a:link id="hsbc_paying_batch_create_manage_link_id" url="${/request/@context_path}/modules/hsbc/HSBC100/hsbc_paying_batch_create_manage.lsc"/>
        <script><![CDATA[
        function create_paying_batch() {
            var winId = '${/parameter/@winId}';
            Leaf.Masker.mask($(winId).wrap, '付款单生成中...');
            var account_ds = $('csh_bank_account');
            var bank_account_id = account_ds.getAt(0).get('bank_account_id');
            if (Ext.isEmpty(bank_account_id)) {
                Leaf.showMessage('提示', '请先选择账户代码!');
                Leaf.Masker.unmask($(winId).wrap);
            } else {
                var req_ln_ds = $('${/parameter/@ds_id}');
                var button_id = '${/parameter/@button_id}';
                var records = req_ln_ds.getSelected();
                var param = {};
                var saveData = [];
                for (var i = 0;i < records.length;i++) {
                    var rec;
                    rec = records[i];
                    rec.set('_status', 'insert');
                    saveData.push(rec.data);
                }
                param['details'] = saveData;
                param['bank_account_id'] = bank_account_id;
                param['button_id'] = button_id;

                var pay_type = '${/parameter/@pay_type}';
                var url;
                if (pay_type == 'TJ'){
                    url = $('hsbc_paying_batch_create_link_id').getUrl();
                }else if(pay_type == 'RETURN'){
                    url = $('hsbc_paying_batch_create_return_link_id').getUrl();
                }else if(pay_type == 'MANAGE'){
                    url = $('hsbc_paying_batch_create_manage_link_id').getUrl();
                }

                Leaf.request({
                    url: url,
                    para: param,
                    success: function() {
                        Leaf.SideBar.show({
                            msg: '付款单生成成功!',
                            duration: 2000
                        });
                        Leaf.Masker.unmask($(winId).wrap);
                        $('${/parameter/@winId}').close();
                        req_ln_ds.query();
                    },
                    failure: function() {
                        Leaf.Masker.unmask($(winId).wrap);
                    },
                    error: function() {
                        Leaf.Masker.unmask($(winId).wrap);
                    },
                    scope: this
                });
            }
        }


        ]]></script>
        <a:dataSets>
            <a:dataSet id="csh_bank_account" autoCreate="true">
                <a:fields>
                    <a:field name="bank_account_id" readOnly="true"/>
                    <a:field name="bank_account_code" lovGridHeight="300" lovHeight="450" lovService="hsbc.HSBC100.csh_bank_account" lovWidth="800" required="true" title="支付账号选择">
                        <a:mapping>
                            <a:map from="bank_account_id" to="bank_account_id"/>
                            <a:map from="bank_account_code" to="bank_account_code"/>
                            <a:map from="bank_short_name" to="bank_short_name"/>
                            <a:map from="bank_branch_name" to="bank_branch_name"/>
                            <a:map from="bank_account_name" to="bank_account_name"/>
                            <a:map from="bank_account_num" to="bank_account_num"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bank_short_name" readOnly="true"/>
                    <a:field name="bank_branch_name" readOnly="true"/>
                    <a:field name="bank_account_name" readOnly="true"/>
                    <a:field name="bank_account_num" readOnly="true"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="create_paying_batch" text="付款单生成"/>
            </a:screenTopToolbar>
            <a:form column="2" title=" ">
                <a:lov name="bank_account_code" bindTarget="csh_bank_account" prompt="账户代码"/>
                <a:textField name="bank_short_name" bindTarget="csh_bank_account" prompt="银行简称"/>
                <a:textField name="bank_branch_name" bindTarget="csh_bank_account" prompt="分行名称"/>
                <a:textField name="bank_account_name" bindTarget="csh_bank_account" prompt="账户名"/>
                <a:textField name="bank_account_num" bindTarget="csh_bank_account" prompt="银行账号"/>
            </a:form>
        </a:screenBody>
    </a:view>
</a:screen>