<?xml version="1.0" encoding="UTF-8"?>

<a:screen xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
    <a:init-procedure>
        <a:model-query model="ccb.CCB600.get_import_head_id" rootPath="header"/>
        <a:import-excel header_id="${/model/header/record/@header_id}" separator=","
                        status_field="/parameter/@ImportSuccess" template_code="CCB_MANUAL_IMPORT"
                        user_id="${/session/@user_id}"/>
<!--        <a:model-query-->
<!--                defaultWhereClause="header_id=${/model/header/record/@header_id} and TEMPLATE_CODE = &apos;CCB_MANUAL_IMPORT&apos;"-->
<!--                model="ccb.CCB503.ccb503_import_get_status" rootPath="status"/>-->
    </a:init-procedure>
    <a:view>
        <a:link id="import_interface_write_off_link" model="ccb.CCB600.ccb_import_ln" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
            function backBtn() {
                history.go(-1);
            }
            
            var import_flag = 0;
            
            function import_confirm() {
                if(!$('ccb_form_ds').validate()){
                    return;
                }
                var transaction_date = $('ccb_form_ds').getCurrentRecord().get('transaction_date');
                $('import_confirm_id').disable();
                var ds = $('ccb_import_grid_ds');
                record = ds.getAll();
                if (import_flag == 0) {
                    for (i = 0;i < record.length;i++) {
                        if (record[i].get('status') == 'ERROR') {
                            Leaf.showMessage('${l:PROMPT}', '导入的数据存在错误,请查看错误信息!');
                            return;
                        }
                    }
                    Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                    Leaf.request({
                        url: $('import_interface_write_off_link').getUrl(),
                        para: {
                            /*'header_id': '${/parameter/@header_id}'*/
                            header_id: '${/model/header/record/@header_id}',
                            batch_id: '${/parameter/@batch_id}',
                            transaction_date: transaction_date
                        },
                        scope: this,
                        success: function() {
                            import_flag = import_flag + 1;
                            Leaf.SideBar.show({
                                msg: '操作成功',
                                duration: 2000
                            });
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function(){
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        failure: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                       }
                    });
                } else {
                    Leaf.showMessage('${l:PROMPT}', '已导入的数据不能重复导入!');
                    return;
                }
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="ccb_import_grid_ds" autoPageSize="true" autoQuery="true" model="ccb.CCB600.ccb_import_ln" queryUrl="${/request/@context_path}/autocrud/ccb.CCB600.ccb_import_ln/query?header_id=${/model/header/record/@header_id}" selectable="true"/>
        </a:dataSets>
        <a:dataSets>
            <a:dataSet id="ccb_form_ds" autoCreate="true">
                <a:fields>
                    <a:field name="transaction_date" defaultValue="${/parameter/@due_date_to}" required="true" prompt="建行划扣截止日期"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="backBtn" text="HLS.EXIT"/>
                <a:gridButton id="import_confirm_id" click="import_confirm" text="确认导入"/>
            </a:screenTopToolbar>
            <a:form column="1" labelWidth="120" marginWidth="30">
                <a:datePicker name="transaction_date" readOnly="true" bindTarget="ccb_form_ds" prompt="建行划扣交易日期"/>
            </a:form>
            <a:grid bindTarget="ccb_import_grid_ds" marginHeight="230" marginWidth="50" navBar="true">
                <a:columns>
                    <a:column name="attribute_1" prompt="序号" width="80"/>
                    <a:column name="attribute_2" prompt="账号"/>
                    <a:column name="attribute_3" prompt="户名" width="150"/>
                    <a:column name="attribute_4" align="right" prompt="发起金额" renderer="Leaf.formatMoney"/>
                    <a:column name="attribute_5" align="right" prompt="成功金额" renderer="Leaf.formatMoney"/>
                    <a:column name="attribute_6" align="center" prompt="跨行标识"/>
                    <a:column name="attribute_7" align="center" prompt="行名" width="170"/>
                    <a:column name="attribute_8" align="center" prompt="行号" width="170"/>
                    <a:column name="attribute_9" align="center" prompt="多方协议号" width="150"/>
                    <a:column name="attribute_10" align="center" prompt="标识号" width="150"/>
                    <a:column name="attribute_11" align="center" prompt="摘要" width="150"/>
                    <a:column name="attribute_12" align="center" prompt="备注" width="150"/>
                    <a:column name="attribute_13" align="center" prompt="银行卡类型" width="150"/>
                    <a:column name="attribute_14" align="center" prompt="成功标志" width="150"/>
                    <a:column name="attribute_15" align="center" prompt="失败原因" width="150"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>