<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Icon  
    $Date: 2014-10-9 下午2:10:08  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure><![CDATA[
	]]></a:init-procedure>
    <a:view>
        <a:link id="assign_company_link" model="hls.HLS052.hls_price_list_assign" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
        	
        	// function init() {s
			    // $('assign_company_ds').setQueryParameter('price_list','${/parameter/@price_list}');
				// $('assign_company_ds').query();
				// $('assign_company_ds').setQueryParameter('price_list','${/parameter/@price_list}');
				// $('assign_company_ds').query();
        	// }   
        	
        	function assign_company_cancel() {
                var ds = $('assign_company_ds');
                var records = ds.getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                    return;
                }
                Leaf.showConfirm('${l:HLS.PROMPT}', '是否取消分配？', function() {
                    var datas = [];
                    for (var i = 0;i < records.length;i++) {
                        var obj = {};
                        obj['company_id'] = records[i].get('company_id');
                        obj['price_list'] = '${/parameter/@price_list}';
                        obj['_status'] = 'delete';
                        obj['enabled_flag'] = 'Y';
                        datas[i] = obj;
                    }
                    Leaf.request({
                        url: $('assign_company_link').getUrl(),
                        para:datas,
                        success: function() {
                            Leaf.SideBar.show({
                                msg: '操作成功',
                                duration: 2000
                            });
                            $('assign_company_ds').query();
                            $('un_assign_company_ds').query();
                        },
                        scope: this
                    });
                });
            }   
        	
        	function assign_company_update() {
                var ds = $('un_assign_company_ds');
                var records = ds.getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                    return;
                }
                Leaf.showConfirm('${l:HLS.PROMPT}', '是否分配公司？', function() {
                    var datas = [];
                    for (var i = 0;i < records.length;i++) {
                        var obj = {};
                        obj['company_id'] = records[i].get('company_id');
                        obj['price_list'] = '${/parameter/@price_list}';
                        obj['_status'] = 'insert';
                        obj['enabled_flag'] = 'Y';
                        datas[i] = obj;
                    }
                    Leaf.request({
                        url: $('assign_company_link').getUrl(),
                        para:datas,
                        success: function() {
                            Leaf.SideBar.show({
                                msg: '操作成功',
                                duration: 2000
                            });
                            $('assign_company_ds').query();
                            $('un_assign_company_ds').query();
                        },
                        scope: this
                    });
                });
            } 
        	
        	function form_reset() {
        	    $('company_query_ds').reset();
        	}	
			
			function grid_query() {
				$('assign_company_ds').query();
				$('un_assign_company_ds').query();
			}
			
			function grid_save() {
				
			}
		]]></script>
        <a:dataSets>
            <a:dataSet id="company_query_ds">
                <a:fields>
                    <a:field name="company_code"/>
                    <a:field name="company_short_name"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="assign_company_ds" autoQuery="true" queryDataSet="company_query_ds" queryUrl="${/request/@context_path}/autocrud/hls.HLS052.fnd_companies/query?price_list=${/parameter/@price_list}&amp;assign_flag=Y" selectable="true"/>
            <a:dataSet id="un_assign_company_ds" autoQuery="true" queryDataSet="company_query_ds" queryUrl="${/request/@context_path}/autocrud/hls.HLS052.fnd_companies/query?price_list=${/parameter/@price_list}&amp;assign_flag=N" selectable="true"/>
            <!--             <a:dataSet id="company_result_ds" model="hls.HLS052.fnd_companies" autoPageSize="true" queryDataSet="company_query_ds">
                <a:fields>                	
                    <a:field name="company_code"/>
                    <a:field name="company_name"/>
                </a:fields>
            </a:dataSet> -->
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="form_reset" text="重置"/>
                <a:gridButton click="grid_query" text="查询"/>
                <a:gridButton click="assign_company_update" text="公司分配"/>
                <a:gridButton click="assign_company_cancel" text="取消分配"/>
            </a:screenTopToolbar>
            <a:form title="查询条件">
                <a:hBox>
                    <a:textField name="company_code" bindTarget="company_query_ds" prompt="公司代码">
                        <a:events>
                            <a:event name="enterdown" handler="grid_query"/>
                        </a:events>
                    </a:textField>
                    <a:textField name="company_short_name" bindTarget="company_query_ds" prompt="公司名称">
                        <a:events>
                            <a:event name="enterdown" handler="grid_query"/>
                        </a:events>
                    </a:textField>
                </a:hBox>
            </a:form>
            <a:hBox>
                <a:form title="未分配公司">
                    <a:grid bindTarget="un_assign_company_ds" height="330" navBar="true" width="378">
                        <a:columns>
                            <a:column name="company_code" prompt="公司代码" width="150"/>
                            <a:column name="company_short_name" prompt="公司简称" width="200"/>
                        </a:columns>
                    </a:grid>
                </a:form>
                <a:form title="已分配公司">
                    <a:grid bindTarget="assign_company_ds" height="330" navBar="true" width="378">
                        <a:columns>
                            <a:column name="company_code" prompt="公司代码" width="150"/>
                            <a:column name="company_short_name" prompt="公司简称" width="200"/>
                        </a:columns>
                    </a:grid>
                </a:form>
            </a:hBox>
            <!-- <a:grid id="company_result_grid" bindTarget="company_result_ds" height="330" navBar="true" width="340">
                <a:columns>
                    <a:column name="company_code" align="center" autoAdjust="true" prompt="公司代码"/>
                    <a:column name="company_short_name" align="center" autoAdjust="true" prompt="公司名称"/>
                    <a:column name="assign_flag" align="center" editor="company_result_grid_cb" prompt="是否分配"/>
                </a:columns>
                <a:editors>
                    <a:checkBox id="company_result_grid_cb"/>
                </a:editors>
            </a:grid> -->
        </a:screenBody>
        <script type="text/javascript"><![CDATA[
            // Leaf.onReady(function() {
                // //////
                // init();
            // });
        ]]></script>
    </a:view>
</a:screen>
