<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Hongquan.Dai  代宏全
    $Date: 2018-1-22 上午10:36:25  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="pageLink_choose_acount" url="${/request/@context_path}/modules/hsbc/HSBC100/csh_bank_account_choose.lview"/>
        <a:link id="${/parameter/@layout_code}con_contract_query_link" url="${/request/@context_path}/modules/cont/CON3200/con_re_incept_modify.lview"/>
        <a:link id="transaction_return_downloadFile_link_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="csh501_csh_asset_req_link_id" url="${/request/@context_path}/modules/csh/CSH501C/csh_payment_asset_req.lview"/>
        <script src="${/request/@context_path}/javascripts/calculate.js"/>
        <script type="text/javascript"><![CDATA[

        function open_contract_win(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['function_usage'] = 'QUERY';
            param['function_code'] = 'CON3200Q';
            param['maintain_type'] = 'QUERY';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';

            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}con_contract_query_link', ds_id);
        }

        function open_return_win(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var header_id = record.data.return_id;
            var table_name = 'CSH_TRANSACTION_RETURN';
            if(!Ext.isEmpty(record.get('csh_return_atm_id'))){
                header_id = record.get('csh_return_atm_id');
                table_name = 'CSH_TRANSACTION_RETURN_DEPOSIT';
            }
            var url = $('transaction_return_downloadFile_link_id').getUrl() + '?table_name='+ table_name +'&_csrf=${/session/@_csrf.token}&header_id=' + header_id;
            var win = new Leaf.Window({
                url: url,
                title: '${l:HLS.SUPPORTING_DOCUMENT}',
                id: 'transaction_return_uploadFile_id',
                width: 850,
                height: 400
            });
        }
        function detail_link(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var param = {};
            param['payment_req_id'] = record.get('payment_req_id');
            param['business_type'] = record.get('business_type');
            param['function_usage'] = 'QUERY';
            param['function_code'] = 'ASSET_SAVE';
            param['download'] = 'Y';
            param['winid'] = 'csh_payment_asset_update_window';
            param['url_title'] = '付款申请';

            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'csh501_csh_asset_req_link_id', ds_id);
        }
        window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
            if (name == 'contract_number' && value) {
                return '<a href="javascript:open_contract_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
            }
            if (name == 'attachment_r') {
                return '<a href="javascript:open_return_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + '附件' + '</a>';
            }
            if (name == 'payment_req_number' && value) {
                link_function = 'detail_link';
                return '<a href="javascript:detail_link(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
            }
            return value;
        };

        //创建代付单
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            var req_ln_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_RESULT', 'csh_payment_req_ln');
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_transaction_return');
            var manage_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'M_RESULT', 'csh_payment_req_ln');
            var req_ln_ds = $(req_ln_ds_id);
            var con_ds = $(con_ds_id);
            var manage_ds = $(manage_ds_id);
            var req_ln_records = req_ln_ds.getSelected();
            var con_records = con_ds.getSelected();
            var manage_records = manage_ds.getSelected();

            var ds_id;
            var pay_type;
            let a = document.querySelectorAll("div.strip");
            // 页面展示  二手机业务付款单
            if(a[0].classList.contains('active')){
                if (con_records.length > 0 || manage_records.length > 0) {
                    Leaf.showMessage('${l:PROMPT}', '只能勾选当前页面付款单数据!');
                    return;
                }
                if (req_ln_records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请至少勾选一条记录!');
                    return;
                }
                ds_id = req_ln_ds_id;
                pay_type = 'TJ';
            }
            // 页面展示  退款付款单
            if(a[1].classList.contains('active')){
                if (req_ln_records.length > 0 || manage_records.length > 0) {
                    Leaf.showMessage('${l:PROMPT}', '只能勾选当前页面付款单数据!');
                    return;
                }
                if (con_records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请至少勾选一条记录!');
                    return;
                }
                ds_id = con_ds_id;
                pay_type = 'RETURN';
            }
            // 页面展示  资产管理付款单
            if(a[2].classList.contains('active')){
                if (req_ln_records.length > 0 || con_records.length > 0) {
                    Leaf.showMessage('${l:PROMPT}', '只能勾选当前页面付款单数据!');
                    return;
                }
                if (manage_records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请至少勾选一条记录!');
                    return;
                }
                ds_id = manage_ds_id;
                pay_type = 'MANAGE';
            }

            new Leaf.Window({
                id: 'choose_acount_window',
                url: $('pageLink_choose_acount').getUrl(),
                params: {
                    winId: 'choose_acount_window',
                    ds_id: ds_id,
                    button_id: 'create_with_sbo',
                    pay_type: pay_type
                },
                title: '支付账号选择',
                height: 260,
                width: 680
            });
        };

        //创建强制付款单生成
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
            var req_ln_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_RESULT', 'csh_payment_req_ln');
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_transaction_return');
            var manage_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'M_RESULT', 'csh_payment_req_ln');
            var req_ln_ds = $(req_ln_ds_id);
            var con_ds = $(con_ds_id);
            var manage_ds = $(manage_ds_id);
            var req_ln_records = req_ln_ds.getSelected();
            var con_records = con_ds.getSelected();
            var manage_records = manage_ds.getSelected();

            var ds_id;
            var pay_type;
            let a = document.querySelectorAll("div.strip");
            // 页面展示  二手机业务付款单
            if(a[0].classList.contains('active')){
                if (con_records.length > 0 || manage_records.length > 0) {
                    Leaf.showMessage('${l:PROMPT}', '只能勾选当前页面付款单数据!');
                    return;
                }
                if (req_ln_records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请至少勾选一条记录!');
                    return;
                }
                ds_id = req_ln_ds_id;
                pay_type = 'TJ';
            }
            // 页面展示  退款付款单
            if(a[1].classList.contains('active')){
                if (req_ln_records.length > 0 || manage_records.length > 0) {
                    Leaf.showMessage('${l:PROMPT}', '只能勾选当前页面付款单数据!');
                    return;
                }
                if (con_records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请至少勾选一条记录!');
                    return;
                }
                ds_id = con_ds_id;
                pay_type = 'RETURN';
            }
            // 页面展示  资产管理付款单
            if(a[2].classList.contains('active')){
                if (req_ln_records.length > 0 || con_records.length > 0) {
                    Leaf.showMessage('${l:PROMPT}', '只能勾选当前页面付款单数据!');
                    return;
                }
                if (manage_records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请至少勾选一条记录!');
                    return;
                }
                ds_id = manage_ds_id;
                pay_type = 'MANAGE';
            }

            new Leaf.Window({
                id: 'choose_acount_window',
                url: $('pageLink_choose_acount').getUrl(),
                params: {
                    winId: 'choose_acount_window',
                    ds_id: ds_id,
                    button_id: 'create_without_sbo',
                    pay_type: pay_type
                },
                title: '支付账号选择',
                height: 260,
                width: 680
            });
        };
        //创建代付单
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
            var req_ln_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_transaction_return');
            var req_ln_ds = $(req_ln_ds_id);
            var con_ds = $(con_ds_id);
            var req_ln_records = req_ln_ds.getSelected();
            var con_records = con_ds.getSelected();
            if (con_records.length == 0 || req_ln_records.length > 0) {
                Leaf.showMessage('${l:PROMPT}', '只能勾选退款付款单数据!');
                return;
            }
            new Leaf.Window({
                id: 'choose_acount_window',
                url: $('pageLink_choose_acount').getUrl(),
                params: {
                    winId: 'choose_acount_window',
                    ds_id: con_ds_id,
                    button_id: 'create_with_sbo',
                    pay_type: 'RETURN'
                },
                title: '支付账号选择',
                height: 260,
                width: 680
            });
        };

        //创建强制付款单生成
        window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function() {
            var req_ln_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_transaction_return');
            var req_ln_ds = $(req_ln_ds_id);
            var con_ds = $(con_ds_id);
            var req_ln_records = req_ln_ds.getSelected();
            var con_records = con_ds.getSelected();
            if (con_records.length == 0 || req_ln_records.length > 0) {
                Leaf.showMessage('${l:PROMPT}', '只能勾选退款付款单数据!');
                return;
            }
            new Leaf.Window({
                id: 'choose_acount_window',
                url: $('pageLink_choose_acount').getUrl(),
                params: {
                    winId: 'choose_acount_window',
                    ds_id: con_ds_id,
                    button_id: 'create_without_sbo',
                    pay_type: 'RETURN'
                },
                title: '支付账号选择',
                height: 260,
                width: 680
            });
        };

        window['${/parameter/@layout_code}_on_layout_dynamic_grid_select'] = function(ds, record, bp_seq) {
            var form_ds_id = '${/parameter/@layout_code}_F_QUERY__ds';
            var formr_r_ds_id = '${/parameter/@layout_code}_R_F_QUERY__ds';
            var formr_m_ds_id = '${/parameter/@layout_code}_M_F_QUERY__ds';
            var req_ln_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_RESULT', 'csh_payment_req_ln');
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_transaction_return');
            var manage_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'M_RESULT', 'csh_payment_req_ln');
            var form_record = $(form_ds_id).getAt(0);
            var form_r_record = $(formr_r_ds_id).getAt(0);
            var form_m_record = $(formr_m_ds_id).getAt(0);
            var req_records = $(req_ln_ds_id).getSelected();
            var con_records = $(con_ds_id).getSelected();
            var manage_records = $(manage_ds_id).getSelected();

            if (req_ln_ds_id == ds.id) {
                var sum = 0;
                for (var i = 0;i < req_records.length;i++) {
                    sum = plus(sum, req_records[i].get('unpaid_amount'));
                }
                form_record.set('total_unpaid_amount', sum);
            }

            if (con_ds_id == ds.id) {
                var sum = 0;
                for (var i = 0;i < con_records.length;i++) {
                    sum = plus(sum, con_records[i].get('this_return_amount'));
                }
                form_r_record.set('total_unpaid_amount', sum);
            }

            if (manage_ds_id == ds.id) {
                var sum = 0;
                for (var i = 0;i < manage_records.length;i++) {
                    sum = plus(sum, manage_records[i].get('unpaid_amount'));
                }
                form_m_record.set('total_unpaid_amount', sum);
            }
        };

        window['${/parameter/@layout_code}_on_layout_dynamic_grid_unselect'] = function(ds, record, bp_seq) {
            var form_ds_id = '${/parameter/@layout_code}_F_QUERY__ds';
            var formr_r_ds_id = '${/parameter/@layout_code}_R_F_QUERY__ds';
            var formr_m_ds_id = '${/parameter/@layout_code}_M_F_QUERY__ds';
            var req_ln_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_RESULT', 'csh_payment_req_ln');
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_transaction_return');
            var manage_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'M_RESULT', 'csh_payment_req_ln');
            var form_record = $(form_ds_id).getAt(0);
            var form_r_record = $(formr_r_ds_id).getAt(0);
            var form_m_record = $(formr_m_ds_id).getAt(0);
            var req_records = $(req_ln_ds_id).getSelected();
            var con_records = $(con_ds_id).getSelected();
            var manage_records = $(manage_ds_id).getSelected();

            if (req_ln_ds_id == ds.id) {
                var sum = 0;
                for (var i = 0;i < req_records.length;i++) {
                    sum = plus(sum, req_records[i].get('unpaid_amount'));
                }
                form_record.set('total_unpaid_amount', sum);
            }

            if (con_ds_id == ds.id) {
                var sum = 0;
                for (var i = 0;i < con_records.length;i++) {
                    sum = plus(sum, con_records[i].get('this_return_amount'));
                }
                form_r_record.set('total_unpaid_amount', sum);
            }

            if (manage_ds_id == ds.id) {
                var sum = 0;
                for (var i = 0;i < manage_records.length;i++) {
                    sum = plus(sum, manage_records[i].get('unpaid_amount'));
                }
                form_m_record.set('total_unpaid_amount', sum);
            }
        };

        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>