<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true"
          trace="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.change_req_id = ${/parameter/@change_req_id}"
                       model="cus_deposit.CUS_DEPOSIT106.get_contract_wfl_status" rootPath="default_value_path"/>
    </a:init-procedure>
    <a:view>

        <a:link id="con731_submit_link" model="cont.CON731.submit_change_req" modelaction="execute"/>
        <a:link id="con731_cancel_link" model="cont.CON731.cancel_change_req" modelaction="execute"/>

        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>
        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>

        <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="con_buyback_info_print_link_id"
                url="${/request/@context_path}/modules/csh/CSH501/csh_con_req_history_pdf_print.lsc"/>
        <a:link id="con_check_deduction_limit_link" model="check_after_save_bm.con_check_deduction_limit_after_save"
                modelaction="update"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_calculator_update_link_id"
                url="${/request/@context_path}/modules/hls/HLS500N/hls_fin_calculator_update_n.lview"/>
     <script type="text/javascript"><![CDATA[

        window['${/parameter/@layout_code}_quote_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var cashflow_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_cashflow');
            var record = $(ds_id).getCurrentRecord();
            var price_list = record.get('price_list');
            var calc_session_id = record.get('calc_session_id');
            var parent_pk_value = record.get('contract_id');
            var calc_type = '${/parameter/@calc_type}' || 'CLASSIC_CALCULATOR';
            var maintain_type = 'QUERY'
            if (calc_session_id) {
                //直接进入报价页面
                var win = new Leaf.Window({
                    id: 'hls_fin_calc_quotation_update_link_winid',
                    params: {
                        layout_code: '${/parameter/@layout_code}',
                        document_id: parent_pk_value,
                        price_list: price_list,
                        document_category: 'CONTRACT',
                        contract_status: record.get('contract_status'),
                        maintain_type: 'MODIFY',
                        business_type: record.get('business_type'),
                        calc_session_id: record.get('calc_session_id'),
                        //quotation_id: record.get('quotation_id'),
                        dsId: cashflow_ds_id,
                        winId: 'hls_fin_calc_quotation_update_link_winid',
                        global_flag: 'Y',
                        id_num: 1,
                        calc_type: calc_type,
                        recreate_L_formula: 'Y',
                        recreate_H_formula: 'Y'
                    },
                    url: $('${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_calculator_update_link_id').getUrl(),
                    fullScreen: true,
                    draggable: true
                });
                win.on('close', function () {
                    $(cashflow_ds_id).query();
                    $(ds_id).query();
                });


            }
        }




       /* window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function (ds, record, name, value, old_value, bp_seq) {


        };*/



        window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function () {
            //  $('${/parameter/@layout_code}_submit_approval').disable();
            var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var req_ds_id2 = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
            var req_record = $(req_ds_id).getAt(0);
            var case_type = '';
            var document_type = '${/parameter/@document_type}';
            var calc_session_id = req_record.get('calc_session_id');

            if ($(req_ds_id).validate($('${/parameter/@layout_code}_submit_approval').enable()) && $(req_ds_id2).validate($('${/parameter/@layout_code}_submit_approval').enable())) {

                    con731_submit();
            } else {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            }
        };

        function con731_submit() {
            var showMessage  ='是否确认提交审批？';

            Leaf.showConfirm('${l:HLS.PROMPT}', showMessage, function () {
                var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var req_record = $(req_ds_id).getAt(0);
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('con731_submit_link').getUrl(),
                    para: {
                        change_req_id: '${/parameter/@change_req_id}',
                        layout_code: '${/parameter/@layout_code}'
                    },
                    success: function (res) {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $('${/parameter/@winid}').close();

                    },
                    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
                });
            }, null, 300, 150);
        }

        //保存submitsuccess调用
        window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function (ds, record, res, bp_seq) {
            var ca_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_cashflow');
            if (ca_ds_id) {
                $(ca_ds_id).query();
            }
            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        };



        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            Leaf.showConfirm('${l:HLS.PROMPT}', '是否确认取消变更？', function () {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('con731_cancel_link').getUrl(),
                    para: {
                        change_req_id: '${/parameter/@change_req_id}'
                    },
                    success: function (res) {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $('${/parameter/@winid}').close();
                    },
                    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
                });
            });
        };


     //加载时调用(grid,table,gridBox)
     window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function (ds, record, config_records, bp_seq) {
         var lease_item_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_LEASE_HEAD_CAR', 'con_contract_lease_item');
         if(ds.id == lease_item_ds_id&&lease_item_ds_id){
             var gridId= ds.bindname+'_layout_grid_id';
             if(record.data.division=='70'){
                 $(gridId).hideColumn('full_name');
                 $(gridId).hideColumn('division_n');
                 $(gridId).hideColumn('equipments');
                 $(gridId).hideColumn('machine_model_class_n');
                 $(gridId).hideColumn('item_type_n');
                 $(gridId).hideColumn('equipment_type_n');
                 $(gridId).hideColumn('machine_number');
                 record.getField('machine_number').setRequired(false);
             }else {
                 $(gridId).hideColumn('machine_number_70');
                 $(gridId).hideColumn('lease_name_n');
                 $(gridId).hideColumn('brand_value');
                 $(gridId).hideColumn('type_name');
                 $(gridId).hideColumn('produce_date');
                 $(gridId).hideColumn('using_hour');
                 $(gridId).hideColumn('detention_amount');
                 $(gridId).hideColumn('residual_value_amount');
                 $(gridId).hideColumn('ownership_flag_n');
                 $(gridId).hideColumn('created_by_n');
             }

             if(record.data.division=='30'||record.data.division=='50'||record.data.division=='80'){
                 record.getField('set_number').setRequired(true);
             }else{
                 record.getField('set_number').setReadOnly(true);
                 if(Ext.isEmpty(record.get('set_number'))){
                     record.set('set_number',1);
                 }
             }
         }

     };



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