<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ZLF  
    $Date: 2014-11-25 下午1:49:31  
    $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="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 save() {               
                if(g_item_detail_id == -1){
        	        Leaf.showMessage('提示','请先选择一个合同');
        	        return;
        	    }
        	    // 维护发动机和车架号
        	    $('con_item_info_ds').submit();
        	    if(!!$('ast_car_license_result_ds')){
        	        $('ast_car_license_result_ds').setSubmitParameter('item_detail_id',g_item_detail_id);
        	        $('ast_car_license_result_ds').submit();// 提交牌照信息        	        
        	    }
        	    if(!!$('ast_car_insurance_result_ds')){
        	        // alert(1);
        	        // // 校验保险信息
        	        // var record = $('ast_car_insurance_result_ds').getCurrentRecord();
        	        // alert(record);
        	        // var in_val1 = record.get('compulsory_rebate_rate');
        	        // var in_val2 = record.get('combustion_rebate_rate');
        	        
        	        // if(in_val1<0||in_val>100){
        	            // record.set('compulsory_rebate','');
        	            // Leaf.showMessage('提示','返利率为百分制，只能输入0-100');
        	            // return ;
        	        // }else if(in_val2<0||in_val2>100){
        	            // record.set('combustion_rebate','');
        	            // Leaf.showMessage('提示','返利率为百分制，只能输入0-100');
        	            // return ;
        	        // }
        	        $('ast_car_insurance_result_ds').setSubmitParameter('item_detail_id',g_item_detail_id);
        	        $('ast_car_insurance_result_ds').submit();// 提交保险信息
        	    }
        	    if(!!$('ast_car_condition_result_ds')){
        	        $('ast_car_condition_result_ds').setSubmitParameter('item_detail_id',g_item_detail_id);
        	        $('ast_car_condition_result_ds').submit();// 提交保养信息
        	    }
        	    // GPS信息待定
        	    if(!!$('ast_car_gps_result_ds')){
        	        $('ast_car_gps_result_ds').setSubmitParameter('item_detail_id',g_item_detail_id);
        	        $('ast_car_gps_result_ds').submit();// 提交保养信息
        	    }
        	    
        	    if(!!$('ast_car_trailer_result_ds')){
        	        $('ast_car_trailer_result_ds').setSubmitParameter('item_detail_id',g_item_detail_id);
        	        $('ast_car_trailer_result_ds').submit();// 提交拖车信息
        	    }
            }
            
            function attachment_upload() {
                var header_id = $('con_item_info_ds').getCurrentRecord().get('contract_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) {
                query();
            }
            
            function selectHandler(ds, record) {
                if (record != '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 loadHandler(ds) {
        	    var g_item_detail_id=ds.getCurrentRecord().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();
                }
                //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();
                }
        	 }
        	 
        ]]></script>
        <a:dataSets>
            <a:dataSet id="car_brands_ds" fetchAll="true" loadData="true" model="ast.AST510.hls_car_brands"/>
            <a:dataSet id="car_series_ds" fetchAll="true" model="ast.AST510.hls_car_series"/>
            <a:dataSet id="car_model_ds" fetchAll="true" model="ast.AST510.hls_car_model"/>
            <a:dataSet id="con_item_info_ds" autoCreate="true" autoQuery="true" fetchAll="true" model="ast.AST510.con_contract_item_v" queryUrl="${/request/@context_path}/autocrud/ast.AST510.con_contract_item_v/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="contract_number"/>
                    <a:field name="bp_name"/>
                    <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="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" readOnly="true" uncheckedValue="N"/>
                    <a:field name="registration_flag" checkedValue="Y" defaultValue="N" readOnly="true" uncheckedValue="N"/>
                    <a:field name="purchase_flag" checkedValue="Y" defaultValue="N" readOnly="true" uncheckedValue="N"/>
                    <a:field name="insurance_flag" checkedValue="Y" defaultValue="N" readOnly="true" uncheckedValue="N"/> -->
                </a:fields>
                <a:events>
                    <a:event name="indexChange" handler="selectHandler"/>
                    <a:event name="load" handler="loadHandler"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="license_type_ds" loadData="true" model="ast.AST502.ast_license_type"/>
            <a:dataSet id="mortgage_flag_ds">
                <a:datas>
                    <a:record name="是" code="Y"/>
                    <a:record name="否" code="N"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="ast_car_license_result_ds" model="ast.AST502.ast_car_license">
                <a:fields>
                    <a:field name="ast_car_license_id"/>
                    <a:field name="item_detail_id"/>
                    <a:field name="license_number"/>
                    <a:field name="on_car_date"/>
                    <a:field name="license_fee" required="true"/>
                    <a:field name="license_attach_fee"/>
                    <a:field name="shh_license_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="purchase_date" readOnly="true"/>
                    <a:field name="purchase_price" readOnly="true"/>
                    <a:field name="license_end_date" readOnly="true"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="mortgage_date"/>
                    <a:field name="license_type_des" displayField="code_value_name" options="license_type_ds" returnField="license_type" valueField="code_value"/>
                    <a:field name="license_type"/>
                    <a:field name="license_flag" defaultValue="Y"/>
                    <a:field name="mortgage_flag"/>
                    <a:field name="mortgage_flag_des" displayField="name" options="mortgage_flag_ds" returnField="mortgage_flag" valueField="code"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="ast_car_gps_result_ds" model="ast.AST506.ast_car_gps" selectable="true">
                <a:fields>
                    <a:field name="enabled_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="install_date" required="true"/>
                    <a:field name="imei" required="true"/>
                    <a:field name="install_location" required="true"/>
                    <a:field name="gps_provider_desc" lovHeight="400" lovService="ast.AST506.hls_bp_master_lov" lovWidth="600">
                        <a:mapping>
                            <a:map from="bp_id" to="gps_provider"/>
                            <a:map from="bp_name" to="gps_provider_desc"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="ast_insurance_type_ds" lookupCode="AST_INSURANCE_TYPE"/>
            <a:dataSet id="ast_car_insurance_result_ds" model="ast.AST503.ast_car_insurance" selectable="true">
                <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.AST503.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="document_status" defaultValue="10"/>
                    <a:field name="document_status_des" defaultValue="新建"/>
                    <a:field name="payment_finish_flag" readOnly="true"/>
                    <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="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:field name="insurance_type" required="true"/>
                    <a:field name="insurance_type_desc" displayField="code_value_name" options="ast_insurance_type_ds" required="true" returnField="insurance_type" valueField="code_value"/>
                </a:fields>
            </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.AST503.ast_car_insurance_records" selectable="true">
                <a:fields>
                    <a:field name="damage_serious_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="payment_finish_flag" readOnly="true"/>
                    <a:field name="document_status" defaultValue="10"/>
                    <a:field name="document_status_des" defaultValue="新建"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="ast_car_trailer_result_ds" model="ast.AST505.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:field name="trailer_reason"/>
                    <a:field name="trail_wfl_status"/>
                    <a:field name="trail_fee_status"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:form title="合同信息" width="1300">
                <a:hBox>
                    <a:textField name="contract_number" bindTarget="con_item_info_ds" prompt="合同号" readOnly="true"/>
                    <a:textField name="item_frame_number" bindTarget="con_item_info_ds" prompt="车架号" readOnly="true"/>
                    <a:textField name="bp_name" bindTarget="con_item_info_ds" prompt="承租人" readOnly="true"/>
                    <a:comboBox name="brand_dis" bindTarget="con_item_info_ds" prompt="品牌" readOnly="true"/>
                    <a:comboBox name="series_dis" bindTarget="con_item_info_ds" prompt="车系" readOnly="true"/>
                    <a:comboBox name="model_dis" bindTarget="con_item_info_ds" prompt=" 车型" readOnly="true"/>
                </a:hBox>
            </a:form>
            <a:tabPanel height="450" width="1300">
                <a:tabs>
                    <a:tab prompt="牌照信息" ref="${/request/@context_path}/modules/ast/AST510/ast_car_license.lview" width="100"/>
                    <a:tab prompt="保险信息" ref="${/request/@context_path}/modules/ast/AST510/ast_car_insurance.lview" width="100"/>
                    <a:tab prompt="GPS信息" ref="${/request/@context_path}/modules/ast/AST510/ast_car_gps.lview" width="100"/>
                    <a:tab prompt="拖车记录" ref="${/request/@context_path}/modules/ast/AST510/ast_car_trailer.lview" width="100"/>
                </a:tabs>
                <!--<a:events>
                        <a:event name="select" handler="tabSelectHandler"/>
                    </a:events>-->
            </a:tabPanel>
        </a:screenBody>
    </a:view>
</a:screen>
