<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ZLF 
    $Date: 2014-10-30 上午11:26:26  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view>
        <a:link id="item_detail_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="get_atm_id_exist" model="ast.AST503.fnd_atm_attachment_multi" modelaction="query"/>
        <script type="text/javascript"><![CDATA[
            var g_item_detail_id = -1;
            var bak_datas = [];
            
            function attachment_upload(val, rec, name) {
                return '<a href=javascript:detail_upload_window(' + rec.get('item_detail_id') + ')>附件上传</a>';
            }
            
            function detail_upload_window(record_id) {
                if (Leaf.isEmpty(record_id)) {
                    Leaf.showMessage('提示', '请先保存再上传附件！');
                    return;
                }
                var url = $('item_detail_uploadFile_id').getUrl() + '?table_name=CON_CONTRACT_ITEM_DETAIL&header_id=' + record_id;
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'insurance_records_uploadFile_id',
                    width: 850,
                    height: 400
                });
                win.on('close', function() {});
            }
            
            
            
            function reset() {
                $('con_item_info_query_ds').reset();
            }
            
            function back() {
                $('contract_lease_item_maintain_window').close();
            }
            
            function query() {
                $('con_item_info_ds').query();
            }
            
            function save() {
                /*if (g_item_detail_id == -1) {
                 Leaf.showMessage('提示', '请先选择一个合同');
                 return;
                 }*/
                // 必须上传附件
                var item_detail_id=$('con_item_info_ds').getCurrentRecord().get('item_detail_id');
                Leaf.request({
                        url: $('get_atm_id_exist').getUrl(),
                        para: {
                            table_name: 'CON_CONTRACT_ITEM_DETAIL',
                            table_pk_value: item_detail_id
            
                        },
                        success: function(res) {
                            var count = res.result.record['atm_num'];
                            if (count > 0) {
                                $('con_item_info_ds').setSubmitParameter('contract_lease_item_id','${/parameter/@contract_lease_item_id}');
                    			$('con_item_info_ds').setSubmitParameter('contract_id','${/parameter/@contract_id}');
                    			$('con_item_info_ds').submit();
                            } else {
                                Leaf.showMessage('提示', '请先上传相关附件');
                            }
                        }
                    });
                
                /*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_trailer_result_ds')) {
                 $('ast_car_trailer_result_ds').setSubmitParameter('item_detail_id', g_item_detail_id);
                 $('ast_car_trailer_result_ds').submit(); // 提交拖车信息
                 }*/
            }
            
            
            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 enterdownHandler(felid, evt) {
                $('con_item_info_ds').query();
            }
            /*
             function selectHandler(ds,rec){
             if(rec != 'test'){
             g_item_detail_id = rec.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_trailer_result_ds')){
             $('ast_car_trailer_result_ds').setQueryParameter('item_detail_id',g_item_detail_id);
             $('ast_car_trailer_result_ds').query();
             }
             }
             function tabSelectHandler(tabPabel,index,tab){
             if(g_item_detail_id == -1){
             return;
             }
             if(0 == index){// 车牌
             //alert(g_item_detail_id);
             $('ast_car_license_result_ds').setQueryParameter('item_detail_id',g_item_detail_id);
             $('ast_car_license_result_ds').query();
             }else if(1 == index){// 保险
             $('ast_car_insurance_result_ds').setQueryParameter('item_detail_id',g_item_detail_id);
             $('ast_car_insurance_result_ds').query();
             }else if(2 == index){// 车况
             $('ast_car_condition_result_ds').setQueryParameter('item_detail_id',g_item_detail_id);
             $('ast_car_condition_result_ds').query();
             }else if(3 == index){// gps
             }else if(4 == index){// 拖车
             $('ast_car_trailer_result_ds').setQueryParameter('item_detail_id',g_item_detail_id);
             $('ast_car_trailer_result_ds').query();
             }
             }
             function queryHandler(ds){
             // 合同头信息查询为空时，置空全局
             if(!!ds.getCurrentRecord()){
             g_item_detail_id = -1;
             selectHandler('','test');
             }
             }
             */
            
            function loadHandler(ds) {
                var records = ds.getAll();
                for (var i = 0;i < records.length;i++) {
                    var record = records[i];
                    for (var name in record.data) {
                        var bak_name = name + '_bak';
                        record.set(bak_name, record.get(name));
                    }
                }
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="car_brands_ds" fetchAll="true" loadData="true" model="ast.AST501.hls_car_brands"/>
            <a:dataSet id="car_series_ds" fetchAll="true" model="ast.AST501.hls_car_series"/>
            <a:dataSet id="car_model_ds" fetchAll="true" model="ast.AST501.hls_car_model"/>
            <a:dataSet id="con_lease_item_ds" autoQuery="true" model="cont.CON500.con_lease_item_query_by_id" queryUrl="${/request/@context_path}/autocrud/cont.CON500.con_lease_item_query_by_id/query?contract_lease_item_id=${/parameter/@contract_lease_item_id}">
                <a:fields>
                    <a:field name="contract_number" readOnly="true"/>
                    <a:field name="brand_dis" readOnly="true"/>
                    <a:field name="series_dis" readOnly="true"/>
                    <a:field name="model_dis" readOnly="true"/>
                    <a:field name="color_of_apprearance" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_item_info_query_ds">
                <a:fields>
                    <a:field name="item_engine_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:dataSet>
            <a:dataSet id="con_item_info_ds" autoPageSize="true" autoQuery="true" model="cont.CON500.con_contract_item_detail" queryDataSet="con_item_info_query_ds" queryUrl="${/request/@context_path}/autocrud/cont.CON500.con_contract_item_detail/query?contract_lease_item_id=${/parameter/@contract_lease_item_id}">
                <a:fields>
                    <a:field name="item_frame_number" required="true"/>
                    <a:field name="item_engine_number" required="true"/>
                </a:fields>
                <a:events>
                    <a:event name="load" handler="loadHandler"/>
                </a:events>
                <!--<a:events>
                    <a:event name="select" handler="selectHandler"/>
                    <a:event name="query" handler="queryHandler"/>
                </a:events>-->
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:form marginWidth="80" title="合同租赁物维护">
                <a:screenTopToolbar>
                    <a:screenTitle/>
                    <a:gridButton click="back" text="后退"/>
                    <!-- <a:gridButton click="query" text="查询"/>
                    <a:gridButton click="reset" text="重置"/> -->
                    <a:gridButton click="save" text="保存"/>
                    <!--  <a:gridButton click="attachment_upload" text="附件上传"/> -->
                </a:screenTopToolbar>
                <a:form marginWidth="80" title="车辆信息">
                    <a:hBox>
                        <a:textField name="contract_number" bindTarget="con_lease_item_ds" prompt="合同号"/>
                        <a:textField name="brand_dis" bindTarget="con_lease_item_ds" prompt="品牌"/>
                        <a:textField name="series_dis" bindTarget="con_lease_item_ds" prompt="车系"/>
                        <a:textField name="model_dis" bindTarget="con_lease_item_ds" prompt="车型"/>
                        <a:textField name="color_of_apprearance" bindTarget="con_lease_item_ds" prompt="颜色"/>
                    </a:hBox>
                </a:form>
                <!-- <a:form marginWidth="80" title="HLS.QUERY_TITLE">
                    <a:hBox>
                        <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:textField name="item_engine_number" bindTarget="con_item_info_query_ds" prompt="发动机号">
                            <a:events>
                                <a:event name="enterdown" handler="enterdownHandler"/>
                            </a:events>
                        </a:textField>                        
                    </a:hBox>
                </a:form> -->
                <a:grid bindTarget="con_item_info_ds" marginHeight="300" marginWidth="80" navBar="true" showRowNumber="true">
                    <a:columns>
                        <!-- <a:column name="contract_number" prompt="合同号" width="120"/> -->
                        <a:column name="item_frame_number" editor="item_info_tf" prompt="车架号" width="180"/>
                        <a:column name="item_engine_number" editor="item_info_tf" prompt="发动机号" width="150"/>
                        <a:column name="attach_upload" align="center" prompt="附件上传" renderer="attachment_upload" width="120"/>
                        <!-- <a:column name="key_flag" editor="item_info_cb" prompt="钥匙" width="80"/>
                        <a:column name="registration_flag" editor="item_info_cb" prompt="登记证" width="80"/>
                        <a:column name="purchase_flag" editor="item_info_cb" prompt="购置税证" width="80"/>
                        <a:column name="insurance_flag" editor="item_info_cb" 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" width="1100">
                    <a:tabs>
                        <a:tab prompt="牌照信息" ref="${/request/@context_path}/modules/ast/AST501/ast_car_license.lview" width="100"/>
                        <a:tab prompt="保险信息" ref="${/request/@context_path}/modules/ast/AST501/ast_car_insurance.lview" width="100"/>
                        <a:tab prompt="车况信息" ref="${/request/@context_path}/modules/ast/AST501/ast_car_condition.lview" width="100"/>
                        <a:tab prompt="GPS信息" width="100"/>
                        <a:tab prompt="拖车记录" ref="${/request/@context_path}/modules/ast/AST501/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>
