<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2017年8月18日 上午10:05:22
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query model="basic.get_sys_default_time" rootPath="ds_abc_create_date_path"/>

    </a:init-procedure>
    <a:view>
        <a:link id="ccb503_temp_delete_link" model="ccb.CCB503.ds_abc_trans_update" modelaction="execute"/>
        <a:link id="update_abc_inteface_link" model="ccb.CCB503.ds_abc_trans_update" modelaction="update"/>
        <a:link id="create_abc_document_link"
                url="${/request/@context_path}/modules/ccb/CCB503/ds_abc_interface_export_txt.lsc"/>
        <a:link id="ccb503_err_message_link" model="ccb.CCB503.ds_abc_import_li" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
        function ds_abc_query() {
            $('ds_abc_detail_result_ds').query();
        }

        function ds_abc_trans_confirm() {
            $('ds_abc_trans_id').disable();
            var date_ds = $('trans_date_ds').getAt(0);
           /* var create_date = date_ds.get('create_date');*/
            var create_date_to = date_ds.get('create_date_to');
            Leaf.Masker.mask($('${/parameter/@winId}').wrap, '${l:HLS.EXECUTING}');
            Leaf.request({
                url: $('update_abc_inteface_link').getUrl(),
                para: {
                    // 'session_id': '${/session/@session_id}',
                    // 'user_id': '${/session/@user_id}',
                   /* 'create_date': create_date,*/
                    'create_date_to': create_date_to
                },
                success: function () {
                    $('ds_abc_trans_id').enable();
                    Leaf.Masker.unmask($('${/parameter/@winId}').wrap);
                    ds_abc_query();
                },
                failure: function () {
                    $('ds_abc_trans_id').enable();
                    Leaf.Masker.unmask($('${/parameter/@winId}').wrap);
                },
                error: function () {
                    $('ds_abc_trans_id').enable();
                    Leaf.Masker.unmask($('${/parameter/@winId}').wrap);
                },
                scope: this
            });
        }


        function ds_abc_trans_create() {

            var records = $('ds_abc_detail_result_ds').getAll();
            if (records.length == 0) {
                Leaf.showMessage('${l:PROMPT}', '不存在待生成的数据!');
                return;
            }
            var param;
            $('create_id').disable();
            $('ds_abc_trans_id').disable();
            $('ds_abc_trans_save').disable();
            $('ds_abc_delete_id').disable();

            //ds_abc_trans_save();    //保存数据
            Leaf.Masker.mask($('${/parameter/@winId}').wrap, '${l:HLS.EXECUTING}');
            Leaf.request({
                url: $('ccb503_err_message_link').getUrl(),
                para: param,
                success: function (res) {
                    Leaf.Masker.unmask($('${/parameter/@winId}').wrap);
                    var url = $('create_abc_document_link').getUrl();
                    window.open(url, '_self');
                   /* window.setTimeout(function () {
                        $('ds_abc_trans_link_winId').close();
                    }, 2000);*/
                },
                failure: function () {
                    $('create_id').enable();
                    Leaf.Masker.unmask($('${/parameter/@winId}').wrap);
                },
                error: function () {
                    $('create_id').enable();
                    Leaf.Masker.unmask($('${/parameter/@winId}').wrap);
                },
                scope: this
            });

        }

        function ds_abc_trans_delete() {
            var ds = $('ds_abc_detail_result_ds');
            var records = ds.getSelected();
            if (records.length == 0) {
                Leaf.showMessage('提示', '请至少勾选一条记录!', null, 350);
                return;
            }
            var param;
            for (var i = 0; i < records.length; i++) {
                param = {
                    'record_id': records[i].get('record_id')
                };
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                Leaf.request({
                    url: $('ccb503_temp_delete_link').getUrl(),
                    para: param,
                    success: function (res) {
                        Leaf.SideBar.show({
                            msg: '删除成功',
                            duration: 2000
                        });
                        Leaf.Masker.unmask(Ext.getBody());
                        ds_abc_query();
                    },
                    scope: this
                });
            }
        }

        //保存
        function ds_abc_trans_save() {

            var ds = $('ds_abc_detail_result_ds');
            var records = ds.getSelected();
            if (records.length == 0) {
                Leaf.showMessage('提示', '请至少勾选一条记录!', null, 350);
                return;
            }
            var param;
            for (var i = 0; i < records.length; i++) {
                param = {
                    'contract_id': records[i].get('contract_id'),
                    'record_id':records[i].get('record_id'),
                    'cdd_list_id': records[i].get('cdd_list_id'),
                    'withhold_amount': records[i].get('withhold_amount')
                };
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/ccb.CCB503.ds_abc_trans_confirm/update',
                    para: param,
                    success: function (res) {
                        Leaf.SideBar.show({
                            msg: '修改成功',
                            duration: 2000
                        });
                        Leaf.Masker.unmask(Ext.getBody());
                        ds_abc_query();
                    },
                    scope: this
                });
            }
        }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="ds_abc_detail_result_ds" autoPageSize="true" autoQuery="true"
                       model="ccb.CCB503.ds_abc_trans_update" selectable="true">
                <a:fields>
                    <a:field name="error_message" readOnly="true"/>
                    <a:field name="withhold_amount" required="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="trans_date_ds" autoCreate="true">
                <a:fields>
                    <a:field name="create_date" datatype="date"  defaultValue="${/model/ds_abc_create_date_path/record/@now_date}"
                             required="true"/>
                    <a:field name="create_date_to" datatype="date" defaultValue="${/model/ds_abc_create_date_path/record/@now_date}"
                             required="true"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <!--  <a:gridButton click="ds_abc_query" text="HLS.QUERY"/> -->
                <a:gridButton id="ds_abc_delete_id" click="ds_abc_trans_delete" text="HLS.REMOVE"/>
                <a:gridButton id="ds_abc_trans_id" click="ds_abc_trans_confirm" text="重新生成"/>
                <a:gridButton id="ds_abc_trans_save" click="ds_abc_trans_save" text="保存"/>
                <a:gridButton id="create_id" click="ds_abc_trans_create" text="生成农行扣款文件"/>
            </a:screenTopToolbar>
            <!-- <a:form column="" title="HAP_QUERY_TITLE">
                <a:hBox labelWidth="100">
                    <a:textField name="" bindTarget="ds_abc_detail_query_ds" prompt="合同编号"/>
                    <a:textField name="" bindTarget="ds_abc_detail_query_ds" prompt="商业伙伴"/>
                </a:hBox>
            </a:form> -->
            <!--  <a:fieldSet column="1" height="60" title="代扣日期选择" width="500">
                <a:datePicker name="create_date" bindTarget="trans_date_ds" prompt="预定支付日到"/>
                <a:datePicker name="create_date_to" bindTarget="trans_date_ds" prompt="预定支付日到"/>
            </a:fieldSet> -->
            <a:form column="" title="扣款日期">
                <a:hBox labelWidth="100">
                   <!-- <a:datePicker name="create_date"  bindTarget="trans_date_ds"
                                  prompt="预定支付日从"/>-->
                    <a:datePicker name="create_date_to"  bindTarget="trans_date_ds"
                                  prompt="预定支付日到"/>
                </a:hBox>
            </a:form>
            <a:grid bindTarget="ds_abc_detail_result_ds" marginHeight="270" marginWidth="70" navBar="true">
                <a:columns>
                    <a:column name="error_message" editor="textAreaEditor" prompt="错误信息" width="180"/>
                    <a:column name="contract_number" align="left" prompt="合同编号"/>
                    <a:column name="bp_name" align="left" prompt="商业伙伴名称" width="150"/>
                    <a:column name="times" align="center" prompt="期数" width="80"/>
                    <a:column name="cf_item_n" align="left" prompt="代扣项目" width="80"/>
                    <a:column name="due_amount" align="right" prompt="应代扣金额" renderer="Leaf.formatMoney" width="130"/>
                    <a:column name="withhold_amount" align="right" prompt="本次代扣金额" editor="grid_nf"
                              renderer="Leaf.formatMoney" width="130"/>
                    <a:column name="currency_code" align="center" prompt="币种" width="80"/>
                    <a:column name="due_date" align="center" prompt="应收日期" width="120"/>
                    <a:column name="bank_account_num" align="left" prompt="银行账号" width="170"/>
                    <a:column name="bank_account_name" align="left" prompt="账号名称" width="170"/>
                </a:columns>
                <a:editors>
                    <a:textArea id="textAreaEditor" height="40" width="180"/>
                    <a:numberField id="grid_nf" allowDecimals="true" allowNegative="false" decimalPrecision ="2"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>