<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qm  
    $Date: 2014-4-18 下午1:49:31  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view>
        <a:link id="lease_item_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <script type="text/javascript"><![CDATA[
            //var g_item_detail_id = -1;
            
            function reset() {
                $('con_item_info_query_ds').reset();
            }
            
            function query() {
                $('con_item_info_ds').query();
            }
            
            
            function attachment_upload() {
                var header_id = g_item_detail_id;
                var url = $('lease_item_uploadFile_id').getUrl() + '?table_name=CON_CONTRACT_ITEM_DETAIL&header_id=' + header_id;
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'item_detail_uploadFile_id',
                    width: 850,
                    height: 400
                });
                win.on('close', function() {});
            }
            
            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 updateHandler(ds, rec, name, val, oldVal) {
                if (name == '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') {
                    $('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 enterdownHandler(felid, evt) {
                $('con_item_info_ds').query();
            }
            
            function selectHandler(ds, record) {
                //if (rec != 'test') {
                    g_item_detail_id = record.get('item_detail_id'); // 保留全局
                //}
                if ( !! $('ast_car_license_result_ds')) {
                    $('ast_car_license_result_ds').setQueryParameter('item_detail_id', g_item_detail_id);
                    $('ast_car_license_result_ds').query();
                }
                if ( !! $('ast_car_insurance_result_ds')) {
                    $('ast_car_insurance_result_ds').setQueryParameter('item_detail_id', g_item_detail_id);
                    $('ast_car_insurance_result_ds').query();
                }
                if ( !! $('ast_car_condition_result_ds')) {
                    $('ast_car_condition_result_ds').setQueryParameter('item_detail_id', g_item_detail_id);
                    $('ast_car_condition_result_ds').query();
                }
                //GPS待定
                if ( !! $('ast_car_gps_result_ds')) {
                    $('ast_car_gps_result_ds').setQueryParameter('item_detail_id', g_item_detail_id);
                    $('ast_car_gps_result_ds').query();
                }
                if ( !! $('ast_car_trailer_result_ds')) {
                    $('ast_car_trailer_result_ds').setQueryParameter('item_detail_id', g_item_detail_id);
                    $('ast_car_trailer_result_ds').query();
                }
            }
            function insuranceUpdateHandler(ds,rec,name,val,oldVal){      	    
        	    if(name == 'insurance_date_from'){
        	    	rec.set('insurance_year',val.getFullYear());  	        
        	    }else if(name == 'insurance_date_to' && val != null){
        	        if(val < rec.get('insurance_date_from')){
	        	        Leaf.showMessage('提示','终止日期不能小于于开始日期');
	        	        rec.set('insurance_date_to',null);
        	        }
        	    }else if(name == 'compulsory_rebate_rate'){// 计算返利
        	        var val1 = rec.get('compulsory_insurance_amount');        	        
        	        rec.set('compulsory_rebate',val1*val/100);
        	    }else if(name == 'combustion_rebate_rate'){
        	        var val2 = rec.get('commercial_insurance_amount');
        	        rec.set('combustion_rebate',val2*val/100);
        	        
        	    }else if(name == 'commercial_insurance_amount'){
        	        if(val == null || val == ''){
        	            rec.getField('combustion_rebate_rate').setReadOnly(true);
        	        }else{
        	            rec.getField('combustion_rebate_rate').setReadOnly(false);
        	        }
        	    } else if(name == 'compulsory_insurance_amount'){
        	        if(val == null || val == ''){
        	            rec.getField('compulsory_rebate_rate').setReadOnly(true);
        	        }else{
        	            rec.getField('compulsory_rebate_rate').setReadOnly(false);
        	        }
        	    }  	    
        	}
        	function insuranceSelectHandler(ds,rec){
        	    if(!!rec.get('ast_car_insurance_id')){
        	        $('ast_car_insurance_records_ds').setQueryParameter('ast_car_insurance_id',rec.get('ast_car_insurance_id'));
        	    	$('ast_car_insurance_records_ds').query();
        	    }       	    
        	}
        	function commercial_renderer(val,rec,name){
        	    if(rec.get('commercial_insurance_amount') == null || rec.get('commercial_insurance_amount')==''){
        	        rec.getField('combustion_rebate_rate').setReadOnly(true);
        	    }else{
        	        rec.getField('combustion_rebate_rate').setReadOnly(false);
        	    }
        	    return Leaf.formatMoney(val);
        	}
        	
        	function compulsory_renderer(val,rec,name){
        	    if(rec.get('compulsory_insurance_amount') == null || rec.get('compulsory_insurance_amount')==''){
        	        rec.getField('compulsory_rebate_rate').setReadOnly(true);
        	    }else{
        	        rec.getField('compulsory_rebate_rate').setReadOnly(false);
        	    }
        	    return Leaf.formatMoney(val);
        	}
            /*
             function queryHandler(ds) {
             // 合同头信息查询为空时,置空全局
             if ( !! ds.getCurrentRecord()) {
             g_item_detail_id = -1;
             selectHandler('', 'test');
             }
             }*/
        ]]></script>
        <a:dataSets>
            <a:dataSet id="car_brands_ds" fetchAll="true" loadData="true" model="ast.AST301.hls_car_brands"/>
            <a:dataSet id="car_series_ds" fetchAll="true" model="ast.AST301.hls_car_series"/>
            <a:dataSet id="car_model_ds" fetchAll="true" model="ast.AST301.hls_car_model"/>
            <a:dataSet id="con_item_info_query_ds">
                <a:fields>
                    <a:field name="contract_number"/>
                    <a:field name="item_frame_number"/>
                    <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:fields>
                <a:events>
                    <a:event name="update" handler="updateHandler"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="con_item_info_ds" autoQuery="true" model="ast.AST301.con_contract_item_v" queryDataSet="con_item_info_query_ds" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="contract_number"/>
                    <a:field name="brand_dis"/>
                    <a:field name="series_dis"/>
                    <a:field name="model_dis"/>
                    <a:field name="color_of_apprearance"/>
                    <a:field name="color_of_decoration"/>
                    <a:field name="item_frame_number"/>
                    <a:field name="item_engine_number"/>
                    <a:field name="key_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="registration_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="purchase_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="insurance_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                </a:fields>
                <a:events>
                    <a:event name="indexChange" handler="selectHandler"/>
                    <!--<a:event name="query" handler="queryHandler"/>-->
                </a:events>
            </a:dataSet>
            <a:dataSet id="ast_car_insurance_result_ds" loadData="true" model="ast.AST301.ast_car_insurance" selectable="true" selectionModel="single" submitUrl="${/request/@context_path}/modules/ast/AST301/ast_car_insurance_save.lsc">
                <a:fields>
                    <a:field name="ast_car_insurance_id"/>
                    <a:field name="item_detail_id"/>
                    <a:field name="bp_id"/>
                    <a:field name="insurer_dis" lovHeight="500" lovService="ast.AST301.ast_query_insurer_info" lovWidth="500" required="true" title="保险公司">
                        <a:mapping>
                            <a:map from="bp_name" to="insurer_dis"/>
                            <a:map from="bp_id" to="bp_id"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="insurance_number"/>
                    <a:field name="insurance_description"/>
                    <a:field name="insure_date"/>
                    <a:field name="insurance_date_from"/>
                    <a:field name="insurance_date_to"/>
                    <a:field name="insurance_year"/>
                    <a:field name="compulsory_insurance_amount"/>
                    <a:field name="commercial_insurance_amount"/>
                    <a:field name="damage_insurance_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="third_party_insurance_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="pilfer_insurance_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="basic_non_deductible_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="glass_insurance_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="seat_insurance_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="combustion_insurance_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="add_non_deductible_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="compulsory_rebate_rate"/>
                    <a:field name="combustion_rebate_rate"/>
                    <a:field name="compulsory_rebate"/>
                    <a:field name="combustion_rebate"/>
                    <a:field name="insure_place"/>
                    <a:field name="insure_name"/>
                    <a:field name="first_beneficiary"/>
                    <a:field name="insurance_party"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="insuranceUpdateHandler"/>
                    <a:event name="select" handler="insuranceSelectHandler"/>
                </a:events>
            </a:dataSet>
            <!-- queryUrl="${/request/@context_path}/autocrud/ast.AST501.ast_car_insurance_records" -->
            <a:dataSet id="ast_car_insurance_records_ds" bindName="records_info" bindTarget="ast_car_insurance_result_ds" model="ast.AST301.ast_car_insurance_records" selectable="true"><![CDATA[
            ]]></a:dataSet>
            <a:dataSet id="ast_car_trailer_result_ds" model="ast.AST301.ast_car_trailer" selectable="true">
                <a:fields>
                    <a:field name="ast_car_trailer_id"/>
                    <a:field name="item_detail_id"/>
                    <a:field name="trailer_date"/>
                    <a:field name="trailer_place"/>
                    <a:field name="trailer_partner"/>
                    <a:field name="trailer_fee"/>
                    <a:field name="trailer_result"/>
                    <a:field name="disposal_scheme"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="ast_car_condition_result_ds" model="ast.AST301.ast_car_condition" selectable="true">
                <a:fields>
                    <a:field name="ast_car_condition_id"/>
                    <a:field name="item_detail_id"/>
                    <a:field name="maintenance_date"/>
                    <a:field name="maintenance_place"/>
                    <a:field name="maintenance_content"/>
                    <a:field name="salvage_value"/>
                    <a:field name="vendibility"/>
                    <a:field name="mileage"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="ast_car_gps_result_ds" model="ast.AST301.ast_car_gps" selectable="true">
                <a:fields>
                    <a:field name="enabled_flag" checkedValue="Y" uncheckedValue="N"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:form marginWidth="30" title="合同租赁物维护">
                <a:screenTopToolbar>
                    <a:screenTitle/>
                    <a:gridButton click="query" text="查询"/>
                    <a:gridButton click="reset" text="重置"/>
                    <a:gridButton click="attachment_upload" text="附件上传"/>
                </a:screenTopToolbar>
                <a:form marginWidth="40" title="HLS.QUERY_TITLE">
                    <a:hBox>
                        <a:textField name="contract_number" bindTarget="con_item_info_query_ds" prompt="合同号">
                            <a:events>
                                <a:event name="enterdown" handler="enterdownHandler"/>
                            </a:events>
                        </a:textField>
                        <a:textField name="item_frame_number" bindTarget="con_item_info_query_ds" prompt="车架号">
                            <a:events>
                                <a:event name="enterdown" handler="enterdownHandler"/>
                            </a:events>
                        </a:textField>
                        <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="enterdownHandler"/>
                            </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="enterdownHandler"/>
                            </a:events>
                        </a:comboBox>
                        <a:comboBox name="model_dis" bindTarget="con_item_info_query_ds" prompt=" 车型">
                            <a:events>
                                <a:event name="enterdown" handler="enterdownHandler"/>
                            </a:events>
                        </a:comboBox>
                    </a:hBox>
                </a:form>
                <a:grid bindTarget="con_item_info_ds" height="200" marginWidth="40" navBar="true">
                    <a:columns>
                        <a:column name="contract_number" prompt="合同号" width="120"/>
                        <a:column name="brand_dis" prompt="品牌" width="80"/>
                        <a:column name="series_dis" prompt="车系" width="80"/>
                        <a:column name="model_dis" prompt="车型" width="110"/>
                        <a:column name="color_of_apprearance" prompt="外观颜色" width="80"/>
                        <a:column name="color_of_decoration" prompt="内饰颜色" width="80"/>
                        <a:column name="item_frame_number" prompt="车架号" width="100"/>
                        <a:column name="item_engine_number" prompt="发动机号" width="100"/>
                        <a:column name="key_flag" prompt="钥匙" width="80"/>
                        <a:column name="registration_flag" prompt="登记证" width="80"/>
                        <a:column name="purchase_flag" prompt="购置税证" width="80"/>
                        <a:column name="insurance_flag" prompt="保单" width="80"/>
                    </a:columns>
                    <a:editors>
                        <a:textField id="item_info_tf"/>
                        <a:checkBox id="item_info_cb"/>
                    </a:editors>
                </a:grid>
                <a:tabPanel height="450" marginWidth="40">
                    <a:tabs>
                        <a:tab prompt="牌照信息" ref="${/request/@context_path}/modules/ast/AST301/ast_car_license.lview" width="100"/>
                        <a:tab prompt="保险信息" ref="${/request/@context_path}/modules/ast/AST301/ast_car_insurance.lview" width="100"/>
                        <a:tab prompt="车况信息" ref="${/request/@context_path}/modules/ast/AST301/ast_car_condition.lview" width="100"/>
                        <a:tab prompt="GPS信息" ref="${/request/@context_path}/modules/ast/AST301/ast_car_gps.lview" width="100"/>
                        <a:tab prompt="拖车记录" ref="${/request/@context_path}/modules/ast/AST301/ast_car_trailer.lview" width="100"/>
                    </a:tabs>
                    <!--<a:events>
                        <a:event name="select" handler="tabSelectHandler"/>
                    </a:events>-->
                </a:tabPanel>
            </a:form>
        </a:screenBody>
    </a:view>
</a:screen>