<?xml version="1.0" encoding="UTF-8"?>
<!--
  &author:  HAND技术
  $date:    2013/12/12
  $purpose: 汽车品牌、车系、车型定义
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:view>
        <script type="text/javascript"><![CDATA[
            function HLS222_brandDsGridQuery() {
                $('HLS222_brandDs').query();
            }
            
            function HLS222_brandDsGridAdd() {
                $('HLS222_brandDsGrid').showEditorByRecord($('HLS222_brandDs').create());
            }
            
            function HLS222_seriesDsGridAdd() {
                var brandDs = $('HLS222_brandDs');
                var record = brandDs.getCurrentRecord();
                if (Ext.isEmpty(record)) {
                    return;
                } else if (record.isNew) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS222.SAVE_FIRST}');
                    return;
                }
                $('HLS222_seriesDsGrid').showEditorByRecord($('HLS222_seriesDs').create({
                    brand_id: record.get('brand_id')
                }));
            
            }
            
            function HLS222_modelDsGridAdd() {
                var brandDs = $('HLS222_brandDs');
                var seriesDs = $('HLS222_seriesDs');
                var record1 = brandDs.getCurrentRecord();
                var record2 = seriesDs.getCurrentRecord();
                if (Ext.isEmpty(record1)||Ext.isEmpty(record2)) {
                    return;
                } else if (record1.isNew||record2.isNew) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS222.SAVE_FIRST2}');
                    return;
                }
                $('HLS222_modelDsGrid').showEditorByRecord($('HLS222_modelDs').create({
                    brand_id: record1.get('brand_id'),
                    series_id: record2.get('series_id')
                }));
            
            }
            
            function HLS222_brandDsGridClear() {
                $('HLS222_brandDsGrid').clear();
            }
            
            function HLS222_seriesDsGridClear() {
                $('HLS222_seriesDsGrid').clear();
            }
            
            function HLS222_modelDsGridClear() {
                $('HLS222_modelDsGrid').clear();
            }
            
            function HLS222_brandDsGridSave() {
                var result_ds = $('HLS222_brandDs');
                if (result_ds.validate()) {
                    result_ds.submit();
                }
                HLS222_brandDsGridQuery();
  
            }
            
            function HLS222_editorFunctionBrandDsGrid(record, name) {
                if (record.isNew) {
                    if (name == 'brand_code') {
                        return 'HLS222_brandDsGridEditorTfUpper';
                    }
                }
                return '';
            }
            
            function HLS222_editorFunctionSeriesDsGrid(record, name) {
                if (record.isNew) {
                    if (name == 'series_code') {
                        return 'HLS222_seriesDsGridEditorTfUpper';
                    }
                }
                return '';
            }
            
            function HLS222_editorFunctionModelDsGrid(record, name) {
                if (record.isNew) {
                    if (name == 'model_code') {
                        return 'HLS222_modelDsGridEditorTfUpper';
                    }
                }
                return '';
            }
            // function updateHandler(ds, record, name, value, oldVlaue) {
                // if (name == 'brand_dis') {
                    // var brand_id = record.get('brand_id');
                    // //
                    // record.getField('series_dis').setLovPara('brand_id', brand_id);
                // } else if (name == 'series_dis') {
                    // var series_id = record.get('series_id');
                    // //
                    // record.getField('model_dis').setLovPara('series_id', series_id);
                // }
            // }
            function updateHandler(dataset, record, name, value, oldvalue) {
                //
                if(name == 'brand_id'){
                    record.getField('series_dis').setLovPara('province_id', value);
                }
                // record.getField('series_dis').setLovPara('brand_id', record.get('brand_id'));
                // record.getField('model_dis').setLovPara('brand_id', record.get('brand_id'));
                // record.getField('model_dis').setLovPara('series_id', record.get('series_id'));
                if (name == 'brand_id') {
                    var series_lovField = record.getMeta().getField("series_dis");
                    series_lovField.setLovPara('brand_id', record.get('brand_id'));
                    // $('car_series_ds').setQueryParameter('brand_id', $('con_item_info_query_ds').getCurrentRecord().get('brand_id'));
                    // $('car_series_ds').query();
                } else if (name == 'series_id') {
                    var model_lovField = record.getMeta().getField("model_dis");
                    model_lovField.setLovPara('series_id', record.get('series_id'));
                    // $('car_model_ds').setQueryParameter('brand_id', $('con_item_info_query_ds').getCurrentRecord().get('brand_id'));
                    // $('car_model_ds').setQueryParameter('series_id', $('con_item_info_query_ds').getCurrentRecord().get('series_id'));
                    // $('car_model_ds').query();
                }
            }
            
            function changeHandler(th, val, oldVal) {
                if (th == $('brand_dis_id')) {
                    $('con_item_info_query_ds').getCurrentRecord().set('series_dis', '');
                    $('con_item_info_query_ds').getCurrentRecord().set('series_id', '');
                    $('con_item_info_query_ds').getCurrentRecord().set('model_dis', '');
                    $('con_item_info_query_ds').getCurrentRecord().set('model_id', '');
                } else if (th == $('series_dis_id')) {
                    $('con_item_info_query_ds').getCurrentRecord().set('model_dis', '');
                    $('con_item_info_query_ds').getCurrentRecord().set('model_id', '');
                }
            }
           
           function brands_query(){
               $('car_brands_ds').query();
           }    
            
        ]]></script>
        <a:dataSets>
            <!--  <a:dataSet id="car_brands_ds" fetchAll="true" loadData="true" model="hls.HLS222.hls_car_brands"/>
            <a:dataSet id="car_series_ds" fetchAll="true" model="hls.HLS222.hls_car_series"/>
            <a:dataSet id="car_model_ds" fetchAll="true" model="hls.HLS222.hls_car_model"/> -->
            <a:dataSet id="hls_vehicle_type_ds" lookupCode="HLS_VEHICLE_TYPE"/>
            <a:dataSet id="plate_ds" lookupCode="CAR_GRADE"/>
            <a:dataSet id="con_item_info_query_ds" autoCreate="true">
                <a:fields>
                    <!-- <a:field name="brand_id"/>
                    <a:field name="brand_dis" displayField="brand_dis" options="car_brands_ds" returnField="brand_id" valueField="brand_id"/>
                    <a:field name="series_id"/>
                    <a:field name="series_dis" displayField="series_dis" options="car_series_ds" returnField="series_id" valueField="series_id"/>
                    <a:field name="model_id"/>
                    <a:field name="model_dis" displayField="model_dis" options="car_model_ds" returnField="model_id" valueField="model_id"/> -->
                    <a:field name="brand_id"/>
                    <a:field name="brand_dis" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="ast.AST606.hls_car_brands_vl" lovWidth="500">
                        <a:mapping>
                            <a:map from="brand_id" to="brand_id"/>
                            <a:map from="description" to="brand_dis"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="series_id"/>
                    <a:field name="series_dis" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="ast.AST606.hls_car_series_vl" lovWidth="500">
                        <a:mapping>
                            <a:map from="series_id" to="series_id"/>
                            <a:map from="description" to="series_dis"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="model_id"/>
                    <a:field name="model_dis" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="ast.AST606.hls_car_model_vl" lovWidth="700">
                        <a:mapping>
                            <a:map from="model_id" to="model_id"/>
                            <a:map from="description" to="model_dis"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="updateHandler"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="HLS222_brandDs" autoQuery="true" fetchAll="true" model="hls.HLS222.hls_car_brands_for_maintain" queryDataSet="con_item_info_query_ds" selectable="true" selectionModel="single" submitUrl="hls_car_brands_series.lsc">
                <a:fields>
                    <a:field name="brand_code" required="true"/>
                    <a:field name="description" required="true"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                </a:fields>
                <a:events>
                    <!-- <a:event name="submitsuccess" handler="brands_query"/> --><![CDATA[
                    
                ]]></a:events>
            </a:dataSet>
            <a:dataSet id="HLS222_seriesDs" bindName="series_info" bindTarget="HLS222_brandDs" fetchAll="true" model="hls.HLS222.hls_car_series_for_maintain" queryDataSet="con_item_info_query_ds" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="series_code" required="true"/>
                    <a:field name="description" required="true"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <a:field name="guide_price"/>
                    <a:field name="vehicle_type_desc" displayField="code_value_name" options="hls_vehicle_type_ds" returnField="vehicle_type" valueField="code_value"/>
                    <a:field name="plate_id_n" displayField="code_value_name" options="plate_ds" returnField="plate_id" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="HLS222_modelDs" bindName="model_info" bindTarget="HLS222_seriesDs" fetchAll="true" model="hls.HLS222.hls_car_model_for_maintain" queryDataSet="con_item_info_query_ds" selectable="true">
                <a:fields>
                    <a:field name="model_code" required="true"/>
                    <a:field name="description" required="true"/>
                    <a:field name="price" required="false"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <a:field name="exceed_price_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="HLS222_brandDsGridQuery" text="HLS.QUERY"/>
                <a:gridButton click="HLS222_brandDsGridAdd" text="新增品牌"/>
                <a:gridButton click="HLS222_brandDsGridClear" text="移除品牌"/>
                <a:gridButton click="HLS222_seriesDsGridAdd" text="新增车系"/>
                <a:gridButton click="HLS222_seriesDsGridClear" text="移除车系"/>
                <a:gridButton click="HLS222_modelDsGridAdd" text="新增车型"/>
                <a:gridButton click="HLS222_modelDsGridClear" text="移除车型"/>
                <a:gridButton click="HLS222_brandDsGridSave" text="HLS.SAVE"/>
            </a:screenTopToolbar>
            <a:form column="3">
                <!-- <a:comboBox name="brand_dis" id="brand_dis_id" bindTarget="con_item_info_query_ds" prompt="品牌">
                    <a:events>
                        <a:event name="change" handler="changeHandler"/>
                        <a:event name="enterdown" handler="HLS222_brandDsGridQuery"/>
                    </a:events>
                </a:comboBox>
                <a:comboBox name="series_dis" id="series_dis_id" bindTarget="con_item_info_query_ds" prompt="车系">
                    <a:events>
                        <a:event name="change" handler="changeHandler"/>
                        <a:event name="enterdown" handler="HLS222_brandDsGridQuery"/>
                    </a:events>
                </a:comboBox>
                <a:comboBox name="model_dis" bindTarget="con_item_info_query_ds" prompt=" 车型">
                    <a:events>
                        <a:event name="enterdown" handler="HLS222_brandDsGridQuery"/>
                    </a:events>
                </a:comboBox> -->
                <a:lov name="brand_dis" bindTarget="con_item_info_query_ds" prompt="品牌"/>
                <a:lov name="series_dis" bindTarget="con_item_info_query_ds" prompt="车系"/>
                <a:lov name="model_dis" bindTarget="con_item_info_query_ds" prompt="车型"/>
            </a:form>
            <a:grid id="HLS222_brandDsGrid" bindTarget="HLS222_brandDs" height="165" marginWidth="50">
                <a:columns>
                    <a:column name="brand_code" align="center" editorFunction="HLS222_editorFunctionBrandDsGrid" prompt="品牌代码" width="200"/>
                    <a:column name="description" editor="HLS222_brandDsGridEditorTf" prompt="品牌名称" width="400"/>
                    <a:column name="enabled_flag" align="center" editor="HLS222_brandDsGridEditorCheck" width="100"/>
                </a:columns>
                <a:editors>
                    <a:textField id="HLS222_brandDsGridEditorTfUpper" maxLength="30" typeCase="upper"/>
                    <a:textField id="HLS222_brandDsGridEditorTf"/>
                    <a:checkBox id="HLS222_brandDsGridEditorCheck"/>
                </a:editors>
            </a:grid>
            <a:grid id="HLS222_seriesDsGrid" bindTarget="HLS222_seriesDs" height="150" marginWidth="50">
                <a:toolBar>
                    <a:button type="excel"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="series_code" align="center" editorFunction="HLS222_editorFunctionSeriesDsGrid" prompt="车系代码" width="200"/>
                    <a:column name="description" editor="HLS222_seriesDsGridEditorTf" prompt="车系名称" width="400"/>
                    <a:column name="enabled_flag" align="center" editor="HLS222_seriesDsGridEditorCheck" width="100"/>
                    <a:column name="guide_price" align="center" editor="HLS222_seriesDsGridEditorTf" prompt="指导价" width="100"/>
                    <a:column name="vehicle_type_desc" align="center" editor="HLS222_seriesDsGridEditorCb" prompt="车辆类型" width="100"/>
                    <!-- <a:column name="plate_id_n" editor="HLS222_seriesDsGridEditorCb" prompt="平台" width="80"/> -->
                </a:columns>
                <a:editors>
                    <a:comboBox id="HLS222_seriesDsGridEditorCb"/>
                    <a:textField id="HLS222_seriesDsGridEditorTfUpper" maxLength="30" typeCase="upper"/>
                    <a:textField id="HLS222_seriesDsGridEditorTf"/>
                    <a:checkBox id="HLS222_seriesDsGridEditorCheck"/>
                </a:editors>
            </a:grid>
            <a:grid id="HLS222_modelDsGrid" bindTarget="HLS222_modelDs" height="150" marginWidth="50">
                <a:columns>
                    <a:column name="model_code" align="center" editor="HLS222_modelDsGridEditorTf" prompt="车型代码" width="200"/>
                    <a:column name="description" editor="HLS222_modelDsGridEditorTf" prompt="车型名称" width="300"/>
                    <a:column name="price" align="right" editor="HLS222_modelDsGridEditorNf" prompt="厂商指导价" width="100"/>
                    <a:column name="enabled_flag" align="center" editor="HLS222_modelDsGridEditorCheck" width="100"/>
                    <!-- <a:column name="exceed_price_flag" align="center" editor="HLS222_modelDsGridEditorCheck" prompt="是否允许超过厂商指导价" width="150"/> -->
                </a:columns>
                <a:editors>
                    <a:textField id="HLS222_modelDsGridEditorTf"/>
                    <a:checkBox id="HLS222_modelDsGridEditorCheck"/>
                    <a:numberField id="HLS222_modelDsGridEditorNf" allowDecimals="true" allowFormat="true" allowNegative="false" decimalPrecision="2"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
