<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: liukang 
    $Date: 2016-04-05 上午9:53:03  
    $Revision: 1.0  
    $Purpose: 产品方案授权
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" dynamiccreateenabled="true" trace="true">
    <a:init-procedure><![CDATA[
	]]></a:init-procedure>
    <a:view>
        <a:link id="hls_plan_to_grant_brand_link" url="${/request/@context_path}/modules/hls/HLS051/hls_plan_to_grant_barnd.lview"/>
        <a:link id="hls_plan_to_grant_area_link" url="${/request/@context_path}/modules/hls/HLS051/hls_plan_to_grant_area.lview"/>
        <script type="text/javascript"><![CDATA[
        
          	window['${/parameter/@bp_seq}${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name) {
                var product_grant_id = record.get('product_grant_id');
                if (name == 'province_city_grant') {
                    return '<a  href="javascript:grant_area_window_open(' + product_grant_id + ',\'' + name + '\')">' + '<font color="#FF9900">省市授权</font>' + '</a>';
                }
            };
            
            //更新时调用
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
            	var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_product_plan_to_grant');
            	if (ds_id == ds.id){
            	    if(name=='agent_type'){
            	        if(!value){
            	            record.getField('agent_n').setLovPara('agent_type', value);
            	        }
            	    }
            	}
            };
            
/*             window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
            	var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_product_plan_to_grant');

            	if (ds_id == ds.id){
            	    if(name=='start_date'||name=='end_date'){
            	        var start_date= record.get('start_date')||0;
            			var end_date = record.get('end_date')||0;
            			if(start_date > end_date){
            			    record.set('end_date','');
            			    Leaf.showMessage('开始时间不能小于结束时间','结束时间必须在开始时间之后!');
            			}            			
            	    }
            	}
               }; */
            
            function grant_area_window_open(id, name) {
                if (Ext.isEmpty(id) || id == 'undefined') {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先点击保存!');
                } else {
                    var win = new Leaf.Window({
                        id: 'hls_grant_area_window',
                        url: $('hls_plan_to_grant_area_link').getUrl(),
                        params: {
                            winId: 'hls_grant_area_window',
                            product_grant_id: id
                        },
                        title: '区域授权',
                        height: 700,
                        width: 550
                    });
                }
            }
            
            // function hls051_grant_close() {
                // $('hls_grant_window').close();
            // }
            
            // function hls051_grant_copy(ds, record) {
                // lag = 'Y';
                // var result_ds = $('hls051_plan_to_grant_ds');
                // var records = result_ds.getSelected();
                // if (records.length == 0) {
                    // Leaf.showMessage("提示", "请至少选择一条数据");
                    // return;
                // } else if (records.length > 1) {
                    // Leaf.showMessage("提示", "请选择单条数据进行复制");
                    // return;
                // } else {
                    // $('hls051_plan_to_grant_grid').showEditorByRecord($('hls051_plan_to_grant_ds').create());
                // }
            // }
            // var lag = 'N';
            
            // function grant_add(ds, record, index) {
            
            
                // if (lag == 'Y') {
                    // var select_record = ds.getSelected()[0];
                    // for (var name in select_record.data) {
                        // record.set(name, select_record.get(name));
                        // record.set('product_grant_id', null);
            
                    // }
                // }
                // lag = 'N';
            // }
            
            // function grant_update(dataset, record, name, value, oldvalue) {
            // if (name == 'province_id') {
            // if (value != oldvalue && !Ext.isEmpty(value)) {
            // var v_city_field = record.getField('city_name');
            // v_city_field.setLovModel('hls.HLS051.hls051_fnd_city');
            // v_city_field.setLovPara('province_id', value);
            // record.set('city_id', null);
            // record.set('city_name', null);
            // }
            // }
            // }
            
            // function grant_selected(grid, row, record) {
            // //alert(${/parameter/@product_plan_id});
            // var v_province_id = record.get('province_id');
            // if (typeof(v_province_id) != 'undefined' && !Ext.isEmpty(v_province_id)) {
            // var v_city_field = record.getField('city_name');
            // v_city_field.setLovModel('hls.HLS051.hls051_fnd_city');
            // v_city_field.setLovPara('province_id', v_province_id);
            // }
            // }
            
            // function to_grand_brand(value, record, name) {
                // var product_grant_id = record.get('product_grant_id');
                // if (name == 'grant_brand') {
                    // return '<a  href="javascript:grant_brand_window_open(' + product_grant_id + ',\'' + name + '\')">' + '<font color="#FF9900">授权品牌</font>' + '</a>';
                // }
            // }
            
            // function grant_brand_window_open(id, name) {
                // if (Ext.isEmpty(id) || id == 'undefined') {
                    // Leaf.showMessage('${l:HLS.PROMPT}', '请先点击保存!');
                // } else {
                    // var win = new Leaf.Window({
                        // id: 'hls_grant_brand_window',
                        // url: $('hls_plan_to_grant_brand_link').getUrl(),
                        // params: {
                            // winId: 'hls_grant_brand_window',
                            // product_grant_id: id
                        // },
                        // title: '品牌授权',
                        // height: 700,
                        // width: 550
                    // });
                // }
            // }
            
            
            // function to_grant_area(value, record, name) {
                // var product_grant_id = record.get('product_grant_id');
                // if (name == 'area') {
                    // return '<a  href="javascript:grant_area_window_open(' + product_grant_id + ',\'' + name + '\')">' + '<font color="#FF9900">授权区域</font>' + '</a>';
                // }
            // }
            
            // function grant_area_window_open(id, name) {
                // if (Ext.isEmpty(id) || id == 'undefined') {
                    // Leaf.showMessage('${l:HLS.PROMPT}', '请先点击保存!');
                // } else {
                    // var win = new Leaf.Window({
                        // id: 'hls_grant_area_window',
                        // url: $('hls_plan_to_grant_area_link').getUrl(),
                        // params: {
                            // winId: 'hls_grant_area_window',
                            // product_grant_id: id
                        // },
                        // title: '区域授权',
                        // height: 700,
                        // width: 550
                    // });
                // }
            // }
        ]]></script>
        <!--         <a:dataSets>
            <a:dataSet id="apply_channel_ds" lookupCode="AGENT_GROUP"/>
            <a:dataSet id="car_type_ds" lookupCode="CAR_TYPE"/>
            <a:dataSet id="lease_method_ds" lookupCode="LEASE_TYPE"/>
            <a:dataSet id="customer_type_ds" lookupCode="CUSTOMER_TYPE"/>
            <a:dataSet id="hls051_plan_to_grant_ds" autoPageSize="true" autoQuery="true" model="hls.HLS051.hls051_product_plan_to_grant" queryUrl="${/request/@context_path}/autocrud/hls.HLS051.hls051_product_plan_to_grant/query?product_plan_id=${/parameter/@product_plan_id}" selectable="true">
                <a:fields>
                    <a:field name="apply_channel"/>
                    <a:field name="apply_channel_desc" displayField="code_value_name" options="apply_channel_ds" returnField="apply_channel" valueField="code_value"/>
                    <a:field name="area"/>
                    <a:field name="car_type"/>
                    <a:field name="product_plan_id" defaultValue="${/parameter/@product_plan_id}"/>
                    <a:field name="car_type_desc" displayField="code_value_name" options="car_type_ds" returnField="car_type" valueField="code_value"/>
                    <a:field name="lease_method"/>
                    <a:field name="lease_method_desc" displayField="code_value_name" options="lease_method_ds" returnField="lease_method" valueField="code_value"/>
                    <a:field name="customer_type"/>
                    <a:field name="customer_type_desc" displayField="code_value_name" options="customer_type_ds" returnField="customer_type" valueField="code_value"/>
                    <a:field name="brand_id"/>

                    <a:field name="grant_brand"/>
                    <a:field name="province_id"/>
                    <a:field name="province_name" lovGridHeight="320" lovHeight="460" lovLabelWidth="120" lovService="hls.HLS051.hls051_fnd_province" lovWidth="500">
                        <a:mapping>
                            <a:map from="description" to="province_name"/>
                            <a:map from="province_id" to="province_id"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="city_id"/>
                    <a:field name="city_name" lovGridHeight="320" lovHeight="460" lovLabelWidth="120" lovWidth="500">
                        <a:mapping>
                            <a:map from="description" to="city_name"/>
                            <a:map from="city_id" to="city_id"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id"/>
                    <a:field name="grant_company" lovGridHeight="320" lovHeight="460" lovLabelWidth="120" lovService="hls.HLS051.hls051_grant_company" lovWidth="500">
                        <a:mapping>
                            <a:map from="description" to="grant_company"/>
                            <a:map from="bp_id" to="bp_id"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
                <a:events>

                    <a:event name="add" handler="grant_add"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="hls051_grant_close" text="退出"/>
                <a:gridButton click="hls051_grant_copy" text="复制"/>
            </a:screenTopToolbar>
            <a:grid id="hls051_plan_to_grant_grid" bindTarget="hls051_plan_to_grant_ds" marginHeight="180" marginWidth="15" navBar="true">
                <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="save"/>
                    <a:button type="delete"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="car_type_desc" align="center" autoAdjust="true" editor="editor_grant_comb" prompt="车辆类型"/>
                    <a:column name="apply_channel_desc" align="center" autoAdjust="true" editor="editor_grant_comb" prompt="申请渠道"/>
                    <a:column name="lease_method_desc" align="center" autoAdjust="true" editor="editor_grant_comb" prompt="租赁方式"/>
                    <a:column name="customer_type_desc" align="center" autoAdjust="true" editor="editor_grant_comb" prompt="客户类型"/>
                    <a:column name="grant_brand" align="center" autoAdjust="true" prompt="授权品牌" renderer="to_grand_brand"/>

                    <a:column name="area" align="center" autoAdjust="true" prompt="授权区域" renderer="to_grant_area"/>
                    <a:column name="grant_company" align="center" autoAdjust="true" editor="editor_lov" prompt="授权公司"/>
                    <a:column name="start_date" align="center" autoAdjust="true" editor="date_dp" prompt="开始时间" renderer="Leaf.formatDate"/>
                    <a:column name="end_date" align="center" autoAdjust="true" editor="date_dp" prompt="结束时间" renderer="Leaf.formatDate"/>
                </a:columns>
                <a:editors>
                    <a:comboBox id="editor_grant_comb"/>
                    <a:lov id="province_lov"/>
                    <a:lov id="city_lov"/>
                    <a:lov id="editor_lov"/>
                    <a:datePicker id="date_dp"/>
                </a:editors>

            </a:grid>
        </a:screenBody> -->
    </a:view>
</a:screen>