<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2017年11月23日 下午1:34:27  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="hls700_credit_hd_update_link" model="hls.HLS700.hls700_bp_master_credit_limit" modelaction="batch_update"/>
        <a:link id="bp_credit_modify_link" url="${/request/@context_path}/modules/hls/HLS700/hls700_bp_master_credit_modify.lview"/>
        <a:link id="bp_credit_details_link" url="${/request/@context_path}/modules/hls/HLS700/hls700_bp_master_credit_detail.lview"/>
        <script type="text/javascript"><![CDATA[
            function hls700_credit_add() {
                $('hls700_credit_grid_ds').showEditorByRecord($('hls700_credit_result_ds').create());
            
            }
            
            
            function hls700_credit_query() {
                $('hls700_credit_result_ds').query();
            
            }
            
            function hls700_credit_reset() {
                $('hls700_credit_query_ds').reset();
            }
            
            function hls700_grid_update(bp_credit_hd_id) {
                if (!bp_credit_hd_id) {
                    Leaf.showMessage('提示', '请先保存!');
                    return;
                }
            
                var win = new Leaf.Window({
                    id: 'bp_credit_modify_window',
                    url: $('bp_credit_modify_link').getUrl(),
                    params: {
                        bp_credit_hd_id: bp_credit_hd_id,
                        winId: 'bp_credit_modify_window'
                    },
                    title: '授信额度分配页面',
                    fullScreen: true
                });
                win.on('close', function() {
                    $('hls700_credit_result_ds').query();
                });
            }
            
            function hls700_credit_detail_render(value, record, name) {
                return '<a href="javascript:hls700_grid_update(' + record.get('bp_credit_hd_id') + ')">分配</a>';
            }
            
            
            function hls700_credit_save() {
                var ds = $('hls700_credit_result_ds');
                var records = ds.getAll();
                var param;
                var param_list = [];
                for (var i = 0;i < records.length;i++) {
                    param = {
                        'bp_credit_hd_id': records[i].get('bp_credit_hd_id'),
                        'bp_id': records[i].get('bp_id'),
                        '_status': 'update'
                    };
                    param_list.push(param);
                }
            
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                Leaf.request({
                    url: $('hls700_credit_hd_update_link').getUrl(),
                    para: param_list,
                    success: function(res) {
                        Leaf.Masker.unmask(Ext.getBody());
                        Leaf.SideBar.show({
                            msg: '保存成功',
                            duration: 2000
                        });
                        $('hls700_credit_result_ds').query();
                    },
                    failure: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });
            
            
            }
            
            function hls700_credit_detail() {
                var record = $('hls700_credit_result_ds').getSelected();
                var bp_credit_hd_id = record[0].get('bp_credit_hd_id');
                var bp_id = record[0].get('bp_id');
                var bp_name = record[0].get('bp_name');
                var win = new Leaf.Window({
                    id: 'bp_credit_details_window',
                    url: $('bp_credit_details_link').getUrl(),
                    params: {
                        bp_credit_hd_id: bp_credit_hd_id,
                        bp_id:bp_id,
                        bp_name:bp_name,
                        winId: 'bp_credit_details_window'
                    },
                    title: '授信额度界面',
                    fullScreen: true
                });
                win.on('close', function() {
                    $('hls700_credit_result_ds').query();
                });
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="hls700_bp_credit_ds" lookupCode="BP_CATEGORY"/>
            <a:dataSet id="hls700_credit_query_ds">
                <a:fields>
                    <a:field name="bp_code" lovHeight="500" lovService="hls.HLS700.hls700_bp_master_lov?bp_category=TENANT" lovWidth="700" title="商业伙伴选择">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id"/>
                            <a:map from="bp_code" to="bp_code"/>
                            <a:map from="bp_name" to="bp_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_category_n" displayField="code_value_name" options="hls700_bp_credit_ds" returnField="invoice_kind" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="hls700_credit_result_ds" autoPageSize="true" autoQuery="true" model="hls.HLS700.hls700_bp_master_credit_limit" queryDataSet="hls700_credit_query_ds" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="bp_code" lovHeight="500" lovService="hls.HLS700.hls700_bp_master_lov" lovWidth="700" required="true" title="商业伙伴选择">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id"/>
                            <a:map from="bp_code" to="bp_code"/>
                            <a:map from="bp_name" to="bp_name"/>
                            <a:map from="bp_category_n" to="bp_category_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="credit_total_amount"/>
                    <a:field name="open_amount"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="hls700_credit_query" text="HLS.QUERY"/>
                <a:gridButton click="hls700_credit_reset" text="HLS.RESET"/>
                <a:gridButton click="hls700_credit_add" text="HLS.NEW"/>
                <a:gridButton click="hls700_credit_save" text="HLS.SAVE"/>
                <a:gridButton click="hls700_credit_detail" text="授信详情"/>
            </a:screenTopToolbar>
            <a:form column="3" labelWidth="150" title="HAP_QUERY_TITLE">
                <a:lov name="bp_code" bindTarget="hls700_credit_query_ds" prompt="商业伙伴编码"/>
                <a:textField name="bp_name" bindTarget="hls700_credit_query_ds" prompt="商业伙伴名称"/>
                <a:comboBox name="bp_category_n" bindTarget="hls700_credit_query_ds" prompt="商业伙伴类型"/>
            </a:form>
            <a:grid id="hls700_credit_grid_ds" bindTarget="hls700_credit_result_ds" marginHeight="230" marginWidth="50" navBar="true">
                <a:columns>
                    <a:column name="bp_code" editor="creditDs_grid_editor_lov" prompt="商业伙伴编码"/>
                    <a:column name="bp_name" prompt="商业伙伴名称" width="280"/>
                    <a:column name="bp_category_n" prompt="商业伙伴类型"/>
                    <a:column name="credit_total_amount" align="right" prompt="授信总额度" renderer="Leaf.formatMoney" width="150"/>
                    <a:column name="open_amount" align="right" prompt="开额额度" renderer="Leaf.formatMoney" width="150"/>
                    <a:column name="used_amount" align="right" prompt="已使用额度" renderer="Leaf.formatMoney" width="150"/>
                    <a:column name="last_amount" align="right" prompt="剩余额度" renderer="Leaf.formatMoney" width="150"/>
                    <a:column align="center" prompt="额度分配" renderer="hls700_credit_detail_render" width="105"/>
                </a:columns>
                <a:editors>
                    <a:lov id="creditDs_grid_editor_lov"/>
                    <a:currencyField id="creditDs_grid_editor_tx"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
