<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Eugene Song $
    $Date: 2018年11月2日10:19:17 $
    $Revision: 1.1 $
    $Purpose: 网银代扣管理
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query model="basic.get_sys_default_time" rootPath="create_date_path"/>

    </a:init-procedure>
    <a:view>
        <a:link id="hls_ebank_create_link" model="ccb.CCB600.hls_ebank_batch" modelaction="execute"/>
        <a:link id="ebank_detail_link" url="${/request/@context_path}/modules/ccb/CCB600/ccb_ebank_detail.lview"/>
        <script type="text/javascript"><![CDATA[

        function create_batch() {
            var ds = $('hls_ccb_form_create_ds');
            if (ds.validate()) {
                var record = $('hls_ccb_form_create_ds').getAt(0);
                Leaf.Masker.mask(Ext.getBody(), '生成中...'); //锁屏
                Leaf.request({
                    url: $('hls_ebank_create_link').getUrl(),
                    para: {
                        bank_account_id: record.get('bank_account_id'),
                        merger_rules: record.get('merger_rules'),
                        payment_amount_from: record.get('payment_amount_from'),
                        payment_amount_to: record.get('payment_amount_to'),
                        due_date: record.get('due_date')
                    },
                    success: function (res) {
                        Leaf.SideBar.show({
                            msg: '操作成功',
                            duration: 2000
                        });
                        Leaf.Masker.unmask(Ext.getBody()); //解锁
                        $('hls_ccb_grid_create_ds').setQueryParameter('batch_id', res.result.batch_id);
                        $('hls_ccb_grid_create_ds').query();
                    },
                    failure: function () {
                    },
                    error: function () {
                    },
                    scope: this
                });
            }
        }

        function reset_batch() {
            $('hls_ccb_form_create_ds').reset();
        }

        function return_batch() {
            $('${/parameter/@winid}').close();
        }

        function batch_detail_renderer(value ,record,name) {
            return '<a href="javascript:open_batch_detail_window(' + record.get('hd_id') + ')">' + '${l:PROMPT.DETAIL}' + '</a>';
        }


        function open_batch_detail_window(hd_id){
            var win = new Leaf.Window({
                id: 'batch_link_winId',
                url: $('ebank_detail_link').getUrl(),
                params: {
                    hd_id: hd_id,
                    winid: 'batch_link_winId'
                },
                title: '代扣指令明细',
                draggable: true,
                width: 900,
                height: 680
            });
        }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="hls_ccb_form_create_ds" autoCreate="true">
                <a:fields>
                    <a:field name="bank_account_num" autoComplete="true" lovGridHeight="350" lovHeight="550"
                             lovService="ccb.CCB600.hls_ebank_bank" lovWidth="1000" required="true"
                             title="银行账户" prompt="银行账户">
                        <a:mapping>
                            <a:map from="bank_account_name" to="bank_account_name"/>
                            <a:map from="bank_account_num" to="bank_account_num"/>
                            <a:map from="bank_short_name" to="bank_name"/>
                            <a:map from="bank_account_id" to="bank_account_id"/>
                            <a:map from="currency_code" to="currency"/>
                        </a:mapping>
                    </a:field>

                    <a:field name="bank_account_name" readOnly="true"/>
                    <a:field name="bank_name" readOnly="true"/>
                    <a:field name="currency" readOnly="true"/>
                    <a:field name="due_date" datatype="date" defaultValue="${/model/create_date_path/record/@now_date}" required="true" prompt="应收日期"/>
                    <!--<a:field name="merger_rules" defaultValue="NONE"/>-->
                    <a:field name="merger_rules" defaultValue="CONTRACT"/>
                </a:fields>
            </a:dataSet>

            <a:dataSet id="hls_ccb_grid_create_ds" model="ccb.CCB600.hls_ebank_batch_hd" pageSize="15"
                       queryUrl="${/request/@context_path}/autocrud/ccb.CCB600.hls_ebank_batch_hd/query"
                       selectable="true">
            </a:dataSet>

        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar height="29">
                <a:gridButton click="create_batch" text="指令生成"/>
                <a:gridButton click="reset_batch" text="重置"/>
                <a:gridButton click="return_batch" text="返回"/>
            </a:screenTopToolbar>

            <a:fieldSet title="本方账户" column="2">
                <a:lov name="bank_account_num" bindTarget="hls_ccb_form_create_ds" prompt="银行账户"/>
                <a:textField name="bank_account_name" bindTarget="hls_ccb_form_create_ds" prompt="账户名"/>
                <a:textField name="bank_name" bindTarget="hls_ccb_form_create_ds" prompt="银行"/>
                <a:textField name="currency" bindTarget="hls_ccb_form_create_ds" prompt="币种"/>
            </a:fieldSet>
            <a:fieldSet title="合并规则" column="2">
                <a:radio name="merger_rules" bindTarget="hls_ccb_form_create_ds" layout="horizontal" width="600">
                    <a:items>
                        <!--<a:item label="不合并" value="NONE"/>-->
                        <a:item label="按合同" value="CONTRACT"/>
                        <a:item label="按期数" value="TIMES"/>
                    </a:items>
                </a:radio>
            </a:fieldSet>
            <a:fieldSet title="筛选条件" column="2">
                <a:numberField name="payment_amount_from" bindTarget="hls_ccb_form_create_ds" prompt="付款金额从"/>
                <a:numberField name="payment_amount_to" bindTarget="hls_ccb_form_create_ds" prompt="付款金额到"/>
            </a:fieldSet>

            <a:grid id="hls_ccb_create_grid" bindTarget="hls_ccb_grid_create_ds" height="200" width="800" navBar="true">
                <a:columns>
                    <a:column name="num" align="left" prompt="序号" width="80"/>
                    <a:column name="detail" align="center" prompt="明细" renderer="batch_detail_renderer" width="100"/>
                </a:columns>
            </a:grid>
            <a:fieldSet title="应收日期" column="2">
                <a:datePicker name="due_date" bindTarget="hls_ccb_form_create_ds" prompt="应收日期"/>
            </a:fieldSet>
        </a:screenBody>
    </a:view>
</a:screen>