<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2018年1月19日 下午4:48:27  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="${/parameter/@layout_code}_con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_con740_save_data_link" model="cont.CON740.con740_car_update" modelaction="insert"/>
        <script type="text/javascript"><![CDATA[
            //保存
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                
                var con_lease_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                var le_ds_id = 'CON_DFF_CAR_DISPLACE_MODIFY_G_CAR_DIS_INFO_con_contract_lease_item_ds';
                var car_ds_id = 'CON_DFF_CAR_DISPLACE_MODIFY_G_NEW_CAR_INFO_con_contract_lease_item_ds';
                // var con_dff_car_id = $(ds_id);
                var con_lease_item_id = $(con_lease_id);
                var record = $(con_lease_id).getAt(0);
                var finance_amount = '${/parameter/@finance_amount}';
                var car_price = record.get('car_price');
            
                if (finance_amount > car_price) {
                    Leaf.showMessage('${l:PROMPT}', '置换车辆的价格小于实际辆融资额,不允许置换!');
                    return;
                }
            
                record.set('contract_id', '${/parameter/@contract_id}');
                record.set('contract_lease_item_id', '${/parameter/@contract_lease_item_id}');
            
                if ($(con_lease_id).validate()) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    Leaf.request({
                        url: $('${/parameter/@layout_code}_con740_save_data_link').getUrl(),
                        para: {
                            contract_lease_item_id: record.get('contract_lease_item_id'),
                            contract_id: record.get('contract_id'),
                            brand_id: record.get('brand_id'),
                            series_id: record.get('series_id'),
                            model_id: record.get('model_id'),
                            manufacturer_name: record.get('manufacturer_name'),
                            color_of_apprearance: record.get('color_of_apprearance'),
                            configure: record.get('configure'),
                            factory_date: record.get('factory_date'),
                            item_frame_number: record.get('item_frame_number'),
                            item_engine_number: record.get('item_engine_number'),
                            guide_price: record.get('guide_price'),
                            finance_amount: record.get('finance_amount'),
                            car_status: record.get('car_status'),
                            invoice_date: record.get('invoice_date'),
                            invoice_price: record.get('invoice_price'),
                            mortgage_flag: record.get('mortgage_flag'),
                            finance_ratio: record.get('finance_ratio'),
                            car_price: record.get('car_price')
                        },
                        success: function(res) {
                            Leaf.SideBar.show({
                                msg: '操作成功',
                                duration: 2000
                            });
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $('${/parameter/@winid}').close();
                            $(le_ds_id).query();
                            $(car_ds_id).query();
                        },
                        failure: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        error: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                }
            };
            
            //新增和加载时调用(form)
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                var rec = $(ds_id).getAt(0);
                if (ds_id == ds.id) {
                    rec.set('brand_id', '');
                    rec.set('brand_id_n', '');
                    rec.set('series_id', '');
                    rec.set('series_id_n', '');
                    rec.set('model_id', '');
                    rec.set('model_id_n', '');
                    rec.set('manufacturer_name', '');
                    rec.set('color_of_apprearance', '');
                    rec.set('configure', '');
                    rec.set('factory_date', '');
                    rec.set('item_frame_number', '');
                    rec.set('item_engine_number', '');
                    rec.set('guide_price', '');
                    rec.set('car_price', '');
                    rec.set('invoice_date', '');
                    rec.set('invoice_price', '');
                    rec.set('mortgage_flag', '');
                    rec.set('finance_ratio', '');
            
                }
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>