<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangyu  
    $Date: 2016-3-10 下午15:33:51
    $Revision: 1.0  
    $Purpose: 开户申请维护
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="sdic200_bank_account_req_submit_link" model="sdic.SDIC200.sdic_bank_account_req_submit" modelaction="execute"/>
        <a:link id="sdic200_bank_account_req_save_link" model="sdic.SDIC200.sdic_get_bank_account_req_num" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
        	
            window['${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'sdic_bank_account_req_hd');
                var hd_ds, hdrecord;
                hd_ds = $(hdds_id);
                hdrecord = hd_ds.getCurrentRecord();
            
                var account_total, basic_account_total, general_account_total, specific_account_total, foreign_currency_account_total;
                if (!Ext.isEmpty(hdrecord.get('basic_account_total'))) {
                    basic_account_total = hdrecord.get('basic_account_total');
                } else {
                    basic_account_total = 0;
                }
                if (!Ext.isEmpty(hdrecord.get('general_account_total'))) {
                    general_account_total = hdrecord.get('general_account_total');
                } else {
                    general_account_total = 0;
                }
                if (!Ext.isEmpty(hdrecord.get('specific_account_total'))) {
                    specific_account_total = hdrecord.get('specific_account_total');
                } else {
                    specific_account_total = 0;
                }
                if (!Ext.isEmpty(hdrecord.get('foreign_currency_account_total'))) {
                    foreign_currency_account_total = hdrecord.get('foreign_currency_account_total');
                } else {
                    foreign_currency_account_total = 0;
                }
                account_total = basic_account_total + general_account_total + specific_account_total + foreign_currency_account_total;
                hdrecord.set('account_total', account_total);
            };
            
            //保存submitsuccess调用
            window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function(ds, record, res, bp_seq) {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'sdic_bank_account_req_hd');
                var hd_record = $(ds_id).getCurrentRecord();
                var hd_id = hd_record.get('hd_id');
                Leaf.request({
                    url: $('sdic200_bank_account_req_save_link').getUrl(),
                    para: {
                        hd_id: hd_id
                    },
                    success: function(res) {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();

                        var req_number = res.result.req_number;
                        hd_record.set('req_number',req_number);
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            };
            
            //提交工作流
            window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {

                var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'sdic_bank_account_req_hd');
                var req_record = $(req_ds_id).getAt(0);
                if ($(req_ds_id).validate()) {
                    if (req_record.dirty) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                        return;
                    }
            
                    Leaf.showConfirm('${l:HLS.PROMPT}', '${l:HLS.ARE_YOU_SURE_TO_SUBMIT}', function() {
                        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                        Leaf.request({
                            url: $('sdic200_bank_account_req_submit_link').getUrl(),
                            para: {
                                hd_id: req_record.get('hd_id')
                            },
                            success: function(res) {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                $('${/parameter/@winid}').close();
                            },
                            failure: function() {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            error: function() {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            scope: this
                        });
                    });
                }
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
