<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LPC
    $Date: 2018-6-26 11:08:57
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script"
          customizationEnabled="true" dynamiccreateenabled="true"
          trace="true">
    <a:view>
        <a:link id="tre_loan_contact_update_submit_link_id" model="lon.LON120.tre_loan_contract_update"
                modelaction="update"/>
        <a:link id="tre505_get_special_fields_link" model="cont.CON500.con_contract_get_special_fields"
                modelaction="update"/>
        <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="loan_change_req_modify_link_id"
                url="${/request/@context_path}/modules/lon/LON120/loan_change_req_modify.lview"/>
        <script type="text/javascript"><![CDATA[

        //保存前调用,生成单据编号
        window['${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function (ds, record) {
            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var head_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'tre_loan_con_change_req');
            //var record_ds = $(head_ds).getAt(0);
            var record_ds = $(head_ds).getCurrentRecord();
            var check_flag = false;

            if (record_ds.get('change_req_num')) {
                return true;
            }
            Leaf.request({
                url: $('tre505_get_special_fields_link').getUrl(),
                para: {
                    document_category: 'LOAN_CONTRACT',
                    document_type: 'LEASE_REQ_NUM'
                },
                success: function (res) {
                    var document_number = res.result.document_number;
                    record_ds.set('change_req_num', document_number);
                    check_flag = true;
                },
                error: function () {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                failure: function () {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                sync: true,
                scope: this
            });
            return check_flag;
        };

        //变更申请
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {

            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'tre_loan_con_change_req');
            var record = $(ds_id).getCurrentRecord();
            var loan_change_req_id = record.get('loan_change_req_id');
            var loan_contract_id = record.get('loan_contract_id');
            var param = {};
            if (!Ext.isEmpty(loan_change_req_id)) {
                param['function_code'] = 'LON120N';
                param['url_title'] = '融资合同变更明细';
                //param['loan_contract_id'] = loan_contract_id;
                param['loan_contract_id'] = loan_change_req_id;
                param['loan_change_req_id'] = loan_change_req_id;
                param['winid'] = 'lon120n_loan_contract_req_winid';
                hls_doc_get_layout_code('${/parameter/@layout_code}con_contract_get_layout_code_link_id', param, 'loan_change_req_modify_link_id', '${/parameter/@layout_code}');
            } else {
                Leaf.showMessage('提示', '请先保存!');
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                return;
            }
        };

        // //保存后更新
        // window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function (ds, record, res) {
        //     window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
        //     var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'tre_loan_con_change_req');
        //     var record1 = $(ds_id).getCurrentRecord();
        //     var loan_contract_id = record.get('loan_contract_id');
        //     var loan_change_req_id = record.get('loan_change_req_id');
        //     debugger
        //     Leaf.request({
        //         url: $('tre_loan_contact_update_submit_link_id').getUrl(),
        //         para: {
        //             loan_contract_id: loan_contract_id,
        //             loan_change_req_id:loan_change_req_id
        //         },
        //         success: function () {
        //             window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //         },
        //         failure: function () {
        //             window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //         },
        //         error: function () {
        //             window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //         },
        //         scope: this
        //     });
        //
        // };

        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>