<?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:model-query defaultWhereClause="cc.division = hd.division and cc.contract_id=${/parameter/@change_req_id}" model="hls.HLS500N.check_con_record_date" rootPath="full_elec_sign"/>
    </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"/>
        <a:link id="cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="check_sign_status_id" model="cont.CON731.check_contract_sign_status" modelaction="query"/>
        <script type="text/javascript"><![CDATA[

        function attachment_window_open(change_req_id,record_id, ds_id) {
            url = $('cdd_uploadFile_id').getUrl() + '?table_name=CCR_BEFORE_SIGN&header_id=' + change_req_id;
            wd = new Leaf.Window({
                id: 'open_attachment_window',
                url: url,
                title: '附件上传',
                height: 350,
                width: 850
            });
        }
        function attachment_window_query(change_req_id,record_id, ds_id) {
            url = $('cdd_downloadFile_id').getUrl() + '?table_name=CCR_BEFORE_SIGN&header_id=' + change_req_id;
            wd = new Leaf.Window({
                id: 'open_attachment_window',
                url: url,
                title: '附件上传',
                height: 350,
                width: 850
            });
        }

        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',
                        change_type : 'CCR_BEFORE_SINGE'
                    },
                    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/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record) {
            //debugger
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            //var record = $(ds_id).getCurrentRecord();
            var contract_id = record.get('contract_id');
            var change_req_id = '${/parameter/@change_req_id}';
            var sign_contract_status;
            Leaf.request({
                url: $('check_sign_status_id').getUrl(),
                para: {
                    change_req_id: change_req_id
                },
                scope: this,
                success: function (res) {
                    sign_contract_status = res.result.record.sign_contract_status;
                },
                failure: function () {
                    return false;
                },
                scope: this,
                sync: true
            });
            if (name == 'attachment') {
                if(sign_contract_status == 'NEW' ){
                    return '<a href="javascript:attachment_window_open(\'' + record.get('change_req_id') + '\',\'' + record.id + '\',\'' + record.ds.id + '\');">' + '附件上传' + '</a>';

                }else{
                    return '<a href="javascript:attachment_window_query(\'' + record.get('change_req_id') + '\',\'' + record.id + '\',\'' + record.ds.id + '\');">' + '附件上传' + '</a>';
                }
            }
        }



        window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function () {
            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');
            var change_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_change_req');
            var req_record2 = $(change_ds_id).getAt(0);
            if (Ext.isEmpty(req_record2.get('ccr_reason'))) {
                $L.showErrorMessage('错误', '变更理由及说明字段不能为空!');
                return false;
            }
            var lease_item_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_LEASE_HEAD_CAR', 'con_contract_lease_item');
            // if ($(lease_item_ds_id).isModified()) {
            //     Leaf.showInfoMessage('提示', '变更后未完成报价计算，请先进行报价计算!');
            //     return false;
            // }

            if ($(change_ds_id).isModified()) {
                Leaf.showInfoMessage('提示', '请先保存之后再提交审批！');
                return false;
            }


            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){
              //加载时根据是否全电签约及电子合同判断，非全电签约及电子合同租赁物信息只读
              if('${/model/full_elec_sign/record/@full_elec_sign}'!='Y' && '${/model/full_elec_sign/record/@sign_type}'=='ELE_SIGN'){
                 var gridId= ds.bindname+'_layout_grid_id';
                 if(record.data.division=='70'|| record.data.division=='92'){
                     $(gridId).hideColumn('full_name');
                     $(gridId).hideColumn('full_name_n');
                     $(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);
                     record.getField('set_number').setReadOnly(true);
                 }else{
                     record.getField('set_number').setReadOnly(true);
                     if(Ext.isEmpty(record.get('set_number'))){
                         record.set('set_number',1);
                     }
                 }
                 //非全电签约电子合同取消设置必填
                 /*if (record.data.division == '70' || record.data.division=='92') {
                     record.getField('lease_name_n').setRequired(true);
                     record.getField('brand_value').setRequired(true);
                     record.getField('modelcd').setReadOnly(false);
                     record.getField('modelcd').setRequired(true);
                     record.getField('machine_number_70').setRequired(true);

                 }*/
                 //设置为非必填
                 record.getField('machine_number').setRequired(false);
                 //新增逻辑，将布局中未设置为只读的字段设置为只读
                 record.getField('lease_item_seq').setReadOnly(true);
                 record.getField('lease_name').setReadOnly(true);
                 record.getField('lease_name_n').setReadOnly(true);
                 record.getField('brand_value').setReadOnly(true);
                 record.getField('modelcd').setReadOnly(true);
                 record.getField('pattern').setReadOnly(true);
                 //机号
                 record.getField('machine_number').setReadOnly(true);
                 record.getField('machine_number_70').setReadOnly(true);
                 record.getField('produce_date').setReadOnly(true);
                 record.getField('using_hour').setReadOnly(true);
                 record.getField('residual_value_amount').setReadOnly(true);
                 record.getField('ownership_flag').setReadOnly(true);
                 record.getField('ownership_flag_n').setReadOnly(true);
                 record.getField('full_name').setReadOnly(true);
                 record.getField('full_name_n').setReadOnly(true);
              }else{
                var gridId= ds.bindname+'_layout_grid_id';
                if(record.data.division=='70'|| record.data.division=='92'){
                    $(gridId).hideColumn('full_name');
                    $(gridId).hideColumn('full_name_n');
                    $(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);
                    }
                }
                if (record.data.division == '70' || record.data.division=='92') {
                    record.getField('lease_name_n').setRequired(true);
                    record.getField('brand_value').setRequired(true);
                    record.getField('modelcd').setReadOnly(true);
                    record.getField('modelcd').setRequired(false);
                    record.getField('pattern').setReadOnly(true);
                    record.getField('pattern').setRequired(false);
                    record.getField('machine_numbe\r_70').setRequired(true);

                }
              }
            }
            var lease_old_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_LEASE_OLD_CAR', 'con_contract_lease_item');
            if(ds.id == lease_old_ds_id&&lease_old_ds_id){
                var gridId= ds.bindname+'_layout_grid_id';
                if(record.data.division=='70' || record.data.division=='92'){
                    $(gridId).hideColumn('full_name');
                    $(gridId).hideColumn('full_name_n');
                    $(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');
                }
            }

        };


        //新增和加载时调用(form)
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
            //document.getElementById('${/parameter/@layout_code}_CCR_BEFORE_SIGN_F_BASIC_1_prompt').style.display = 'none';//component_id_
            //document.getElementById('${/parameter/@layout_code}_CCR_BEFORE_SIGN_F_BASIC_1').style.display = 'none';
            document.getElementById('CCR_BEFORE_SIGN_F_BASIC_1_component_id').style.display = "none";
            if('${/parameter/@function_usage}'=='QUERY'){
                document.getElementById('CCR_BEFORE_SIGN_save').style.display = 'none';
                document.getElementById('CCR_BEFORE_SIGN_quote').style.display = 'none';
                document.getElementById('CCR_BEFORE_SIGN_exit').style.display = 'none';
                document.getElementById('CCR_BEFORE_SIGN_user_button1').style.display = 'none';
                document.getElementById('CCR_BEFORE_SIGN_submit_approval').style.display = 'none';
            }



        }
        //更新时调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function (ds, record, name, value, old_value, 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 (lease_item_ds_id == ds.id && lease_item_ds_id) {
                if(record.data.division=='70' || record.data.division=='92'){
                    if(name=='lease_name_n'){
                        record.data.type_name=value;
                    }else if(name=='modelcd'){
                        record.data.pattern=value;
                    }
                    record.getField('full_name').setRequired(false);
                    record.getField('full_name_n').setRequired(false);
                }
            }
        }



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